Skip to content

Commit

Permalink
Merge pull request #367 from Master92/assignable_functions
Browse files Browse the repository at this point in the history
Make button and roller actions configurable for video mode
  • Loading branch information
ligenxxxx authored Nov 30, 2023
2 parents 8b560fd + 43c003e commit 07cfcf5
Show file tree
Hide file tree
Showing 19 changed files with 448 additions and 24 deletions.
8 changes: 8 additions & 0 deletions mkapp/app/setting.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ enable=false
[elrs]
enable=false

[inputs]
roller=0
left_click=0
left_press=1
right_click=2
right_press=6
right_double_click=3

[wifi]
enable=false
ap_ssid=HDZero
Expand Down
2 changes: 2 additions & 0 deletions src/core/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ hw_revision_t getHwRevision();
#define RIGHT_KEY_CLICK 5
#define RIGHT_KEY_PRESS 6

#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))

extern atomic_int g_key;
extern atomic_int g_init_done;
extern pthread_mutex_t lvgl_mutex;
Expand Down
4 changes: 4 additions & 0 deletions src/core/dvr.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ void dvr_update_vi_conf(video_resolution_t fmt) {
LOGI("update_record_vi_conf: fmt=%d", fmt);
}

void dvr_toggle() {
dvr_cmd(DVR_TOGGLE);
}

static void dvr_update_record_conf() {
LOGI("CAM_MODE=%d", CAM_MODE);
if (g_setting.record.format_ts)
Expand Down
1 change: 1 addition & 0 deletions src/core/dvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void dvr_select_audio_source(uint8_t audio_source);
void dvr_enable_line_out(bool enable);
void dvr_cmd(osd_dvr_cmd_t cmd);
void dvr_update_vi_conf(video_resolution_t fmt);
void dvr_toggle();

#ifdef __cplusplus
}
Expand Down
49 changes: 28 additions & 21 deletions src/core/input_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ void tune_channel(uint8_t action) {
tune_timer = TUNER_TIMER_LEN;
tune_state = 2;
channel = g_setting.scan.channel;
} else if (action == DIAL_KEY_CLICK) {
g_setting.osd.is_visible = !g_setting.osd.is_visible;
if (g_setting.osd.is_visible)
channel_osd_mode = CHANNEL_SHOWTIME;

settings_put_bool("osd", "is_visible", g_setting.osd.is_visible);
}
}

Expand Down Expand Up @@ -136,6 +130,12 @@ void tune_channel(uint8_t action) {
tune_timer = TUNER_TIMER_LEN;
}

void tune_channel_confirm() {
if (g_source_info.source == SOURCE_HDZERO) {
tune_channel(DIAL_KEY_CLICK);
}
}

void tune_channel_timer() {
if (tune_state == 2) {
if (!tune_timer)
Expand All @@ -157,6 +157,15 @@ void tune_channel_timer() {
static int roller_up_acc = 0;
static int roller_down_acc = 0;

void (*btn_click_callback)() = &osd_toggle;
void (*btn_press_callback)() = &app_switch_to_menu;

void (*rbtn_click_callback)() = &dvr_toggle;
void (*rbtn_press_callback)() = &step_topfan;
void (*rbtn_double_click_callback)() = &ht_set_center_position;

void (*roller_callback)(uint8_t key) = &tune_channel;

static void btn_press(void) // long press left key
{
LOGI("btn_press (%d)", g_app_state);
Expand All @@ -177,7 +186,7 @@ static void btn_press(void) // long press left key
if (tune_timer && g_source_info.source == SOURCE_HDZERO)
tune_channel(DIAL_KEY_PRESS);
else
app_switch_to_menu();
(*btn_press_callback)();
} else if (g_app_state == APP_STATE_OSD_ELEMENT_PREV) {
ui_osd_element_pos_cancel_and_hide();
app_switch_to_menu();
Expand All @@ -204,7 +213,11 @@ static void btn_click(void) // short press enter key

if (g_app_state == APP_STATE_VIDEO) {
pthread_mutex_lock(&lvgl_mutex);
tune_channel(DIAL_KEY_CLICK);
if (tune_state == 2) {
tune_channel_confirm();
} else {
(*btn_click_callback)();
}
pthread_mutex_unlock(&lvgl_mutex);
return;
} else if (g_app_state == APP_STATE_IMS) {
Expand Down Expand Up @@ -263,19 +276,15 @@ void rbtn_click(right_button_t click_type) {
pthread_mutex_unlock(&lvgl_mutex);
break;
case APP_STATE_VIDEO:
pthread_mutex_lock(&lvgl_mutex);
if (click_type == RIGHT_CLICK) {
dvr_cmd(DVR_TOGGLE);
(*rbtn_click_callback)();
} else if (click_type == RIGHT_LONG_PRESS) {
pthread_mutex_lock(&lvgl_mutex);
step_topfan();
pthread_mutex_unlock(&lvgl_mutex);
(*rbtn_press_callback)();
} else if (click_type == RIGHT_DOUBLE_CLICK) {
if (g_setting.ht.enable == true) {
ht_set_center_position();
} else {
go_sleep();
}
(*rbtn_double_click_callback)();
}
pthread_mutex_unlock(&lvgl_mutex);
break;
case APP_STATE_SLEEP:
wake_up();
Expand Down Expand Up @@ -307,8 +316,7 @@ static void roller_up(void) {
} else if ((g_app_state == APP_STATE_SUBMENU_ITEM_FOCUSED)) {
submenu_roller_no_selection_change(DIAL_KEY_UP);
} else if (g_app_state == APP_STATE_VIDEO) {
if (g_source_info.source == SOURCE_HDZERO)
tune_channel(DIAL_KEY_UP);
(*roller_callback)(DIAL_KEY_UP);
} else if (g_app_state == APP_STATE_IMS) {
ims_key(DIAL_KEY_UP);
} else if (g_app_state == APP_STATE_OSD_ELEMENT_PREV) {
Expand Down Expand Up @@ -342,8 +350,7 @@ static void roller_down(void) {
} else if ((g_app_state == APP_STATE_SUBMENU_ITEM_FOCUSED)) {
submenu_roller_no_selection_change(DIAL_KEY_DOWN);
} else if (g_app_state == APP_STATE_VIDEO) {
if (g_source_info.source == SOURCE_HDZERO)
tune_channel(DIAL_KEY_DOWN);
(*roller_callback)(DIAL_KEY_DOWN);
} else if (g_app_state == APP_STATE_IMS) {
ims_key(DIAL_KEY_DOWN);
} else if (g_app_state == APP_STATE_OSD_ELEMENT_PREV) {
Expand Down
12 changes: 12 additions & 0 deletions src/core/input_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ typedef enum {
} right_button_t;

void input_device_init();
void tune_channel(uint8_t key);
void tune_channel_timer();
void tune_channel_confirm();
void exit_tune_channel();
void rbtn_click(right_button_t click_type);

extern void (*btn_click_callback)();
extern void (*btn_press_callback)();

extern void (*rbtn_click_callback)();
extern void (*rbtn_press_callback)();
extern void (*rbtn_double_click_callback)();


extern void (*roller_callback)(uint8_t key);

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions src/core/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ void osd_resource_path(char *buf, const char *fmt, osd_resource_t osd_resource_t
buf[1] = ':';
}

void osd_toggle() {
g_setting.osd.is_visible = !g_setting.osd.is_visible;
if (g_setting.osd.is_visible) {
channel_osd_mode = CHANNEL_SHOWTIME;
}

settings_put_bool("osd", "is_visible", g_setting.osd.is_visible);
}

///////////////////////////////////////////////////////////////////////////////
// these are local for OSD controlling
static osd_hdzero_t g_osd_hdzero;
Expand Down
1 change: 1 addition & 0 deletions src/core/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ char *channel2str(uint8_t band, uint8_t channel);
void load_fc_osd_font(uint8_t);
void *thread_osd(void *ptr);
void osd_resource_path(char *buf, const char *fmt, osd_resource_t osd_resource_type, ...);
void osd_toggle();

#ifdef __cplusplus
}
Expand Down
17 changes: 17 additions & 0 deletions src/core/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ const setting_t g_setting_defaults = {
.sec = 30,
.format = 0,
},
// Refer to `page_input.c`'s arrays `rollerFunctionPointers` and `btnFunctionPointers`
.inputs = {
.roller = 0,
.left_click = 0,
.left_press = 1,
.right_click = 2,
.right_press = 6,
.right_double_click = 3,
},
.wifi = {
.enable = false,
.mode = 0,
Expand Down Expand Up @@ -405,6 +414,14 @@ void settings_load(void) {
g_setting.clock.sec = ini_getl("clock", "sec", g_setting_defaults.clock.sec, SETTING_INI);
g_setting.clock.format = ini_getl("clock", "format", g_setting_defaults.clock.format, SETTING_INI);

// inputs
g_setting.inputs.roller = ini_getl("inputs", "roller", g_setting_defaults.inputs.roller, SETTING_INI);
g_setting.inputs.left_click = ini_getl("inputs", "left_click", g_setting_defaults.inputs.left_click, SETTING_INI);
g_setting.inputs.left_press = ini_getl("inputs", "left_press", g_setting_defaults.inputs.left_press, SETTING_INI);
g_setting.inputs.right_click = ini_getl("inputs", "right_click", g_setting_defaults.inputs.right_click, SETTING_INI);
g_setting.inputs.right_press = ini_getl("inputs", "right_press", g_setting_defaults.inputs.right_press, SETTING_INI);
g_setting.inputs.right_double_click = ini_getl("inputs", "right_double_click", g_setting_defaults.inputs.right_double_click, SETTING_INI);

// wifi
g_setting.wifi.enable = settings_get_bool("wifi", "enable", g_setting_defaults.wifi.enable);
g_setting.wifi.mode = ini_getl("wifi", "mode", g_setting_defaults.wifi.mode, SETTING_INI);
Expand Down
10 changes: 10 additions & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ typedef struct {
setting_sources_hdzero_bw_t hdzero_bw;
} setting_sources_t;

typedef struct {
uint16_t roller;
uint16_t left_click;
uint16_t left_press;
uint16_t right_click;
uint16_t right_press;
uint16_t right_double_click;
} setting_inputs_t;

typedef struct {
bool logging;
bool selftest;
Expand All @@ -239,6 +248,7 @@ typedef struct {
wifi_t wifi;
setting_osd_t osd;
setting_clock_t clock;
setting_inputs_t inputs;
ease_use_t ease;
setting_storage_t storage;
} setting_t;
Expand Down
3 changes: 3 additions & 0 deletions src/driver/oled.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ extern "C" {
#include "defines.h"
#include <stdint.h>

#define MIN_OLED_BRIGHTNESS 0
#define MAX_OLED_BRIGHTNESS 12

void OLED_write(uint16_t addr, uint16_t wdat, uint8_t sel);
uint16_t OLED_read(uint16_t addr, uint8_t sel);

Expand Down
8 changes: 8 additions & 0 deletions src/ui/page_fans.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,14 @@ void fans_auto_ctrl() {
}
}

void change_topfan(uint8_t key) {
if (key == DIAL_KEY_UP) {
fans_top_speed_inc();
} else if (key == DIAL_KEY_DOWN) {
fans_top_speed_dec();
}
}

page_pack_t pp_fans = {
.p_arr = {
.cur = 0,
Expand Down
1 change: 1 addition & 0 deletions src/ui/page_fans.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern page_pack_t pp_fans;

void step_topfan();
void fans_auto_ctrl();
void change_topfan(uint8_t key);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 07cfcf5

Please sign in to comment.