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

Make a beep once goggles are up and running. #395

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "HDZGOGGLE emulator",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build_emu/HDZGOGGLE",
"cwd": "${workspaceFolder}"
}
]
}
4 changes: 4 additions & 0 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ int main(int argc, char *argv[]) {
// Head alarm
head_alarm_init();

if (g_setting.power.beep_on_power) {
beep();
}

// 10. Execute main loop
g_init_done = 1;
for (;;) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const setting_t g_setting_defaults = {
.osd_display_mode = SETTING_POWER_OSD_DISPLAY_MODE_TOTAL,
.power_ana = false,
.calibration_offset = 0,
.beep_on_power = false
},
.record = {
.mode_manual = false,
Expand Down Expand Up @@ -384,6 +385,7 @@ void settings_load(void) {
g_setting.power.osd_display_mode = ini_getl("power", "osd_display_mode", g_setting_defaults.power.osd_display_mode, SETTING_INI);
g_setting.power.power_ana = ini_getl("power", "power_ana_rx", g_setting_defaults.power.power_ana, SETTING_INI);
g_setting.power.calibration_offset = ini_getl("power", "calibration_offset", g_setting_defaults.power.calibration_offset, SETTING_INI);
g_setting.power.beep_on_power = settings_get_bool("power", "beep_on_power", false);

// record
g_setting.record.mode_manual = settings_get_bool("record", "mode_manual", g_setting_defaults.record.mode_manual);
Expand Down
1 change: 1 addition & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef struct {
setting_power_osd_display_mode_t osd_display_mode;
bool power_ana;
int calibration_offset;
bool beep_on_power;
} setting_power_t;

typedef enum {
Expand Down
4 changes: 3 additions & 1 deletion src/driver/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,9 @@ void Analog_Module_Power(bool ForceSet) {
}
}
if ((Analog_Module_Power_State_Last != Analog_Module_Power_State) || (ForceSet == 1)) {
beep();
if (g_setting.power.beep_on_power) {
beep();
}
Analog_Module_Power_State_Last = Analog_Module_Power_State;
DM5680_Power_AnalogModule(Analog_Module_Power_State);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/page_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extern "C" {
#define RIGHT_BUTTON_IMG "right_button.png"
#define ALERT_IMG "alert.png"

#define MAX_PANELS 9
#define MAX_PANELS 10

#define FLAG_SELECTABLE LV_OBJ_FLAG_USER_1
#define STATE_DISABLED LV_STATE_USER_1
Expand Down
14 changes: 12 additions & 2 deletions src/ui/page_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum {
ROW_CALIBRATION_OFFSET,
ROW_OSD_DISPLAY_MODE,
ROW_WARN_TYPE,
ROW_POWER_BEEP,
ROW_POWER_ANA,
ROW_BACK,

Expand All @@ -40,6 +41,7 @@ static slider_group_t slider_group_cell_count;
static slider_group_t slider_group_calibration_offset;
static btn_group_t btn_group_osd_display_mode;
static btn_group_t btn_group_warn_type;
static btn_group_t btn_group_power_on_beep;
static btn_group_t btn_group_power_ana;

static slider_group_t* selected_slider_group = NULL;
Expand Down Expand Up @@ -92,7 +94,7 @@ static lv_obj_t *page_power_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_clear_flag(page, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_size(page, 1063, 980);
lv_obj_add_style(page, &style_subpage, LV_PART_MAIN);
lv_obj_set_style_pad_top(page, 94, 0);
lv_obj_set_style_pad_top(page, 70, 0);

lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
Expand All @@ -101,7 +103,7 @@ static lv_obj_t *page_power_create(lv_obj_t *parent, panel_arr_t *arr) {
create_text(NULL, section, false, "Power:", LV_MENU_ITEM_BUILDER_VARIANT_2);

lv_obj_t *cont = lv_obj_create(section);
lv_obj_set_size(cont, 970, 680);
lv_obj_set_size(cont, 970, 700);
lv_obj_set_pos(cont, 0, 0);
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
Expand All @@ -122,6 +124,7 @@ static lv_obj_t *page_power_create(lv_obj_t *parent, panel_arr_t *arr) {
create_slider_item(&slider_group_calibration_offset, cont, "Voltage Calibration", 0, g_setting.power.calibration_offset, ROW_CALIBRATION_OFFSET);
create_btn_group_item(&btn_group_osd_display_mode, cont, 2, "Display Mode", "Total", "Cell Avg.", "", "", ROW_OSD_DISPLAY_MODE);
create_btn_group_item(&btn_group_warn_type, cont, 3, "Warning Type", "Beep", "Visual", "Both", "", ROW_WARN_TYPE);
create_btn_group_item(&btn_group_power_on_beep, cont, 2, "Beep on Power", "Off", "On", "", "", ROW_POWER_BEEP);

// Batch 2 goggles only
if (getHwRevision() >= HW_REV_2) {
Expand Down Expand Up @@ -152,6 +155,7 @@ static lv_obj_t *page_power_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_slider_set_value(slider_group_calibration_offset.slider, g_setting.power.calibration_offset, LV_ANIM_OFF);
btn_group_set_sel(&btn_group_osd_display_mode, g_setting.power.osd_display_mode);
btn_group_set_sel(&btn_group_warn_type, g_setting.power.warning_type);
btn_group_set_sel(&btn_group_power_on_beep, g_setting.power.beep_on_power ? 1 : 0);
btn_group_set_sel(&btn_group_power_ana, g_setting.power.power_ana);

page_power_update_cell_count();
Expand Down Expand Up @@ -327,6 +331,12 @@ static void page_power_on_click(uint8_t key, int sel) {
ini_putl("power", "warning_type", g_setting.power.warning_type, SETTING_INI);
break;

case ROW_POWER_BEEP:
btn_group_toggle_sel(&btn_group_power_on_beep);
g_setting.power.beep_on_power = (btn_group_get_sel(&btn_group_power_on_beep) != 0);
settings_put_bool("power", "beep_on_power", g_setting.power.beep_on_power);
break;

case ROW_POWER_ANA:
// Batch 2 goggles only
if (getHwRevision() >= HW_REV_2) {
Expand Down
11 changes: 8 additions & 3 deletions src/ui/ui_main_menu.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ui/ui_main_menu.h"

#include <assert.h>
#include <stdio.h>

#include <log/log.h>
Expand Down Expand Up @@ -100,8 +101,12 @@ void submenu_enter(void) {

if (pp->p_arr.max) {
// if we have selectable entries, select the first selectable one
for (pp->p_arr.cur = 0; !lv_obj_has_flag(pp->p_arr.panel[pp->p_arr.cur], FLAG_SELECTABLE); ++pp->p_arr.cur);
set_select_item(&pp->p_arr, pp->p_arr.cur);
for (pp->p_arr.cur = 0; pp->p_arr.cur < pp->p_arr.max && !lv_obj_has_flag(pp->p_arr.panel[pp->p_arr.cur], FLAG_SELECTABLE); ++pp->p_arr.cur);
if (pp->p_arr.cur == pp->p_arr.max) {
pp->p_arr.cur = 0;
} else {
set_select_item(&pp->p_arr, pp->p_arr.cur);
}
}

if (pp->enter) {
Expand Down Expand Up @@ -264,7 +269,7 @@ void main_menu_show(bool is_show) {

static void main_menu_create_entry(lv_obj_t *menu, lv_obj_t *section, page_pack_t *pp) {
LOGD("creating main menu entry %s", pp->name);

assert(pp->p_arr.max <= MAX_PANELS);
pp->page = pp->create(menu, &pp->p_arr);

lv_obj_t *cont = lv_menu_cont_create(section);
Expand Down