Skip to content

Commit

Permalink
gain_offset: event handler of rgb and unified spinbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mlorenzati committed Feb 13, 2024
1 parent ac3dd65 commit 9828138
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/commands/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ bool command_is_license_valid() {
}

void command_validate_license(const uint8_t *security_key) {
int token = -1;
#ifdef USE_LICENSE
int token = -1;
command_license_is_valid = security_key_is_valid(security_key, token) <= 0;
#else
command_license_is_valid = true;
Expand Down
4 changes: 4 additions & 0 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ gui_object_t menu_create_left_button_group(menu_button_group_type previous, menu
gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[0].base, &menu_left_buttons_group_elements[4], NULL);
gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[0].base, &menu_left_buttons_group_elements[5], NULL);
gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[0].base, &menu_left_buttons_group_elements[6], NULL);
gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[2].base, &menu_left_buttons_group_elements[2], on_gain_offset_rgb_spinbox_event);
gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[3].base, &menu_left_buttons_group_elements[3], on_gain_offset_rgb_spinbox_event);
gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[4].base, &menu_left_buttons_group_elements[4], on_gain_offset_rgb_spinbox_event);
gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[6].base, &menu_left_buttons_group_elements[6], on_gain_offset_unified_spinbox_event);
gui_event_subscribe(button_status, &menu_left_buttons_group_elements[7].base, &menu_left_buttons_group_elements[7], on_back_event);
gain_offset_slider_option = 0;
menu_update_gain_offset_sliders();
Expand Down
99 changes: 85 additions & 14 deletions src/menu/menuCallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ bool on_alignment_event(gui_status_t status, gui_base_t *origin, gui_object_t *d
spinbox_horizontal = GET_VIDEO_PROPS().horizontal_front_porch;
spinbox_vertical = GET_VIDEO_PROPS().vertical_front_porch;
spinbox_pix_width = GET_VIDEO_PROPS().horizontal_front_porch + GET_VIDEO_PROPS().horizontal_back_porch;
destination->base.status.data_changed = 1;
}

destination->base.status.data_changed = 1;

return true;
}

Expand All @@ -109,7 +108,7 @@ bool on_display_selection_event(gui_status_t status, gui_base_t *origin, gui_obj
destination->base.status.navigable = !destination->base.status.navigable;
} else {
if (status.add && spinbox_display_no < SETTINGS_DISPLAY_MAX) {
spinbox_display_no++;
spinbox_display_no++;
} else if (status.substract && spinbox_display_no > 1) {
spinbox_display_no--;
}
Expand Down Expand Up @@ -138,9 +137,9 @@ bool on_display_selection_event(gui_status_t status, gui_base_t *origin, gui_obj
spinbox_pix_width = GET_VIDEO_PROPS().horizontal_front_porch + GET_VIDEO_PROPS().horizontal_back_porch;
// Gain offset sliders are set when already on the screen, not here
}
destination->base.status.data_changed = 1;
}
destination->base.status.data_changed = 1;


return true;
}

Expand All @@ -161,9 +160,9 @@ bool on_palette_option_event(gui_status_t status, gui_base_t *origin, gui_object
}

void menu_update_gain_offset_sliders(void) {
uint index = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPT - 1) / GUI_BAR_100PERCENT;
uint index = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPTS - 1) / GUI_BAR_100PERCENT;

if (index <= MENU_GAIN_OFFSET_UNI) {
if (index <= MENU_G_OFF_OPT_UNI_NOFFSET) {
gui_disable(&menu_left_buttons_group_elements[2]);
gui_disable(&menu_left_buttons_group_elements[3]);
gui_disable(&menu_left_buttons_group_elements[4]);
Expand All @@ -172,9 +171,9 @@ void menu_update_gain_offset_sliders(void) {
spinbox_gain_offset_green = 0;
spinbox_gain_offset_blue = 0;

if (index == MENU_RGB_OFFSET) {
if (index == MENU_G_OFF_OPT_UNI_OFFSET) {
spinbox_gain_offset_unified = wm8213_afe_get_offset(color_part_all);
} else if (index < MENU_RGB_OFFSET) {
} else if (index < MENU_G_OFF_OPT_UNI_OFFSET) {
spinbox_gain_offset_unified = wm8213_afe_get_gain(color_part_all);
} else {
spinbox_gain_offset_unified = wm8213_afe_get_negative_offset();
Expand All @@ -185,7 +184,7 @@ void menu_update_gain_offset_sliders(void) {
gui_enable(&menu_left_buttons_group_elements[4]);
gui_disable(&menu_left_buttons_group_elements[6]);
spinbox_gain_offset_unified = 0;
if (index == MENU_RGB_GAIN) {
if (index == MENU_G_OFF_OPT_RGB_GAIN) {
spinbox_gain_offset_red = wm8213_afe_get_gain(color_part_red);
spinbox_gain_offset_green = wm8213_afe_get_gain(color_part_green);
spinbox_gain_offset_blue = wm8213_afe_get_gain(color_part_blue);
Expand All @@ -197,16 +196,88 @@ void menu_update_gain_offset_sliders(void) {
}
}

bool on_gain_offset_rgb_spinbox_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination) {
uint *data = (uint *) origin->data;
if (!status.activated && origin->status.activated) {
destination->base.status.navigable = !destination->base.status.navigable;
} else {
uint sliderOpt = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPTS - 1) / GUI_BAR_100PERCENT;
if (data != &spinbox_gain_offset_red && data != &spinbox_gain_offset_green && data != &spinbox_gain_offset_blue) {
// Current slider is not RGB options
return false;
}

if (sliderOpt == MENU_G_OFF_OPT_RGB_GAIN) {
if (status.add && (*data) < WM8213_GAIN_MAX) {
(*data)++;
} else if (status.substract && (*data) != 0) {
(*data)--;
}
wm8213_afe_update_gain(spinbox_gain_offset_red, spinbox_gain_offset_green, spinbox_gain_offset_blue, true);
} else if (sliderOpt == MENU_G_OFF_OPT_RGB_OFFSET) {
if (status.add && (*data) < WM8213_POS_OFFSET_MAX) {
(*data)++;
} else if (status.substract && (*data) != 0) {
(*data)--;
}
wm8213_afe_update_offset(spinbox_gain_offset_red, spinbox_gain_offset_green, spinbox_gain_offset_blue, true);
} else {
// Fail condition
return true;
}
destination->base.status.data_changed = 1;
}
return true;
}

bool on_gain_offset_unified_spinbox_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination) {
uint *data = (uint *) origin->data;
if (!status.activated && origin->status.activated) {
destination->base.status.navigable = !destination->base.status.navigable;
} else {
uint sliderOpt = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPTS - 1) / GUI_BAR_100PERCENT;
if (data != &spinbox_gain_offset_unified ) {
// Current slider is not an unified option
return false;
}
if (sliderOpt == MENU_G_OFF_OPT_UNI_GAIN) {
if (status.add && (*data) < WM8213_GAIN_MAX) {
(*data)++;
} else if (status.substract && (*data) != 0) {
(*data)--;
}
wm8213_afe_update_gain(spinbox_gain_offset_unified, spinbox_gain_offset_unified, spinbox_gain_offset_unified, true);
} else if (sliderOpt == MENU_G_OFF_OPT_UNI_OFFSET) {
if (status.add && (*data) < WM8213_POS_OFFSET_MAX) {
(*data)++;
} else if (status.substract && (*data) != 0) {
(*data)--;
}
wm8213_afe_update_offset(spinbox_gain_offset_unified, spinbox_gain_offset_unified, spinbox_gain_offset_unified, true);
} else if (sliderOpt == MENU_G_OFF_OPT_UNI_NOFFSET) {
if (status.add && (*data) < WM8213_NEG_OFFSET_MAX) {
(*data)++;
} else if (status.substract && (*data) != 0) {
(*data)--;
}
wm8213_afe_update_negative_offset(spinbox_gain_offset_unified, true);
} else {
return false;
}
destination->base.status.data_changed = 1;
}
return true;
}

bool on_gain_offset_option_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination) {
uint *data = (uint *) origin->data;
if (!status.activated && origin->status.activated) {
destination->base.status.navigable = !destination->base.status.navigable;
destination->base.status.data_changed = 1;
} else if (status.add && *data < GUI_BAR_100PERCENT) {
*data += (GUI_BAR_100PERCENT/(MENU_GAIN_OFFSET_OPT - 1));
*data += (GUI_BAR_100PERCENT/(MENU_GAIN_OFFSET_OPTS - 1));
destination->base.status.data_changed = 1;
} else if (status.substract && *data != 0) {
*data -= (GUI_BAR_100PERCENT/(MENU_GAIN_OFFSET_OPT - 1));
*data -= (GUI_BAR_100PERCENT/(MENU_GAIN_OFFSET_OPTS - 1));
destination->base.status.data_changed = 1;
}
if (destination->base.status.data_changed) {
Expand Down Expand Up @@ -361,7 +432,7 @@ void menu_palette_opt_print(print_delegate_t printer) {
}

void menu_gain_offset_rgb_opt_print(print_delegate_t printer) {
uint index = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPT - 1) / GUI_BAR_100PERCENT;
uint index = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPTS - 1) / GUI_BAR_100PERCENT;
printer("%s", menu_gain_offset_rgb_str[index]);
}

Expand Down
2 changes: 2 additions & 0 deletions src/menu/menuCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ bool on_alignment_event(gui_status_t status, gui_base_t *origin, gui_object_t *d
bool on_display_selection_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
bool on_palette_option_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
bool on_gain_offset_option_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
bool on_gain_offset_rgb_spinbox_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
bool on_gain_offset_unified_spinbox_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
bool on_palette_color_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
bool on_save_reboot_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
bool on_factory_reboot_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination);
Expand Down
4 changes: 2 additions & 2 deletions src/menu/menuGlobals.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool menu_usb_enabled = false;
bool menu_display_confirmation=false;
display_t *menu_current_display;
uint color_black, color_white;
const char *menu_gain_offset_rgb_str[MENU_GAIN_OFFSET_OPT] = { "", "", "", "RGB gain", "RGB offset"};
const char *menu_gain_offset_unified_str[MENU_GAIN_OFFSET_OPT] = { "Unified gain", "Unified offset", "Negative offset", "", ""};
const char *menu_gain_offset_rgb_str[MENU_GAIN_OFFSET_OPTS] = { "", "", "", "RGB gain", "RGB offset"};
const char *menu_gain_offset_unified_str[MENU_GAIN_OFFSET_OPTS] = { "Unified gain", "Unified offset", "Negative offset", "", ""};

// --------- Global register end ---------
15 changes: 9 additions & 6 deletions src/menu/menuGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#define MENU_TOTAL_NAV_STACK 4
#define MENU_TOTAL_LEFT_BUTTONS 8
#define MENU_TOTAL_MAIN_VIEW 4
#define MENU_GAIN_OFFSET_OPT 5
#define MENU_GAIN_OFFSET_UNI 2
#define MENU_RGB_GAIN 3
#define MENU_RGB_OFFSET 1

#define MENU_GAIN_OFFSET_OPTS 5
#define MENU_G_OFF_OPT_UNI_GAIN 0
#define MENU_G_OFF_OPT_UNI_OFFSET 1
#define MENU_G_OFF_OPT_UNI_NOFFSET 2
#define MENU_G_OFF_OPT_RGB_GAIN 3
#define MENU_G_OFF_OPT_RGB_OFFSET 4

// ------------ Defines End ------------

Expand Down Expand Up @@ -80,6 +83,6 @@ extern bool menu_usb_enabled;
extern display_t *menu_current_display;
extern uint color_black, color_white;
extern bool menu_display_confirmation;
extern const char *menu_gain_offset_rgb_str[MENU_GAIN_OFFSET_OPT];
extern const char *menu_gain_offset_unified_str[MENU_GAIN_OFFSET_OPT];
extern const char *menu_gain_offset_rgb_str[MENU_GAIN_OFFSET_OPTS];
extern const char *menu_gain_offset_unified_str[MENU_GAIN_OFFSET_OPTS];
#endif

0 comments on commit 9828138

Please sign in to comment.