diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-10-04 09:51:49 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-10-04 09:52:07 -0400 |
commit | c1ec7734c910d1eef74ebc3647dc084eeb43bbcf (patch) | |
tree | f0d791675d1e3300e5e9f790781900aa3c7a93fd | |
parent | 51e2f0d77d95a6e5c3b1426fbc7874c3a59a5e00 (diff) | |
download | Sensor-Watch-c1ec7734c910d1eef74ebc3647dc084eeb43bbcf.tar.gz Sensor-Watch-c1ec7734c910d1eef74ebc3647dc084eeb43bbcf.tar.bz2 Sensor-Watch-c1ec7734c910d1eef74ebc3647dc084eeb43bbcf.zip |
launcher: let widgets prevent sleep
-rw-r--r-- | launcher/launcher.c | 26 | ||||
-rw-r--r-- | launcher/launcher.h | 3 | ||||
-rw-r--r-- | launcher/widgets/clock/simple_clock_widget.c | 6 | ||||
-rw-r--r-- | launcher/widgets/clock/simple_clock_widget.h | 2 | ||||
-rw-r--r-- | launcher/widgets/fake_widget_1.c | 6 | ||||
-rw-r--r-- | launcher/widgets/fake_widget_1.h | 2 | ||||
-rw-r--r-- | launcher/widgets/fake_widget_2.c | 6 | ||||
-rw-r--r-- | launcher/widgets/fake_widget_2.h | 2 | ||||
-rw-r--r-- | launcher/widgets/settings/preferences_widget.c | 24 | ||||
-rw-r--r-- | launcher/widgets/settings/preferences_widget.h | 2 |
10 files changed, 43 insertions, 36 deletions
diff --git a/launcher/launcher.c b/launcher/launcher.c index 4211e1ac..20fd7e59 100644 --- a/launcher/launcher.c +++ b/launcher/launcher.c @@ -35,13 +35,7 @@ void launcher_illuminate_led() { void launcher_move_to_widget(uint8_t widget_index) { launcher_state.widget_changed = true; - widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); - launcher_state.current_widget = widget_index; - watch_clear_display(); - widgets[launcher_state.current_widget].activate(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); - event.value = 0; - event.bit.event_type = EVENT_ACTIVATE; - widgets[launcher_state.current_widget].loop(event, &launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); + launcher_state.next_widget = widget_index; } void launcher_move_to_next_widget() { @@ -94,12 +88,17 @@ void app_wake_from_sleep() { } bool app_loop() { - // play a beep if the widget has changed in response to a user's press of the MODE button if (launcher_state.widget_changed) { - // low note for nonzero case, high note for return to widget 0 if (launcher_state.launcher_settings.bit.button_should_sound) { + // low note for nonzero case, high note for return to widget 0 watch_buzzer_play_note(launcher_state.current_widget ? BUZZER_NOTE_C7 : BUZZER_NOTE_C8, 50); } + widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); + launcher_state.current_widget = launcher_state.next_widget; + watch_clear_display(); + widgets[launcher_state.current_widget].activate(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); + event.value = 0; + event.bit.event_type = EVENT_ACTIVATE; launcher_state.widget_changed = false; } @@ -136,16 +135,15 @@ bool app_loop() { watch_enter_shallow_sleep(true); } + bool can_sleep = true; + if (event.bit.event_type) { event.bit.subsecond = launcher_state.subsecond; - widgets[launcher_state.current_widget].loop(event, &launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); + can_sleep = widgets[launcher_state.current_widget].loop(event, &launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); event.value = 0; } - - if (launcher_state.led_on) return false; - - return true; + return can_sleep && !launcher_state.led_on; } LauncherEventType _figure_out_button_event(LauncherEventType button_down_event, uint8_t *down_timestamp) { diff --git a/launcher/launcher.h b/launcher/launcher.h index d6ebbc2c..97c56545 100644 --- a/launcher/launcher.h +++ b/launcher/launcher.h @@ -49,7 +49,7 @@ typedef union { typedef void (*launcher_widget_setup)(LauncherSettings *settings, void ** context_ptr); typedef void (*launcher_widget_activate)(LauncherSettings *settings, void *context); -typedef void (*launcher_widget_loop)(LauncherEvent event, LauncherSettings *settings, void *context); +typedef bool (*launcher_widget_loop)(LauncherEvent event, LauncherSettings *settings, void *context); typedef void (*launcher_widget_resign)(LauncherSettings *settings, void *context); typedef struct WatchWidget { @@ -65,6 +65,7 @@ typedef struct LauncherState { // transient properties int16_t current_widget; + int16_t next_widget; bool widget_changed; // LED stuff diff --git a/launcher/widgets/clock/simple_clock_widget.c b/launcher/widgets/clock/simple_clock_widget.c index 427793f3..83b5a713 100644 --- a/launcher/widgets/clock/simple_clock_widget.c +++ b/launcher/widgets/clock/simple_clock_widget.c @@ -17,7 +17,7 @@ void simple_clock_widget_activate(LauncherSettings *settings, void *context) { *((uint32_t *)context) = 0xFFFFFFFF; } -void simple_clock_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) { +bool simple_clock_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) { printf("simple_clock_widget_loop\n"); const char weekdays[7][3] = {"SA", "SU", "MO", "TU", "WE", "TH", "FR"}; char buf[11]; @@ -64,7 +64,7 @@ void simple_clock_widget_loop(LauncherEvent event, LauncherSettings *settings, v break; case EVENT_MODE_BUTTON_UP: launcher_move_to_next_widget(); - return; + return false; case EVENT_LIGHT_BUTTON_UP: launcher_illuminate_led(); break; @@ -73,6 +73,8 @@ void simple_clock_widget_loop(LauncherEvent event, LauncherSettings *settings, v default: break; } + + return true; } void simple_clock_widget_resign(LauncherSettings *settings, void *context) { diff --git a/launcher/widgets/clock/simple_clock_widget.h b/launcher/widgets/clock/simple_clock_widget.h index 42b0d3c5..739c942b 100644 --- a/launcher/widgets/clock/simple_clock_widget.h +++ b/launcher/widgets/clock/simple_clock_widget.h @@ -5,7 +5,7 @@ void simple_clock_widget_setup(LauncherSettings *settings, void ** context_ptr); void simple_clock_widget_activate(LauncherSettings *settings, void *context); -void simple_clock_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context); +bool simple_clock_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context); void simple_clock_widget_resign(LauncherSettings *settings, void *context); uint8_t simple_clock_widget_get_weekday(uint16_t day, uint16_t month, uint16_t year); diff --git a/launcher/widgets/fake_widget_1.c b/launcher/widgets/fake_widget_1.c index 65324095..bdc964e2 100644 --- a/launcher/widgets/fake_widget_1.c +++ b/launcher/widgets/fake_widget_1.c @@ -11,7 +11,7 @@ void fake_widget_1_activate(LauncherSettings *settings, void *context) { (void) context; } -void fake_widget_1_loop(LauncherEvent event, LauncherSettings *settings, void *context) { +bool fake_widget_1_loop(LauncherEvent event, LauncherSettings *settings, void *context) { printf("fake_widget_1_loop\n"); (void) settings; (void) context; @@ -20,13 +20,15 @@ void fake_widget_1_loop(LauncherEvent event, LauncherSettings *settings, void *c switch (event.bit.event_type) { case EVENT_MODE_BUTTON_UP: launcher_move_to_next_widget(); - return; + return false; case EVENT_LIGHT_BUTTON_UP: launcher_illuminate_led(); break; default: break; } + + return true; } void fake_widget_1_resign(LauncherSettings *settings, void *context) { diff --git a/launcher/widgets/fake_widget_1.h b/launcher/widgets/fake_widget_1.h index 24704f23..d033b49a 100644 --- a/launcher/widgets/fake_widget_1.h +++ b/launcher/widgets/fake_widget_1.h @@ -5,7 +5,7 @@ void fake_widget_1_setup(LauncherSettings *settings, void ** context_ptr); void fake_widget_1_activate(LauncherSettings *settings, void *context); -void fake_widget_1_loop(LauncherEvent event, LauncherSettings *settings, void *context); +bool fake_widget_1_loop(LauncherEvent event, LauncherSettings *settings, void *context); void fake_widget_1_resign(LauncherSettings *settings, void *context); #define fake_widget_1 { \ diff --git a/launcher/widgets/fake_widget_2.c b/launcher/widgets/fake_widget_2.c index a6eafb7b..46772222 100644 --- a/launcher/widgets/fake_widget_2.c +++ b/launcher/widgets/fake_widget_2.c @@ -11,7 +11,7 @@ void fake_widget_2_activate(LauncherSettings *settings, void *context) { (void) context; } -void fake_widget_2_loop(LauncherEvent event, LauncherSettings *settings, void *context) { +bool fake_widget_2_loop(LauncherEvent event, LauncherSettings *settings, void *context) { printf("fake_widget_2_loop\n"); (void) settings; (void) context; @@ -20,13 +20,15 @@ void fake_widget_2_loop(LauncherEvent event, LauncherSettings *settings, void *c switch (event.bit.event_type) { case EVENT_MODE_BUTTON_UP: launcher_move_to_next_widget(); - return; + return false; case EVENT_LIGHT_BUTTON_UP: launcher_illuminate_led(); break; default: break; } + + return true; } void fake_widget_2_resign(LauncherSettings *settings, void *context) { diff --git a/launcher/widgets/fake_widget_2.h b/launcher/widgets/fake_widget_2.h index 945e28fa..cf01969d 100644 --- a/launcher/widgets/fake_widget_2.h +++ b/launcher/widgets/fake_widget_2.h @@ -5,7 +5,7 @@ void fake_widget_2_setup(LauncherSettings *settings, void ** context_ptr); void fake_widget_2_activate(LauncherSettings *settings, void *context); -void fake_widget_2_loop(LauncherEvent event, LauncherSettings *settings, void *context); +bool fake_widget_2_loop(LauncherEvent event, LauncherSettings *settings, void *context); void fake_widget_2_resign(LauncherSettings *settings, void *context); #define fake_widget_2 { \ diff --git a/launcher/widgets/settings/preferences_widget.c b/launcher/widgets/settings/preferences_widget.c index d4abeb8e..878b775b 100644 --- a/launcher/widgets/settings/preferences_widget.c +++ b/launcher/widgets/settings/preferences_widget.c @@ -16,15 +16,16 @@ void preferences_widget_activate(LauncherSettings *settings, void *context) { launcher_request_tick_frequency(4); // we need to manually blink some pixels } -void preferences_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) { +bool preferences_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) { (void) settings; (void) context; printf("preferences_widget_loop\n"); uint8_t current_page = *((uint8_t *)context); switch (event.bit.event_type) { case EVENT_MODE_BUTTON_UP: + watch_set_led_off(); launcher_move_to_next_widget(); - return; + return false; case EVENT_LIGHT_BUTTON_UP: current_page = (current_page + 1) % PREFERENCES_WIDGET_NUM_PREFEFENCES; *((uint8_t *)context) = current_page; @@ -54,16 +55,8 @@ void preferences_widget_loop(LauncherEvent event, LauncherSettings *settings, vo watch_clear_display(); watch_display_string((char *)preferences_widget_titles[current_page], 0); - if (current_page > 2) { - // this is a hack, launcher should be able to illumate with a custom color. - launcher_illuminate_led(); - watch_set_led_color(settings->bit.led_red_color ? (0xF | settings->bit.led_red_color << 4) : 0, - settings->bit.led_green_color ? (0xF | settings->bit.led_green_color << 4) : 0); - } else { - watch_set_led_off(); - } - if (event.bit.subsecond % 2) return; + if (event.bit.subsecond % 2) return current_page <= 2; char buf[3]; switch (current_page) { case 0: @@ -111,6 +104,15 @@ void preferences_widget_loop(LauncherEvent event, LauncherSettings *settings, vo watch_display_string(buf, 8); break; } + + if (current_page > 2) { + watch_set_led_color(settings->bit.led_red_color ? (0xF | settings->bit.led_red_color << 4) : 0, + settings->bit.led_green_color ? (0xF | settings->bit.led_green_color << 4) : 0); + return false; + } + + watch_set_led_off(); + return true; } void preferences_widget_resign(LauncherSettings *settings, void *context) { diff --git a/launcher/widgets/settings/preferences_widget.h b/launcher/widgets/settings/preferences_widget.h index e2e27fc7..11a189f8 100644 --- a/launcher/widgets/settings/preferences_widget.h +++ b/launcher/widgets/settings/preferences_widget.h @@ -5,7 +5,7 @@ void preferences_widget_setup(LauncherSettings *settings, void ** context_ptr); void preferences_widget_activate(LauncherSettings *settings, void *context); -void preferences_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context); +bool preferences_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context); void preferences_widget_resign(LauncherSettings *settings, void *context); #define preferences_widget { \ |