]> git.earman.xyz Git - sensor-watch.git/commitdiff
movement: add loudness setting for button press
authorJoey Castillo <joeycastillo@utexas.edu>
Tue, 20 May 2025 21:27:32 +0000 (17:27 -0400)
committerJoey Castillo <joeycastillo@utexas.edu>
Tue, 20 May 2025 21:27:32 +0000 (17:27 -0400)
movement.c
movement.h
movement_config.h
watch-faces/complication/countdown_face.c
watch-faces/complication/fast_stopwatch_face.c
watch-faces/complication/stopwatch_face.c
watch-faces/settings/settings_face.c

index a6492c9a9e4f98ae270f7fa3195f0254be71804e..773a3742e5ea6a37635ed04d791a2462cd77fd37 100644 (file)
@@ -434,6 +434,14 @@ void movement_set_button_should_sound(bool value) {
     movement_state.settings.bit.button_should_sound = value;
 }
 
+watch_buzzer_volume_t movement_button_volume(void) {
+    return movement_state.settings.bit.button_volume;
+}
+
+void movement_set_button_volume(watch_buzzer_volume_t value) {
+    movement_state.settings.bit.button_volume = value;
+}
+
 movement_clock_mode_t movement_clock_mode_24h(void) {
     return movement_state.settings.bit.clock_mode_24h ? MOVEMENT_CLOCK_MODE_24H : MOVEMENT_CLOCK_MODE_12H;
 }
@@ -609,6 +617,7 @@ void app_init(void) {
         movement_state.settings.bit.led_blue_color = MOVEMENT_DEFAULT_BLUE_COLOR;
     #endif
         movement_state.settings.bit.button_should_sound = MOVEMENT_DEFAULT_BUTTON_SOUND;
+        movement_state.settings.bit.button_volume = MOVEMENT_DEFAULT_BUTTON_VOLUME;
         movement_state.settings.bit.to_interval = MOVEMENT_DEFAULT_TIMEOUT_INTERVAL;
         movement_state.settings.bit.le_interval = MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL;
         movement_state.settings.bit.led_duration = MOVEMENT_DEFAULT_LED_DURATION;
@@ -767,7 +776,7 @@ bool app_loop(void) {
     if (movement_state.watch_face_changed) {
         if (movement_state.settings.bit.button_should_sound) {
             // low note for nonzero case, high note for return to watch_face 0
-            watch_buzzer_play_note_with_volume(movement_state.next_face_idx ? BUZZER_NOTE_C7 : BUZZER_NOTE_C8, 50, WATCH_BUZZER_VOLUME_SOFT);
+            watch_buzzer_play_note_with_volume(movement_state.next_face_idx ? BUZZER_NOTE_C7 : BUZZER_NOTE_C8, 50, movement_state.settings.bit.button_volume);
         }
         wf->resign(watch_face_contexts[movement_state.current_face_idx]);
         movement_state.current_face_idx = movement_state.next_face_idx;
index 817c28411982210b0f678094cb31d89f11b42c57..5626385af0fb9e181bd3ae42a0109e0b102ce4dc 100644 (file)
@@ -83,8 +83,7 @@ typedef union {
         bool clock_mode_24h : 1;            // indicates whether clock should use 12 or 24 hour mode.
         bool use_imperial_units : 1;        // indicates whether to use metric units (the default) or imperial.
         
-        // That's 31 bits, leaving room for one more toggle if needed.
-        uint8_t reserved : 1;
+        bool button_volume : 1;             // 0 for soft beep, 1 for loud beep. If button_should_sound (above) is false, this is ignored.
     } bit;
     uint32_t reg;
 } movement_settings_t;
@@ -341,6 +340,9 @@ void movement_set_local_date_time(watch_date_time_t date_time);
 bool movement_button_should_sound(void);
 void movement_set_button_should_sound(bool value);
 
+watch_buzzer_volume_t movement_button_volume(void);
+void movement_set_button_volume(watch_buzzer_volume_t value);
+
 movement_clock_mode_t movement_clock_mode_24h(void);
 void movement_set_clock_mode_24h(movement_clock_mode_t value);
 
index a3578ff11d3a763cf3ac6490289913b49684523c..6a960b827e5a8c63efb6d6943b6d797a07c28151 100644 (file)
@@ -66,6 +66,8 @@ const watch_face_t watch_faces[] = {
 /* Enable or disable the sound on mode button press */
 #define MOVEMENT_DEFAULT_BUTTON_SOUND true
 
+#define MOVEMENT_DEFAULT_BUTTON_VOLUME WATCH_BUZZER_VOLUME_SOFT
+
 /* Set the timeout before switching back to the main watch face
  * Valid values are:
  * 0: 60 seconds
index 5314acead40042f43701a289e51b25caa0f0ec7d..19de57e01094d434fd5ac2a2b414c6d5f9912769 100644 (file)
@@ -67,7 +67,7 @@ static inline void load_countdown(countdown_state_t *state) {
 
 static inline void button_beep() {
     // play a beep as confirmation for a button press (if applicable)
-    if (movement_button_should_sound()) watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, WATCH_BUZZER_VOLUME_SOFT);
+    if (movement_button_should_sound()) watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, movement_button_volume());
 }
 
 static void schedule_countdown(countdown_state_t *state) {
index 4ee8ca65fe25f4bbb768efd705046847b11394ce..ce998102ad89782cbc7dc143c3727cace76e3192 100644 (file)
@@ -121,7 +121,7 @@ void irq_handler_tc1(void) {
 
 static inline void _button_beep() {
     // play a beep as confirmation for a button press (if applicable)
-    if (movement_button_should_sound()) watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, WATCH_BUZZER_VOLUME_SOFT);
+    if (movement_button_should_sound()) watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, movement_button_volume());
 }
 
 /// @brief Display minutes, seconds and fractions derived from 128 Hz tick counter
index 4a2bfcf9301a504ccb8c093f8bede2c1315fb86a..e7e5ebb126d527f41f3752012866221038c513d5 100644 (file)
@@ -118,7 +118,7 @@ bool stopwatch_face_loop(movement_event_t event, void *context) {
             break;
         case EVENT_ALARM_BUTTON_DOWN:
             if (movement_button_should_sound()) {
-                watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, WATCH_BUZZER_VOLUME_SOFT);
+                watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, movement_button_volume());
             }
             stopwatch_state->running = !stopwatch_state->running;
             if (stopwatch_state->running) {
index c39aec0ffe0ac1fb29d9713b308834dc1a8c741e..7d1b392c754f810671f49404aca879874bbd5a82 100644 (file)
@@ -42,16 +42,39 @@ static void beep_setting_display(uint8_t subsecond) {
     watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "BTN", "BT");
     watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, "beep  ", " beep ");
     if (subsecond % 2) {
-            if (movement_button_should_sound()) {
-            watch_display_text(WATCH_POSITION_TOP_RIGHT, " Y");
+        if (movement_button_should_sound()) {
+            if (movement_button_volume() == WATCH_BUZZER_VOLUME_LOUD) {
+                // H for HIGH
+                watch_display_text(WATCH_POSITION_TOP_RIGHT, " H");
+            }
+            else {
+                // L for LOW
+                watch_display_text(WATCH_POSITION_TOP_RIGHT, " L");
+            }
         } else {
+            // N for NONE
             watch_display_text(WATCH_POSITION_TOP_RIGHT, " N");
         }
     }
 }
 
 static void beep_setting_advance(void) {
-    movement_set_button_should_sound(!movement_button_should_sound());
+    if (!movement_button_should_sound()) {
+        // was muted. make it soft.
+        movement_set_button_should_sound(true);
+        movement_set_button_volume(WATCH_BUZZER_VOLUME_SOFT);
+        beep_setting_display(1);
+        watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, WATCH_BUZZER_VOLUME_SOFT);
+    } else if (movement_button_volume() == WATCH_BUZZER_VOLUME_SOFT) {
+        // was soft. make it loud.
+        movement_set_button_volume(WATCH_BUZZER_VOLUME_LOUD);
+        beep_setting_display(1);
+        watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, WATCH_BUZZER_VOLUME_LOUD);
+    } else {
+        // was loud. make it silent.
+        movement_set_button_should_sound(false);
+        beep_setting_display(1);
+    }
 }
 
 static void timeout_setting_display(uint8_t subsecond) {