]> git.earman.xyz Git - sensor-watch.git/commitdiff
refactor movement's button preference into a function call
authorjoeycastillo <joeycastillo@utexas.edu>
Sun, 29 Sep 2024 01:57:21 +0000 (21:57 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Sun, 29 Sep 2024 01:57:21 +0000 (21:57 -0400)
18 files changed:
movement.c
movement.h
movement/watch_faces/clock/world_clock2_face.c
movement/watch_faces/complication/couch_to_5k_face.c
movement/watch_faces/complication/deadline_face.c
movement/watch_faces/complication/discgolf_face.c
movement/watch_faces/complication/interval_face.c
movement/watch_faces/complication/kitchen_conversions_face.c
movement/watch_faces/complication/menstrual_cycle_face.c
movement/watch_faces/complication/periodic_face.c
movement/watch_faces/complication/stock_stopwatch_face.c
movement/watch_faces/complication/stopwatch_face.c
movement/watch_faces/complication/tachymeter_face.c
movement/watch_faces/complication/tally_face.c
movement/watch_faces/complication/timer_face.c
movement/watch_faces/sensor/alarm_thermometer_face.c
watch-faces/complication/countdown_face.c
watch-faces/settings/preferences_face.c

index 9a512fcbd95789cac9dd3ce6638da4be683fef58..ff84197cc6d2ef0bf754d5f400621a571a2a85c6 100644 (file)
@@ -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();
 
index 7eecd2be1ddc55e286a97ec1c4e4bc1e5c325e02..661373cb693314a029720731b0de62aa4c2f698e 100644 (file)
@@ -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);
index 2e1e96950fa6d1666c845a637553f4856fe3186b..b678bdd99fa83f69843489a0a1e81dfd96217176 100644 (file)
@@ -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 {
index 8aa3fe6628322c473edb7f70b8049b3a57aa8324..b8bcdef9b3b8144cc00aee64933a9dd51a9f3e75 100644 (file)
@@ -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;
index ae9cab8632e4bd9c93cf3b9d9650988806bc6fd7..c30229c13b2340168532079d9f34e17e14793d20 100644 (file)
@@ -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);
index 7b5142ab4297bc9688cad2f11132c14f676a38e4..61508c0045323666eeb6532c800b6e8e6ff3265f 100644 (file)
@@ -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 */
index f4983236fc6ebf83a838f47b211674c5b51c283e..fb39c9bbd0a9c4a838b8d38d50531ec119d238bb 100644 (file)
@@ -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) {
index c19e755403ed04b7d16d07e0901d150168c8d832..9d1a92dd57f829fddb840ee4a1bdde8ee519f07c 100644 (file)
@@ -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);
             }
         }
index 812de59b8616a5462ac230f3fb7a7d928ccd7680..37cc73034291d93b22b1d9c38d55d752d9670093 100644 (file)
@@ -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);
 }
 
index 69ae4ade329710f235501ec422211427bac63741..909744300ed9b678cada2791eaf29da6a55eec22 100644 (file)
@@ -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;
index 4a9608d91e0e3d08015f458739eca6e18d11ba1e..8e7e3941fb270cde4eab22449e6cf6a241f7b186 100644 (file)
@@ -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
index 03a746970bb67888fba69115afe16ffc0e8fe66b..9931e1c47ad206ba51dd5462ef1272960f4e2032 100644 (file)
@@ -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;
index ea69b2af4e03b6fa40222ce2cb3c128a14bdc73a..056ac845692ff9338d68994adb219afce2cdc419 100644 (file)
@@ -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);
                     }
index 3ea550360ded9e30cfe47d6ba98786e66f00f4be..07b43023e61553862ecf9f904ca02bc1736d437b 100644 (file)
@@ -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
index 29392d694152e9f4845a949252ffb8d971730fe7..aa7f2d9948835a76124c921665df66c6bf81d35d 100644 (file)
@@ -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;
index 3b7821e4858bd1814f4b705d102097d11f4e4dde..5184df9902e76c1a32385fa46a9946623466c370 100644 (file)
@@ -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;
index a0b860600a20047b28ff5eb635043f674ff63286..781481dfccf129238845fdc0dc737f9c12ddfa0a 100644 (file)
@@ -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);
 }
 
index 77c7c8233947f0aa0b9e518f4c23d126ba82037c..07359451cb1764359e3a97ead5718cff72af00e3 100644 (file)
@@ -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;