From 01f1008e169f22a78e42d25755ccaa03c757b14c Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Sat, 28 Sep 2024 21:57:21 -0400 Subject: [PATCH] refactor movement's button preference into a function call --- movement.c | 8 +++++ movement.h | 3 ++ .../watch_faces/clock/world_clock2_face.c | 6 ++-- .../complication/couch_to_5k_face.c | 2 +- .../watch_faces/complication/deadline_face.c | 6 ++-- .../watch_faces/complication/discgolf_face.c | 2 +- .../watch_faces/complication/interval_face.c | 2 +- .../complication/kitchen_conversions_face.c | 10 +++---- .../complication/menstrual_cycle_face.c | 2 +- .../watch_faces/complication/periodic_face.c | 22 +++++++------- .../complication/stock_stopwatch_face.c | 2 +- .../watch_faces/complication/stopwatch_face.c | 2 +- .../complication/tachymeter_face.c | 8 ++--- .../watch_faces/complication/tally_face.c | 30 +++++++++---------- .../watch_faces/complication/timer_face.c | 2 +- .../sensor/alarm_thermometer_face.c | 2 +- watch-faces/complication/countdown_face.c | 2 +- watch-faces/settings/preferences_face.c | 4 +-- 18 files changed, 63 insertions(+), 52 deletions(-) diff --git a/movement.c b/movement.c index 9a512fcb..ff84197c 100644 --- a/movement.c +++ b/movement.c @@ -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(); diff --git a/movement.h b/movement.h index 7eecd2be..661373cb 100644 --- a/movement.h +++ b/movement.h @@ -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); diff --git a/movement/watch_faces/clock/world_clock2_face.c b/movement/watch_faces/clock/world_clock2_face.c index 2e1e9695..b678bdd9 100644 --- a/movement/watch_faces/clock/world_clock2_face.c +++ b/movement/watch_faces/clock/world_clock2_face.c @@ -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 { diff --git a/movement/watch_faces/complication/couch_to_5k_face.c b/movement/watch_faces/complication/couch_to_5k_face.c index 8aa3fe66..b8bcdef9 100644 --- a/movement/watch_faces/complication/couch_to_5k_face.c +++ b/movement/watch_faces/complication/couch_to_5k_face.c @@ -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; diff --git a/movement/watch_faces/complication/deadline_face.c b/movement/watch_faces/complication/deadline_face.c index ae9cab86..c30229c1 100644 --- a/movement/watch_faces/complication/deadline_face.c +++ b/movement/watch_faces/complication/deadline_face.c @@ -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); diff --git a/movement/watch_faces/complication/discgolf_face.c b/movement/watch_faces/complication/discgolf_face.c index 7b5142ab..61508c00 100644 --- a/movement/watch_faces/complication/discgolf_face.c +++ b/movement/watch_faces/complication/discgolf_face.c @@ -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 */ diff --git a/movement/watch_faces/complication/interval_face.c b/movement/watch_faces/complication/interval_face.c index f4983236..fb39c9bb 100644 --- a/movement/watch_faces/complication/interval_face.c +++ b/movement/watch_faces/complication/interval_face.c @@ -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) { diff --git a/movement/watch_faces/complication/kitchen_conversions_face.c b/movement/watch_faces/complication/kitchen_conversions_face.c index c19e7554..9d1a92dd 100644 --- a/movement/watch_faces/complication/kitchen_conversions_face.c +++ b/movement/watch_faces/complication/kitchen_conversions_face.c @@ -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); } } diff --git a/movement/watch_faces/complication/menstrual_cycle_face.c b/movement/watch_faces/complication/menstrual_cycle_face.c index 812de59b..37cc7303 100644 --- a/movement/watch_faces/complication/menstrual_cycle_face.c +++ b/movement/watch_faces/complication/menstrual_cycle_face.c @@ -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); } diff --git a/movement/watch_faces/complication/periodic_face.c b/movement/watch_faces/complication/periodic_face.c index 69ae4ade..90974430 100644 --- a/movement/watch_faces/complication/periodic_face.c +++ b/movement/watch_faces/complication/periodic_face.c @@ -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; diff --git a/movement/watch_faces/complication/stock_stopwatch_face.c b/movement/watch_faces/complication/stock_stopwatch_face.c index 4a9608d9..8e7e3941 100644 --- a/movement/watch_faces/complication/stock_stopwatch_face.c +++ b/movement/watch_faces/complication/stock_stopwatch_face.c @@ -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 diff --git a/movement/watch_faces/complication/stopwatch_face.c b/movement/watch_faces/complication/stopwatch_face.c index 03a74697..9931e1c4 100644 --- a/movement/watch_faces/complication/stopwatch_face.c +++ b/movement/watch_faces/complication/stopwatch_face.c @@ -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; diff --git a/movement/watch_faces/complication/tachymeter_face.c b/movement/watch_faces/complication/tachymeter_face.c index ea69b2af..056ac845 100644 --- a/movement/watch_faces/complication/tachymeter_face.c +++ b/movement/watch_faces/complication/tachymeter_face.c @@ -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); } diff --git a/movement/watch_faces/complication/tally_face.c b/movement/watch_faces/complication/tally_face.c index 3ea55036..07b43023 100644 --- a/movement/watch_faces/complication/tally_face.c +++ b/movement/watch_faces/complication/tally_face.c @@ -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 diff --git a/movement/watch_faces/complication/timer_face.c b/movement/watch_faces/complication/timer_face.c index 29392d69..aa7f2d99 100644 --- a/movement/watch_faces/complication/timer_face.c +++ b/movement/watch_faces/complication/timer_face.c @@ -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; diff --git a/movement/watch_faces/sensor/alarm_thermometer_face.c b/movement/watch_faces/sensor/alarm_thermometer_face.c index 3b7821e4..5184df99 100644 --- a/movement/watch_faces/sensor/alarm_thermometer_face.c +++ b/movement/watch_faces/sensor/alarm_thermometer_face.c @@ -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; diff --git a/watch-faces/complication/countdown_face.c b/watch-faces/complication/countdown_face.c index a0b86060..781481df 100644 --- a/watch-faces/complication/countdown_face.c +++ b/watch-faces/complication/countdown_face.c @@ -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); } diff --git a/watch-faces/settings/preferences_face.c b/watch-faces/settings/preferences_face.c index 77c7c823..07359451 100644 --- a/watch-faces/settings/preferences_face.c +++ b/watch-faces/settings/preferences_face.c @@ -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;