-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from ISSUIUC/camera-b2b-interface-i2c
Add B2B communication interface for camera board
- Loading branch information
Showing
6 changed files
with
165 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "b2b_interface.h" | ||
|
||
|
||
ErrorCode B2BInterface::init() { | ||
// No special init | ||
return ErrorCode::NoError; | ||
} | ||
|
||
|
||
|
||
void CameraB2B::transmit_command(CameraCommand command) { | ||
#ifdef B2B_I2C | ||
|
||
Wire.beginTransmission(0x69); // 0x69 --> Camera board i2c address | ||
Wire.write((uint8_t) command); | ||
if (Wire.endTransmission()) { | ||
Serial.println("Camera B2B i2c write error"); | ||
} | ||
|
||
#endif | ||
|
||
#ifdef B2B_CAN | ||
// todo :D | ||
#endif | ||
} | ||
|
||
void CameraB2B::vtx_on() { | ||
transmit_command(CameraCommand::VTX_ON); | ||
vtx_state_ = true; | ||
} | ||
|
||
void CameraB2B::vtx_off() { | ||
transmit_command(CameraCommand::VTX_OFF); | ||
vtx_state_ = false; | ||
} | ||
|
||
void CameraB2B::vtx_toggle() { | ||
if(vtx_state_) { | ||
vtx_off(); | ||
} else { | ||
vtx_on(); | ||
} | ||
} | ||
|
||
void CameraB2B::camera_on(int cam_index) { | ||
switch (cam_index) { | ||
case 0: | ||
transmit_command(CameraCommand::CAMERA0_ON); | ||
cam_state_[0] = true; | ||
break; | ||
case 1: | ||
transmit_command(CameraCommand::CAMERA1_ON); | ||
cam_state_[1] = true; | ||
break; | ||
default: | ||
Serial.print("B2B camera on -- invalid index "); | ||
Serial.println(cam_index); | ||
break; | ||
} | ||
} | ||
|
||
void CameraB2B::camera_off(int cam_index) { | ||
switch (cam_index) { | ||
case 0: | ||
transmit_command(CameraCommand::CAMERA0_OFF); | ||
cam_state_[0] = false; | ||
break; | ||
case 1: | ||
transmit_command(CameraCommand::CAMERA1_OFF); | ||
cam_state_[1] = false; | ||
break; | ||
default: | ||
Serial.print("B2B camera on -- invalid index "); | ||
Serial.println(cam_index); | ||
break; | ||
} | ||
} | ||
|
||
void CameraB2B::camera_toggle(int cam_index) { | ||
switch (cam_index) { | ||
case 0: | ||
if (cam_state_[0]) { | ||
camera_off(0); | ||
} else { | ||
camera_on(0); | ||
} | ||
break; | ||
case 1: | ||
if (cam_state_[1]) { | ||
camera_off(1); | ||
} else { | ||
camera_on(1); | ||
} | ||
break; | ||
default: | ||
Serial.print("B2B camera on -- invalid index "); | ||
Serial.println(cam_index); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <Wire.h> | ||
#include "errors.h" | ||
#include "hal.h" | ||
|
||
// Which b2b communication we should use | ||
#define B2B_I2C | ||
// #define B2B_CAN | ||
|
||
#if defined(B2B_I2C) && defined(B2B_CAN) | ||
#error "B2B can only use one option of B2B_I2C, or B2B_CAN" | ||
#elif !defined(B2B_I2C) && !defined(B2B_CAN) | ||
#error "At least one B2B_I2C or B2B_CAN must be defined" | ||
#endif | ||
|
||
|
||
enum class CameraCommand { | ||
CAMERA0_OFF = 0, | ||
CAMERA0_ON = 1, | ||
CAMERA1_OFF = 2, | ||
CAMERA1_ON = 3, | ||
VTX_OFF = 4, | ||
VTX_ON = 5, | ||
MUX_0 = 6, | ||
MUX_1 = 7 | ||
}; | ||
|
||
struct CameraB2B { | ||
|
||
void camera_on(int cam_index); | ||
void camera_off(int cam_index); | ||
void camera_toggle(int cam_index); | ||
|
||
void vtx_on(); | ||
void vtx_off(); | ||
void vtx_toggle(); | ||
|
||
private: | ||
void transmit_command(CameraCommand command); | ||
bool cam_state_[2] = { false, false }; // false: off, true: on | ||
bool vtx_state_ = false; | ||
}; | ||
|
||
/** | ||
* @struct Interface for B2B communication protocol | ||
*/ | ||
struct B2BInterface { | ||
ErrorCode init(); | ||
|
||
CameraB2B camera; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters