refactor movement's button preference into a function call
This commit is contained in:
parent
fec225ec8b
commit
01f1008e16
@ -329,6 +329,14 @@ int32_t movement_get_current_timezone_offset(void) {
|
||||
return movement_get_current_timezone_offset_for_zone(movement_state.settings.bit.time_zone);
|
||||
}
|
||||
|
||||
bool movement_button_should_sound(void) {
|
||||
return movement_state.settings.bit.button_should_sound;
|
||||
}
|
||||
|
||||
void movement_set_button_should_sound(bool value) {
|
||||
movement_state.settings.bit.button_should_sound = value;
|
||||
}
|
||||
|
||||
void app_init(void) {
|
||||
_watch_init();
|
||||
|
||||
|
||||
@ -318,3 +318,6 @@ uint8_t movement_claim_backup_register(void);
|
||||
|
||||
int32_t movement_get_current_timezone_offset_for_zone(uint8_t zone_index);
|
||||
int32_t movement_get_current_timezone_offset(void);
|
||||
|
||||
bool movement_button_should_sound(void);
|
||||
void movement_set_button_should_sound(bool value);
|
||||
|
||||
@ -251,7 +251,7 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
|
||||
refresh_face = true;
|
||||
movement_request_tick_frequency(1);
|
||||
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
break;
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
@ -330,7 +330,7 @@ static bool mode_settings(movement_event_t event, movement_settings_t *settings,
|
||||
refresh_face = true;
|
||||
movement_request_tick_frequency(1);
|
||||
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
break;
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
@ -338,7 +338,7 @@ static bool mode_settings(movement_event_t event, movement_settings_t *settings,
|
||||
zone = state->current_zone;
|
||||
state->zones[zone].selected = !state->zones[zone].selected;
|
||||
|
||||
if (settings->bit.button_should_sound) {
|
||||
if (movement_button_should_sound()) {
|
||||
if (state->zones[zone].selected) {
|
||||
beep_enable();
|
||||
} else {
|
||||
|
||||
@ -214,7 +214,7 @@ bool couch_to_5k_face_loop(movement_event_t event, movement_settings_t *settings
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
if (settings->bit.button_should_sound) {
|
||||
if (movement_button_should_sound()) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
}
|
||||
paused = !paused;
|
||||
|
||||
@ -166,7 +166,7 @@ static inline int32_t _get_tz_offset(movement_settings_t *settings)
|
||||
static inline void _beep_button(movement_settings_t *settings)
|
||||
{
|
||||
// Play a beep as confirmation for a button press (if applicable)
|
||||
if (!settings->bit.button_should_sound)
|
||||
if (!movement_button_should_sound())
|
||||
return;
|
||||
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
@ -175,7 +175,7 @@ static inline void _beep_button(movement_settings_t *settings)
|
||||
/* Beep for entering settings */
|
||||
static inline void _beep_enable(movement_settings_t *settings)
|
||||
{
|
||||
if (!settings->bit.button_should_sound)
|
||||
if (!movement_button_should_sound())
|
||||
return;
|
||||
|
||||
watch_buzzer_play_note(BUZZER_NOTE_G7, 50);
|
||||
@ -186,7 +186,7 @@ static inline void _beep_enable(movement_settings_t *settings)
|
||||
/* Beep for leaving settings */
|
||||
static inline void _beep_disable(movement_settings_t *settings)
|
||||
{
|
||||
if (!settings->bit.button_should_sound)
|
||||
if (!movement_button_should_sound())
|
||||
return;
|
||||
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
|
||||
@ -88,7 +88,7 @@ static const char labels[][2] = {
|
||||
|
||||
/* Beep function */
|
||||
static inline void beep(movement_settings_t *settings) {
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
}
|
||||
|
||||
/* Prep for a new round */
|
||||
|
||||
@ -99,7 +99,7 @@ static uint32_t _get_now_ts() {
|
||||
|
||||
static inline void _button_beep(movement_settings_t *settings) {
|
||||
// play a beep as confirmation for a button press (if applicable)
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
}
|
||||
|
||||
static void _timer_write_info(interval_face_state_t *state, char *buf, uint8_t timer_page) {
|
||||
|
||||
@ -257,7 +257,7 @@ static void display(kitchen_conversions_state_t *state, movement_settings_t *set
|
||||
watch_set_indicator(WATCH_INDICATOR_BELL);
|
||||
watch_display_string("Err", 5);
|
||||
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_sequence(calc_fail_seq, NULL);
|
||||
}
|
||||
else
|
||||
@ -277,7 +277,7 @@ static void display(kitchen_conversions_state_t *state, movement_settings_t *set
|
||||
watch_display_string("0", 7);
|
||||
}
|
||||
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_sequence(calc_success_seq, NULL);
|
||||
}
|
||||
watch_display_string("=", 1);
|
||||
@ -373,7 +373,7 @@ bool kitchen_conversions_face_loop(movement_event_t event, movement_settings_t *
|
||||
}
|
||||
|
||||
// Play boop
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
}
|
||||
|
||||
@ -420,7 +420,7 @@ bool kitchen_conversions_face_loop(movement_event_t event, movement_settings_t *
|
||||
display(state, settings, event.subsecond);
|
||||
|
||||
// Play beep
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
|
||||
state->light_held = false;
|
||||
@ -445,7 +445,7 @@ bool kitchen_conversions_face_loop(movement_event_t event, movement_settings_t *
|
||||
display(state, settings, event.subsecond);
|
||||
|
||||
// Play bleep
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_note(BUZZER_NOTE_E7, 50);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ const char menstrual_cycle_face_titles[MENSTRUAL_CYCLE_FACE_NUM_PAGES][11] = {
|
||||
|
||||
/* Beep function */
|
||||
static inline void beep(movement_settings_t *settings) {
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_note(BUZZER_NOTE_E8, 75);
|
||||
}
|
||||
|
||||
|
||||
@ -408,38 +408,38 @@ bool periodic_face_loop(movement_event_t event, movement_settings_t *settings, v
|
||||
else stop_quick_cyc();
|
||||
}
|
||||
|
||||
_handle_mode_still_pressed(state, settings->bit.button_should_sound);
|
||||
_handle_mode_still_pressed(state, movement_button_should_sound());
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
if (state->mode <= SCREEN_ELEMENT) {
|
||||
_handle_backward(state, settings->bit.button_should_sound);
|
||||
_handle_backward(state, movement_button_should_sound());
|
||||
}
|
||||
else {
|
||||
state->mode = SCREEN_ELEMENT;
|
||||
_display_screen(state, settings->bit.button_should_sound);
|
||||
_display_screen(state, movement_button_should_sound());
|
||||
}
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_DOWN:
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
if (state->mode <= SCREEN_ELEMENT) {
|
||||
_handle_forward(state, settings->bit.button_should_sound);
|
||||
_handle_forward(state, movement_button_should_sound());
|
||||
}
|
||||
else {
|
||||
state->mode = SCREEN_ELEMENT;
|
||||
_display_screen(state, settings->bit.button_should_sound);
|
||||
_display_screen(state, movement_button_should_sound());
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
if (state->mode <= SCREEN_ELEMENT) {
|
||||
start_quick_cyc();
|
||||
_handle_forward(state, settings->bit.button_should_sound);
|
||||
_handle_forward(state, movement_button_should_sound());
|
||||
}
|
||||
break;
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
if (state->mode <= SCREEN_ELEMENT) {
|
||||
start_quick_cyc();
|
||||
_handle_backward(state, settings->bit.button_should_sound);
|
||||
_handle_backward(state, movement_button_should_sound());
|
||||
}
|
||||
else {
|
||||
movement_illuminate_led();
|
||||
@ -453,10 +453,10 @@ bool periodic_face_loop(movement_event_t event, movement_settings_t *settings, v
|
||||
state->mode = (state->mode + 1) % SCREENS_COUNT;
|
||||
if (state->mode == SCREEN_ELEMENT){
|
||||
_display_screen(state, false);
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_A6, 50);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_A6, 50);
|
||||
}
|
||||
else
|
||||
_display_screen(state, settings->bit.button_should_sound);
|
||||
_display_screen(state, movement_button_should_sound());
|
||||
}
|
||||
break;
|
||||
case EVENT_MODE_LONG_PRESS:
|
||||
@ -467,11 +467,11 @@ bool periodic_face_loop(movement_event_t event, movement_settings_t *settings, v
|
||||
return true;
|
||||
case SCREEN_ELEMENT:
|
||||
state->mode = SCREEN_TITLE;
|
||||
_display_screen(state, settings->bit.button_should_sound);
|
||||
_display_screen(state, movement_button_should_sound());
|
||||
break;
|
||||
default:
|
||||
state->mode = SCREEN_ELEMENT;
|
||||
_display_screen(state, settings->bit.button_should_sound);
|
||||
_display_screen(state, movement_button_should_sound());
|
||||
break;
|
||||
}
|
||||
_ts_ticks = 2;
|
||||
|
||||
@ -125,7 +125,7 @@ void TC2_Handler(void) {
|
||||
|
||||
static inline void _button_beep(movement_settings_t *settings) {
|
||||
// play a beep as confirmation for a button press (if applicable)
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
}
|
||||
|
||||
/// @brief Display minutes, seconds and fractions derived from 128 Hz tick counter
|
||||
|
||||
@ -116,7 +116,7 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings,
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_DOWN:
|
||||
if (settings->bit.button_should_sound) {
|
||||
if (movement_button_should_sound()) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
}
|
||||
stopwatch_state->running = !stopwatch_state->running;
|
||||
|
||||
@ -167,7 +167,7 @@ bool tachymeter_face_loop(movement_event_t event, movement_settings_t *settings,
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
if (!state->running && state->total_time == 0){
|
||||
if (settings->bit.button_should_sound && !state->editing) {
|
||||
if (movement_button_should_sound() && !state->editing) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
}
|
||||
if (!state->editing) {
|
||||
@ -200,7 +200,7 @@ bool tachymeter_face_loop(movement_event_t event, movement_settings_t *settings,
|
||||
}
|
||||
}
|
||||
} else if (state->running) {
|
||||
if (settings->bit.button_should_sound && !state->editing) {
|
||||
if (movement_button_should_sound() && !state->editing) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
|
||||
}
|
||||
// Stop running
|
||||
@ -220,7 +220,7 @@ bool tachymeter_face_loop(movement_event_t event, movement_settings_t *settings,
|
||||
// Enter editing
|
||||
state->editing = true;
|
||||
state->active_digit = 0;
|
||||
if (settings->bit.button_should_sound) {
|
||||
if (movement_button_should_sound()) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C7, 80);
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 80);
|
||||
}
|
||||
@ -232,7 +232,7 @@ bool tachymeter_face_loop(movement_event_t event, movement_settings_t *settings,
|
||||
state->dist_digits.ones = 1;
|
||||
}
|
||||
_tachymeter_face_distance_lcd(event, state);
|
||||
if (settings->bit.button_should_sound) {
|
||||
if (movement_button_should_sound()) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 80);
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C7, 80);
|
||||
}
|
||||
|
||||
@ -130,16 +130,16 @@ bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void
|
||||
bool light_pressed = watch_get_pin_level(BTN_LIGHT);
|
||||
bool alarm_pressed = watch_get_pin_level(BTN_ALARM);
|
||||
if (light_pressed && alarm_pressed) stop_quick_cyc();
|
||||
else if (light_pressed) tally_face_increment(state, settings->bit.button_should_sound);
|
||||
else if (alarm_pressed) tally_face_decrement(state, settings->bit.button_should_sound);
|
||||
else if (light_pressed) tally_face_increment(state, movement_button_should_sound());
|
||||
else if (alarm_pressed) tally_face_decrement(state, movement_button_should_sound());
|
||||
else stop_quick_cyc();
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
tally_face_decrement(state, settings->bit.button_should_sound);
|
||||
tally_face_decrement(state, movement_button_should_sound());
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
tally_face_decrement(state, settings->bit.button_should_sound);
|
||||
tally_face_decrement(state, movement_button_should_sound());
|
||||
start_quick_cyc();
|
||||
break;
|
||||
case EVENT_MODE_LONG_PRESS:
|
||||
@ -151,14 +151,14 @@ bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void
|
||||
state->tally_idx = _tally_default[state->tally_default_idx]; // reset tally index
|
||||
_init_val = true;
|
||||
//play a reset tune
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
|
||||
print_tally(state, settings->bit.button_should_sound);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
|
||||
print_tally(state, movement_button_should_sound());
|
||||
}
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
tally_face_increment(state, settings->bit.button_should_sound);
|
||||
tally_face_increment(state, movement_button_should_sound());
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_DOWN:
|
||||
case EVENT_ALARM_BUTTON_DOWN:
|
||||
@ -171,18 +171,18 @@ bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void
|
||||
if (TALLY_FACE_PRESETS_SIZE() > 1 && _init_val){
|
||||
state->tally_default_idx = (state->tally_default_idx + 1) % TALLY_FACE_PRESETS_SIZE();
|
||||
state->tally_idx = _tally_default[state->tally_default_idx];
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
|
||||
print_tally(state, settings->bit.button_should_sound);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
|
||||
print_tally(state, movement_button_should_sound());
|
||||
}
|
||||
else{
|
||||
tally_face_increment(state, settings->bit.button_should_sound);
|
||||
tally_face_increment(state, movement_button_should_sound());
|
||||
start_quick_cyc();
|
||||
}
|
||||
break;
|
||||
case EVENT_ACTIVATE:
|
||||
print_tally(state, settings->bit.button_should_sound);
|
||||
print_tally(state, movement_button_should_sound());
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
// ignore timeout
|
||||
|
||||
@ -331,7 +331,7 @@ bool timer_face_loop(movement_event_t event, movement_settings_t *settings, void
|
||||
case pausing:
|
||||
case running:
|
||||
_reset(state);
|
||||
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -119,7 +119,7 @@ bool alarm_thermometer_face_loop(movement_event_t event, movement_settings_t *se
|
||||
_alarm_thermometer_face_update(settings->bit.use_imperial_units);
|
||||
break;
|
||||
}
|
||||
if (settings->bit.button_should_sound) {
|
||||
if (movement_button_should_sound()) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -61,7 +61,7 @@ static inline void load_countdown(countdown_state_t *state) {
|
||||
|
||||
static inline void button_beep(movement_settings_t *settings) {
|
||||
// play a beep as confirmation for a button press (if applicable)
|
||||
if (settings->bit.button_should_sound)
|
||||
if (movement_button_should_sound())
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C7, 50);
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
|
||||
else watch_display_text(WATCH_POSITION_BOTTOM, "12h");
|
||||
break;
|
||||
case PREFERENCES_PAGE_BUTTON_SOUND:
|
||||
if (settings->bit.button_should_sound) {
|
||||
if (movement_button_should_sound()) {
|
||||
watch_display_text(WATCH_POSITION_TOP_RIGHT, " Y");
|
||||
} else {
|
||||
watch_display_text(WATCH_POSITION_TOP_RIGHT, " N");
|
||||
@ -182,7 +182,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
|
||||
settings->bit.clock_mode_24h = !settings->bit.clock_mode_24h;
|
||||
break;
|
||||
case PREFERENCES_PAGE_BUTTON_SOUND:
|
||||
settings->bit.button_should_sound = !settings->bit.button_should_sound;
|
||||
movement_set_button_should_sound(!movement_button_should_sound());
|
||||
break;
|
||||
case PREFERENCES_PAGE_TIMEOUT:
|
||||
settings->bit.to_interval = settings->bit.to_interval + 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user