Skip to content

Commit

Permalink
feat: stealth mode menu improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Aug 29, 2024
1 parent 89efe80 commit e3b2ce3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
3 changes: 0 additions & 3 deletions firmware/components/buzzer/buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ void buzzer_play_for(uint32_t duration) {
}

void buzzer_stop() {
if (!buzzer.enabled) {
return;
}
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ static void input_cb(uint8_t button_name, uint8_t button_event) {
free(general_radio_selection_ctx);
break;
case BUTTON_RIGHT:
buzzer_play_for(SOUND_DURATION);
general_radio_selection_ctx->current_option =
general_radio_selection_ctx->selected_option;
void (*select_cb)() = general_radio_selection_ctx->select_cb;
if (select_cb) {
select_cb(general_radio_selection_ctx->current_option);
}
buzzer_play_for(SOUND_DURATION);
list_radio_options();
break;
case BUTTON_UP:
Expand Down
22 changes: 14 additions & 8 deletions firmware/main/modules/settings/stealth_mode/stealth_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

#include "buzzer.h"
#include "coroutine.h"
#include "general_radio_selection.h"
#include "leds.h"
#include "menus_module.h"
#include "modals_module.h"
#include "preferences.h"

static void set_stealth_status() {
uint8_t stealth_mode = preferences_get_bool("stealth_mode", false);
char* stealth_options[] = {"Disabled", "Enabled"};
stealth_mode = modals_module_get_radio_selection(
stealth_options, "Stealth Mode", stealth_mode);
char* stealth_mode_options[] = {"Disabled", "Enabled"};

static void stealth_selection_handler(uint8_t stealth_mode) {
preferences_put_bool("stealth_mode", stealth_mode);
if (stealth_mode) {
buzzer_disable();
Expand All @@ -23,10 +22,17 @@ static void set_stealth_status() {
buzzer_enable();
leds_begin();
}
menus_module_restart();
vTaskDelete(NULL);
}

void stealth_mode_open_menu() {
start_coroutine(set_stealth_status, NULL);
general_radio_selection_menu_t stealth_mode_radio_menu;
stealth_mode_radio_menu.banner = "Stealth Mode";
stealth_mode_radio_menu.exit_cb = menus_module_exit_app;
stealth_mode_radio_menu.options = stealth_mode_options;
stealth_mode_radio_menu.options_count = 2;
stealth_mode_radio_menu.style = RADIO_SELECTION_OLD_STYLE;
stealth_mode_radio_menu.current_option =
preferences_get_bool("stealth_mode", false);
stealth_mode_radio_menu.select_cb = stealth_selection_handler;
general_radio_selection(stealth_mode_radio_menu);
}

0 comments on commit e3b2ce3

Please sign in to comment.