diff options
author | joeycastillo <joeycastillo@utexas.edu> | 2023-01-17 10:52:42 -0600 |
---|---|---|
committer | joeycastillo <joeycastillo@utexas.edu> | 2023-01-17 10:52:42 -0600 |
commit | 3142fccea3d19dc5b41313627f444851407238a9 (patch) | |
tree | 556c53d0318ac1d56800ed81f16c5606830207c9 | |
parent | a610382f89165370bd9239546dcc4f2fe9bf9e1c (diff) | |
parent | 5163cf1fe1e8bf878bf8d4e54b1fa24dccb4e116 (diff) | |
download | Sensor-Watch-3142fccea3d19dc5b41313627f444851407238a9.tar.gz Sensor-Watch-3142fccea3d19dc5b41313627f444851407238a9.tar.bz2 Sensor-Watch-3142fccea3d19dc5b41313627f444851407238a9.zip |
Merge branch 'main' into default-handler
-rw-r--r-- | movement/watch_faces/clock/simple_clock_face.c | 12 | ||||
-rw-r--r-- | movement/watch_faces/clock/weeknumber_clock_face.c | 12 | ||||
-rw-r--r-- | movement/watch_faces/complication/alarm_face.c | 10 | ||||
-rw-r--r-- | movement/watch_faces/complication/rpn_calculator_face.c | 30 | ||||
-rw-r--r-- | watch-library/hardware/watch/watch_buzzer.c | 4 |
5 files changed, 48 insertions, 20 deletions
diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index fbc2c4b3..91400b6c 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -136,7 +136,17 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - movement_play_signal(); + if (watch_is_buzzer_or_led_enabled()) { + // if we are in the foreground, we can just beep. + movement_play_signal(); + } else { + // if we were in the background, we need to enable the buzzer peripheral first, + watch_enable_buzzer(); + // beep quickly (this call blocks for 275 ms), + movement_play_signal(); + // and then turn the buzzer peripheral off again. + watch_disable_buzzer(); + } break; default: return movement_default_loop_handler(event, settings); diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 45d751af..e49e5abf 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -136,7 +136,17 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - movement_play_signal(); + if (watch_is_buzzer_or_led_enabled()) { + // if we are in the foreground, we can just beep. + movement_play_signal(); + } else { + // if we were in the background, we need to enable the buzzer peripheral first, + watch_enable_buzzer(); + // beep quickly (this call blocks for 275 ms), + movement_play_signal(); + // and then turn the buzzer peripheral off again. + watch_disable_buzzer(); + } break; default: break; diff --git a/movement/watch_faces/complication/alarm_face.c b/movement/watch_faces/complication/alarm_face.c index 9acf5899..5ad3976c 100644 --- a/movement/watch_faces/complication/alarm_face.c +++ b/movement/watch_faces/complication/alarm_face.c @@ -417,7 +417,15 @@ bool alarm_face_loop(movement_event_t event, movement_settings_t *settings, void case EVENT_BACKGROUND_TASK: // play alarm if (state->alarm[state->alarm_playing_idx].beeps == 0) { - _alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch); + // short beep + if (watch_is_buzzer_or_led_enabled()) { + _alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch); + } else { + // enable, play beep and disable buzzer again + watch_enable_buzzer(); + _alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch); + watch_disable_buzzer(); + } } else { // regular alarm beeps movement_play_alarm_beeps((state->alarm[state->alarm_playing_idx].beeps == (ALARM_MAX_BEEP_ROUNDS - 1) ? 20 : state->alarm[state->alarm_playing_idx].beeps), diff --git a/movement/watch_faces/complication/rpn_calculator_face.c b/movement/watch_faces/complication/rpn_calculator_face.c index 5ba5e559..9271a101 100644 --- a/movement/watch_faces/complication/rpn_calculator_face.c +++ b/movement/watch_faces/complication/rpn_calculator_face.c @@ -79,7 +79,7 @@ static void next_op(rpn_calculator_state_t *state) { // FIXME: this converts the number to string and back, there might // be better ways to do this static float inc_digit(float num, uint8_t position) { - char buf[7]; + char buf[8]; if (position > 5) { return 0.0; } @@ -203,7 +203,7 @@ static void run_op(rpn_calculator_state_t *state) { state->mode = rpn_calculator_err; } -static void draw(rpn_calculator_state_t *state, uint8_t subsecond, movement_settings_t *settings) { +static void draw(rpn_calculator_state_t *state, uint8_t subsecond) { char buf[16]; switch (state->mode) { case rpn_calculator_err: @@ -234,6 +234,7 @@ static void draw(rpn_calculator_state_t *state, uint8_t subsecond, movement_sett void rpn_calculator_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; + (void) watch_face_index; if (*context_ptr == NULL) { *context_ptr = malloc(sizeof(rpn_calculator_state_t)); memset(*context_ptr, 0, sizeof(rpn_calculator_state_t)); @@ -246,29 +247,30 @@ void rpn_calculator_face_setup(movement_settings_t *settings, uint8_t watch_face void rpn_calculator_face_activate(movement_settings_t *settings, void *context) { (void) settings; - rpn_calculator_state_t *state = (rpn_calculator_state_t *)context; - (void) state; + (void) context; // Handle any tasks related to your watch face coming on screen. } bool rpn_calculator_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + rpn_calculator_state_t *state = (rpn_calculator_state_t *)context; switch (event.event_type) { case EVENT_ACTIVATE: - draw(state, event.subsecond, settings); + draw(state, event.subsecond); break; case EVENT_TICK: if (state->mode == rpn_calculator_number) { - draw(state, event.subsecond, settings); + draw(state, event.subsecond); } break; case EVENT_MODE_BUTTON_UP: switch (state->mode) { case rpn_calculator_number: state->mode = rpn_calculator_waiting; - draw(state, event.subsecond, settings); + draw(state, event.subsecond); movement_request_tick_frequency(1); break; default: @@ -282,15 +284,15 @@ bool rpn_calculator_face_loop(movement_event_t event, movement_settings_t *setti switch (state->mode) { case rpn_calculator_waiting: state->mode = rpn_calculator_op; - draw(state, event.subsecond, settings); + draw(state, event.subsecond); break; case rpn_calculator_number: state->selection = (state->selection + 1) % 6; - draw(state, event.subsecond, settings); + draw(state, event.subsecond); break; case rpn_calculator_op: next_op(state); - draw(state, event.subsecond, settings); + draw(state, event.subsecond); break; default: movement_illuminate_led(); @@ -303,21 +305,21 @@ bool rpn_calculator_face_loop(movement_event_t event, movement_settings_t *setti state->mode = rpn_calculator_number; state->selection = 2; stack_push(state, 0); - draw(state, event.subsecond, settings); + draw(state, event.subsecond); movement_request_tick_frequency(4); break; case rpn_calculator_number: state->stack[state->top] = inc_digit(state->stack[state->top], state->selection); printf_stack(state); - draw(state, event.subsecond, settings); + draw(state, event.subsecond); break; case rpn_calculator_err: state->mode = rpn_calculator_waiting; - draw(state, event.subsecond, settings); + draw(state, event.subsecond); break; case rpn_calculator_op: run_op(state); - draw(state, event.subsecond, settings); + draw(state, event.subsecond); break; default: break; diff --git a/watch-library/hardware/watch/watch_buzzer.c b/watch-library/hardware/watch/watch_buzzer.c index b999397a..18fb4db0 100644 --- a/watch-library/hardware/watch/watch_buzzer.c +++ b/watch-library/hardware/watch/watch_buzzer.c @@ -147,7 +147,6 @@ inline void watch_enable_buzzer(void) { if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { _watch_enable_tcc(); } - gpio_set_pin_direction(BUZZER, GPIO_DIRECTION_OUT); } inline void watch_set_buzzer_period(uint32_t period) { @@ -157,7 +156,6 @@ inline void watch_set_buzzer_period(uint32_t period) { void watch_disable_buzzer(void) { _watch_disable_tcc(); - watch_set_buzzer_off(); } inline void watch_set_buzzer_on(void) { @@ -166,8 +164,8 @@ inline void watch_set_buzzer_on(void) { } inline void watch_set_buzzer_off(void) { + gpio_set_pin_direction(BUZZER, GPIO_DIRECTION_OFF); gpio_set_pin_function(BUZZER, GPIO_PIN_FUNCTION_OFF); - gpio_set_pin_level(BUZZER, true); } void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms) { |