launcher: let widgets prevent sleep

This commit is contained in:
Joey Castillo 2021-10-04 09:51:49 -04:00
parent 51e2f0d77d
commit c1ec7734c9
10 changed files with 43 additions and 36 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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) {

View file

@ -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);

View file

@ -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) {

View file

@ -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 { \

View file

@ -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) {

View file

@ -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 { \

View file

@ -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) {

View file

@ -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 { \