From cb69a2c181a3126ade2044f223b74077f48e0c77 Mon Sep 17 00:00:00 2001 From: TheOnePerson Date: Wed, 26 Oct 2022 04:57:53 +0200 Subject: Add an Alarm face to movement (#96) * Add movement_play_alarm_beeps() to movement.c and make alarm sounds customizable. Add alarm indicator to simple watch face. * Add alarm face * alarm_face: fix problem with disabling alarms for 00:00. * Fix typos in comments and get rid of of unused variable warning * remove unnecessary constant * simple_clock_face: fix disappearing chime indicator after face switch, enable alarm indicator updates in app loop (for one-time alarms). movement: handle situations where watch is in sleep mode and chimes fire off at the same time as alarms properly. * alarm_face: tweak process of displaying things on the lcd. Add extra long and extra short alarms. Increase number of alarm slots to 16. * alarm face: fix alarms playing one beeping round more than set. * alarm face: add proper quick cycling of hour and minute setting * alarm-face: correct am/pm indication and some minor tweaks. Reset movement_config.h to current main branch. simple-watch-face: Remove unnecessary check and swap indicators (alarm / hourly chime) * alarm-face: reverse commit parts from another branch (accidentially commited logic depending on movement firmware auto firing the long press event) Co-authored-by: joeycastillo --- movement/movement.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'movement/movement.c') 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) { -- cgit v1.2.3