Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 1v8 standard virtual camera button #220

Merged
merged 10 commits into from
Sep 13, 2024
67 changes: 53 additions & 14 deletions src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ uint8_t camera_setting_reg_menu[CAMERA_SETTING_NUM];
uint8_t camera_profile_menu;

uint8_t video_format = VDO_FMT_720P60;
uint8_t camRatio = 0;
uint8_t camRatio = 0; // 0->16:9 1->4:3
uint8_t camMenuStatus = CAM_STATUS_IDLE;
uint8_t reset_isp_need = 0;

uint8_t camera_is_3v3 = 0;

void camera_type_detect(void) {
camera_type = CAMERA_TYPE_UNKNOW;

Expand Down Expand Up @@ -52,7 +54,9 @@ void camera_ratio_detect(void) {
break;
#ifdef USE_TP9950
case CAMERA_TYPE_OUTDATED:
camRatio = 1;
camRatio = I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_CAM_RATIO);
if (camRatio > 1)
camRatio = 1;
break;
#endif
default:
Expand Down Expand Up @@ -542,19 +546,15 @@ void camera_menu_init(void) {

memset(osd_buf, 0x20, sizeof(osd_buf));
disp_mode = DISPLAY_CMS;
if (camera_type == CAMERA_TYPE_UNKNOW ||
camera_type == CAMERA_TYPE_OUTDATED)
camera_button_enter;
else {
for (i = 0; i <= 15; i++) {
osd_buf_p = osd_buf[i] + osd_menu_offset + 3;
strcpy(osd_buf_p, cam_menu_string[i]);
}
camera_profile_menu = camera_profile_eep;
camera_setting_reg_menu_update();
camera_menu_draw_bracket();
camera_menu_draw_value();

for (i = 0; i <= 15; i++) {
osd_buf_p = osd_buf[i] + osd_menu_offset + 3;
strcpy(osd_buf_p, cam_menu_string[i]);
}
camera_profile_menu = camera_profile_eep;
camera_setting_reg_menu_update();
camera_menu_draw_bracket();
camera_menu_draw_value();
}
void camera_menu_show_repower(void) {
memset(osd_buf, 0x20, sizeof(osd_buf));
Expand Down Expand Up @@ -876,3 +876,42 @@ uint8_t camera_status_update(uint8_t op) {
return ret;
}
#endif

void camera_select_menu_init(void) {
const char *cam_select_menu_string[] = {
"> ECO CAMERA MENU",
" LUX CAMERA MENU",
" VTX RATIO FOR LUX CAMERA <4:3> ",
" EXIT",
};
char *osd_buf_p;
uint8_t i;

for (i = 0; i <= CAM_SELECT_EXIT; i++) {
osd_buf_p = osd_buf[i] + osd_menu_offset;
strcpy(osd_buf_p, cam_select_menu_string[i]);
}
camera_select_menu_ratio_upate();
}

void camera_select_menu_cursor_update(uint8_t index) {
uint8_t i;
for (i = 0; i <= CAM_SELECT_EXIT; i++) {
if (i == index)
osd_buf[i][osd_menu_offset] = '>';
else
osd_buf[i][osd_menu_offset] = ' ';
}
}

void camera_select_menu_ratio_upate() {
if (camRatio == 1)
strcpy(osd_buf[2] + osd_menu_offset + 28, "<4:3> ");
else
strcpy(osd_buf[2] + osd_menu_offset + 28, "<16:9>");
}

void camera_menu_mode_exit_note() {
const char note_string[] = "LEFT MOVE THROTTLE TO EXIT CAMERA MENU";
strcpy(osd_buf[15] + 5, note_string);
}
26 changes: 20 additions & 6 deletions src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#define CAMERA_SETTING_NUM 16
#define CAMERA_PROFILE_NUM 3

#define camera_button_enter WriteReg(0, 0x14, 0x32)
#define camera_button_right WriteReg(0, 0x14, 0x58)
#define camera_button_down WriteReg(0, 0x14, 0x64)
#define camera_button_left WriteReg(0, 0x14, 0x3F)
#define camera_button_up WriteReg(0, 0x14, 0x4B)
#define camera_button_mid WriteReg(0, 0x14, 0x00)
extern uint8_t camera_is_3v3;

#define camera_button_enter WriteReg(0, 0x14, camera_is_3v3 ? 50 : 65)
#define camera_button_right WriteReg(0, 0x14, camera_is_3v3 ? 88 : 89)
#define camera_button_down WriteReg(0, 0x14, camera_is_3v3 ? 100 : 100)
#define camera_button_left WriteReg(0, 0x14, camera_is_3v3 ? 63 : 72)
#define camera_button_up WriteReg(0, 0x14, camera_is_3v3 ? 75 : 80)
#define camera_button_mid WriteReg(0, 0x14, camera_is_3v3 ? 0 : 44)

typedef enum {
CAMERA_MFR_UNKNOW,
Expand Down Expand Up @@ -81,9 +83,21 @@ typedef enum {
CAM_STATUS_END,
} camera_status_e;

typedef enum {
CAM_SELECT_RUNCAM_ECO = 0,
CAM_SELECT_RUNCAM_LUX,

CAM_SELECT_RATIO,
CAM_SELECT_EXIT,
} camera_select_e;

void camera_init();
uint8_t camera_status_update(uint8_t op);
void camera_menu_init(void);
void camera_select_menu_init(void);
void camera_select_menu_cursor_update(uint8_t index);
void camera_select_menu_ratio_upate();
void camera_menu_mode_exit_note();

extern uint8_t camRatio;
extern uint8_t video_format;
Expand Down
1 change: 1 addition & 0 deletions src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef enum {
#define EEP_ADDR_BAUDRATE 0x8B
#define EEP_ADDR_LOWBAND_LOCK 0x8C
#define EEP_ADDR_SHORTCUT 0x8D
#define EEP_ADDR_CAM_RATIO 0x8E
#define EEP_ADDR_TAB3 0xA0 // 0xA0 - 0xBF
#define EEP_ADDR_DCOC1 0xC0 // 0xC0 - 0xC4
#define EEP_ADDR_DCOC_EN 0xC0
Expand Down
80 changes: 78 additions & 2 deletions src/msp_displayport.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ uint8_t mspVtxLock = 0;
uint8_t init_table_done = 0;
uint8_t init_table_unsupported = 0;

#ifdef USE_TP9950
uint16_t cam_menu_timeout_sec = 0;
#endif

uint8_t crc8tab[256] = {
0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
Expand Down Expand Up @@ -1321,7 +1325,10 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt
static uint8_t last_mid = 1;
static uint8_t cms_cnt;

static uint8_t camera_selected = 0;

uint8_t VirtualBtn = BTN_INVALID;
static uint8_t VirtualBtn_last = BTN_INVALID;

uint8_t IS_HI_yaw = IS_HI(yaw);
uint8_t IS_LO_yaw = IS_LO(yaw);
Expand Down Expand Up @@ -1681,8 +1688,59 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt
cms_cnt = 0;
disp_mode = DISPLAY_CMS;
clear_screen();
camera_menu_init();
cms_state = CMS_CAM;
if (camera_type == CAMERA_TYPE_UNKNOW ||
camera_type == CAMERA_TYPE_OUTDATED) {
camera_select_menu_init();
camera_selected = 0;
cms_state = CMS_SELECT_CAM;
} else {
camera_menu_init();
cms_state = CMS_CAM;
}
}
break;
}

case CMS_SELECT_CAM: {
if (last_mid) {
if (VirtualBtn == BTN_UP) {
camera_selected--;
if (camera_selected > CAM_SELECT_EXIT)
camera_selected = CAM_SELECT_EXIT;
camera_select_menu_cursor_update(camera_selected);
} else if (VirtualBtn == BTN_DOWN) {
camera_selected++;
if (camera_selected > CAM_SELECT_EXIT)
camera_selected = CAM_SELECT_RUNCAM_ECO;
camera_select_menu_cursor_update(camera_selected);
} else if (VirtualBtn == BTN_LEFT) {
if (camera_selected == CAM_SELECT_RATIO) {
camRatio = 1 - camRatio;
camera_select_menu_ratio_upate();
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_CAM_RATIO, camRatio);
}
} else if (VirtualBtn == BTN_RIGHT) {
if (camera_selected == CAM_SELECT_RATIO) {
camRatio = 1 - camRatio;
camera_select_menu_ratio_upate();
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_CAM_RATIO, camRatio);
} else {
camera_is_3v3 = (camera_selected == CAM_SELECT_RUNCAM_ECO);
clear_screen();
if (camera_selected == CAM_SELECT_EXIT) {
disp_mode = DISPLAY_OSD;
cms_state = CMS_OSD;
msp_tx_cnt = 0;
} else {
camera_button_enter;
camera_menu_mode_exit_note();
#ifdef USE_TP9950
cam_menu_timeout_sec = seconds;
#endif
cms_state = CMS_CAM;
}
}
}
}
break;
}
Expand Down Expand Up @@ -1710,7 +1768,25 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt
break;
}
} // switch

last_mid = mid;

#ifdef USE_TP9950
if (cms_state == CMS_CAM && (camera_type == CAMERA_TYPE_UNKNOW || camera_type == CAMERA_TYPE_OUTDATED)) {
if (VirtualBtn_last == VirtualBtn) {
if (seconds - cam_menu_timeout_sec >= 60) {
// exit cam menu
disp_mode = DISPLAY_OSD;
cms_state = CMS_OSD;
fc_init();
msp_tx_cnt = 0;
}
} else {
cam_menu_timeout_sec = seconds;
}
}
VirtualBtn_last = VirtualBtn;
#endif
}

void vtx_menu_init() {
Expand Down
3 changes: 2 additions & 1 deletion src/msp_displayport.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ typedef enum {
CMS_CONFIG_NORMAL_POWER,
CMS_ENTER_CAM,
CMS_VTX_MENU,
CMS_CAM
CMS_CAM,
CMS_SELECT_CAM,
} cms_state_e;

typedef enum {
Expand Down