diff options
Diffstat (limited to 'movement/movement.c')
-rw-r--r-- | movement/movement.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/movement/movement.c b/movement/movement.c index 33ca14c7..f313bd79 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -261,11 +261,16 @@ void movement_play_signal(void) { } void movement_play_alarm(void) { + movement_play_alarm_beeps(5, BUZZER_NOTE_C8); +} + +void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note) { + if (rounds == 0) rounds = 1; + if (rounds > 20) rounds = 20; movement_request_wake(); - // alarm length: 75 ticks short of 5 seconds, or 4.414 seconds: - // our tone is 0.375 seconds of beep and 0.625 of silence, repeated five times. - // so 4.375 + a few ticks to wake up from sleep mode. - movement_state.alarm_ticks = 128 * 5 - 75; + movement_state.alarm_note = alarm_note; + // our tone is 0.375 seconds of beep and 0.625 of silence, repeated as given. + movement_state.alarm_ticks = 128 * rounds - 75; _movement_enable_fast_tick_if_needed(); } @@ -468,10 +473,13 @@ bool app_loop(void) { if (movement_state.alarm_ticks >= 0) { uint8_t buzzer_phase = (movement_state.alarm_ticks + 80) % 128; if(buzzer_phase == 127) { + // failsafe: buzzer could have been disabled in the meantime + if (!watch_is_buzzer_or_led_enabled()) watch_enable_buzzer(); + // play 4 beeps plus pause for(uint8_t i = 0; i < 4; i++) { // TODO: This method of playing the buzzer blocks the UI while it's beeping. // It might be better to time it with the fast tick. - watch_buzzer_play_note(BUZZER_NOTE_C8, (i != 3) ? 50 : 75); + watch_buzzer_play_note(movement_state.alarm_note, (i != 3) ? 50 : 75); if (i != 3) watch_buzzer_play_note(BUZZER_NOTE_REST, 50); } } @@ -528,7 +536,7 @@ static movement_event_type_t _figure_out_button_event(bool pin_level, movement_e *down_timestamp = movement_state.fast_ticks + 1; return button_down_event_type; } else { - // this line is hack but it handles the situation where the light button was held for more than 10 seconds. + // this line is hack but it handles the situation where the light button was held for more than 20 seconds. // fast tick is disabled by then, and the LED would get stuck on since there's no one left decrementing light_ticks. if (movement_state.light_ticks == 1) movement_state.light_ticks = 0; // now that that's out of the way, handle falling edge @@ -573,8 +581,8 @@ void cb_fast_tick(void) { if (movement_state.light_ticks > 0) movement_state.light_ticks--; if (movement_state.alarm_ticks > 0) movement_state.alarm_ticks--; // this is just a fail-safe; fast tick should be disabled as soon as the button is up, the LED times out, and/or the alarm finishes. - // but if for whatever reason it isn't, this forces the fast tick off after 10 seconds. - if (movement_state.fast_ticks >= 1280) watch_rtc_disable_periodic_callback(128); + // but if for whatever reason it isn't, this forces the fast tick off after 20 seconds. + if (movement_state.fast_ticks >= 128 * 20) watch_rtc_disable_periodic_callback(128); } void cb_tick(void) { |