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

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