more wip launcher stuff
This commit is contained in:
parent
624ff19580
commit
399caa2582
@ -7,8 +7,19 @@
|
|||||||
LauncherState launcher_state;
|
LauncherState launcher_state;
|
||||||
void * widget_contexts[LAUNCHER_NUM_WIDGETS];
|
void * widget_contexts[LAUNCHER_NUM_WIDGETS];
|
||||||
|
|
||||||
|
void launcher_request_tick_frequency(uint8_t freq) {
|
||||||
|
watch_rtc_disable_all_periodic_callbacks();
|
||||||
|
watch_rtc_register_periodic_callback(cb_tick, freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
void launcher_illuminate_led() {
|
||||||
|
launcher_state.light_ticks = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void app_init() {
|
void app_init() {
|
||||||
memset(&launcher_state, 0, sizeof(launcher_state));
|
memset(&launcher_state, 0, sizeof(launcher_state));
|
||||||
|
launcher_state.launcher_settings.bit.led_green_color = 0xF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_wake_from_deep_sleep() {
|
void app_wake_from_deep_sleep() {
|
||||||
@ -25,10 +36,10 @@ void app_setup() {
|
|||||||
watch_enable_leds();
|
watch_enable_leds();
|
||||||
watch_enable_display();
|
watch_enable_display();
|
||||||
|
|
||||||
watch_register_tick_callback(cb_tick);
|
launcher_request_tick_frequency(1);
|
||||||
|
|
||||||
for(uint8_t i = 0; i < LAUNCHER_NUM_WIDGETS; i++) {
|
for(uint8_t i = 0; i < LAUNCHER_NUM_WIDGETS; i++) {
|
||||||
widgets[i].setup(&launcher_state.launcherSettings, widget_contexts[i]);
|
widgets[i].setup(&launcher_state.launcher_settings, widget_contexts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +61,7 @@ bool app_loop() {
|
|||||||
|
|
||||||
// If the LED is off and should be on, turn it on
|
// If the LED is off and should be on, turn it on
|
||||||
if (launcher_state.light_ticks > 0 && !launcher_state.led_on) {
|
if (launcher_state.light_ticks > 0 && !launcher_state.led_on) {
|
||||||
watch_set_led_green();
|
watch_set_led_color(launcher_state.launcher_settings.bit.led_red_color, launcher_state.launcher_settings.bit.led_green_color);
|
||||||
launcher_state.led_on = true;
|
launcher_state.led_on = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,32 +78,26 @@ bool app_loop() {
|
|||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
event = 0;
|
event = 0;
|
||||||
bool can_sleep = widgets[launcher_state.current_widget].loop(event, &launcher_state.launcherSettings, widget_contexts[launcher_state.current_widget]);
|
widgets[launcher_state.current_widget].loop(event, &launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]);
|
||||||
if (can_sleep) return true;
|
|
||||||
|
|
||||||
event = EVENT_LOOP;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (launcher_state.led_on) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_to_next_widget() {
|
void move_to_next_widget() {
|
||||||
launcher_state.widget_changed = true;
|
launcher_state.widget_changed = true;
|
||||||
widgets[launcher_state.current_widget].enter_background(&launcher_state.launcherSettings, widget_contexts[launcher_state.current_widget]);
|
widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]);
|
||||||
launcher_state.current_widget = (launcher_state.current_widget + 1) % LAUNCHER_NUM_WIDGETS;
|
launcher_state.current_widget = (launcher_state.current_widget + 1) % LAUNCHER_NUM_WIDGETS;
|
||||||
widgets[launcher_state.current_widget].enter_foreground(&launcher_state.launcherSettings, widget_contexts[launcher_state.current_widget]);
|
widgets[launcher_state.current_widget].activate(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_to_first_widget() {
|
void move_to_first_widget() {
|
||||||
launcher_state.widget_changed = true;
|
launcher_state.widget_changed = true;
|
||||||
widgets[launcher_state.current_widget].enter_background(&launcher_state.launcherSettings, widget_contexts[launcher_state.current_widget]);
|
widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]);
|
||||||
launcher_state.current_widget = 0;
|
launcher_state.current_widget = 0;
|
||||||
widgets[0].enter_foreground(&launcher_state.launcherSettings, widget_contexts[0]);
|
widgets[0].activate(&launcher_state.launcher_settings, widget_contexts[0]);
|
||||||
}
|
|
||||||
|
|
||||||
void illuminate_led() {
|
|
||||||
launcher_state.light_ticks = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cb_light_pressed() {
|
void cb_light_pressed() {
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
// TODO: none of this is implemented
|
// TODO: none of this is implemented
|
||||||
typedef union {
|
typedef union {
|
||||||
struct {
|
struct {
|
||||||
uint32_t reserved : 1;
|
uint32_t clock_mode_24h : 1; // determines whether clock should use 12 or 24 hour mode.
|
||||||
uint32_t clock_mode_24h : 1; // determines whether display should use 12 or 24 hour mode.
|
|
||||||
uint32_t signal_should_sound : 1; // if true, a double beep is played at the top of each hour.
|
uint32_t signal_should_sound : 1; // if true, a double beep is played at the top of each hour.
|
||||||
uint32_t alarm_should_sound : 1; // if true, the alarm interrupt plays a song.
|
uint32_t alarm_should_sound : 1; // if true, the alarm interrupt can match a time and play a song.
|
||||||
uint32_t note_index : 7; // the index of the tone to play, or 0x7F for no tone.
|
uint32_t alarm_minute : 6; // the minute of the alarm we want to match
|
||||||
uint32_t snapback_enabled : 1; // if true, snaps back to the main screen after 5 minutes
|
uint32_t alarm_hour : 5; // the second of the alarm we want to match
|
||||||
uint32_t sleep_interval : 3; // 0 to disable sleep, or a number of days to sleep after.
|
uint32_t note_index : 4; // the index of the tone to play on button press, or 0xF for no tone.
|
||||||
uint32_t sleep_blanks_screen : 1; // blank screen or display "SLEEP" when asleep
|
uint32_t screensaver_interval : 3; // 0 to disable screensaver, or a screensaver activation interval.
|
||||||
uint32_t led_red_color : 8; // for general purpose illumination, the red LED value
|
uint32_t led_duration : 3; // how many seconds to shine the LED for, or 0 to disable it.
|
||||||
uint32_t led_green_color : 8; // for general purpose illumination, the green LED value
|
uint32_t led_red_color : 4; // for general purpose illumination, the red LED value (0-15)
|
||||||
|
uint32_t led_green_color : 4; // for general purpose illumination, the green LED value (0-15)
|
||||||
} bit;
|
} bit;
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
} LauncherSettings;
|
} LauncherSettings;
|
||||||
@ -24,7 +24,6 @@ typedef enum LauncherEvent {
|
|||||||
EVENT_NONE = 0, // There is no event to report.
|
EVENT_NONE = 0, // There is no event to report.
|
||||||
EVENT_ACTIVATE, // Your widget is entering the foreground.
|
EVENT_ACTIVATE, // Your widget is entering the foreground.
|
||||||
EVENT_TICK, // Most common event type. Your widget is being called from the tick callback.
|
EVENT_TICK, // Most common event type. Your widget is being called from the tick callback.
|
||||||
EVENT_LOOP, // The app did not sleep, and is going into another invocation of the run loop.
|
|
||||||
EVENT_LIGHT_BUTTON_DOWN, // The light button has been pressed, but not yet released.
|
EVENT_LIGHT_BUTTON_DOWN, // The light button has been pressed, but not yet released.
|
||||||
EVENT_LIGHT_BUTTON_UP, // The light button was pressed and released.
|
EVENT_LIGHT_BUTTON_UP, // The light button was pressed and released.
|
||||||
EVENT_LIGHT_LONG_PRESS, // The light button was held for >2 seconds, and released.
|
EVENT_LIGHT_LONG_PRESS, // The light button was held for >2 seconds, and released.
|
||||||
@ -37,20 +36,22 @@ typedef enum LauncherEvent {
|
|||||||
} LauncherEvent;
|
} LauncherEvent;
|
||||||
|
|
||||||
typedef void (*launcher_widget_setup)(LauncherSettings *settings, void ** context_ptr);
|
typedef void (*launcher_widget_setup)(LauncherSettings *settings, void ** context_ptr);
|
||||||
typedef void (*launcher_widget_enter_foreground)(LauncherSettings *settings, void *context);
|
typedef void (*launcher_widget_activate)(LauncherSettings *settings, void *context);
|
||||||
typedef bool (*launcher_widget_loop)(LauncherEvent event, LauncherSettings *settings, void *context);
|
typedef void (*launcher_widget_loop)(LauncherEvent event, LauncherSettings *settings, void *context);
|
||||||
typedef void (*launcher_widget_enter_background)(LauncherSettings *settings, void *context);
|
typedef void (*launcher_widget_resign)(LauncherSettings *settings, void *context);
|
||||||
|
|
||||||
typedef struct WatchWidget {
|
typedef struct WatchWidget {
|
||||||
|
char widget_name[11];
|
||||||
|
bool snapback_enabled;
|
||||||
launcher_widget_setup setup;
|
launcher_widget_setup setup;
|
||||||
launcher_widget_enter_foreground enter_foreground;
|
launcher_widget_activate activate;
|
||||||
launcher_widget_loop loop;
|
launcher_widget_loop loop;
|
||||||
launcher_widget_enter_background enter_background;
|
launcher_widget_resign resign;
|
||||||
} WatchWidget;
|
} WatchWidget;
|
||||||
|
|
||||||
typedef struct LauncherState {
|
typedef struct LauncherState {
|
||||||
// properties stored in BACKUP register
|
// properties stored in BACKUP register
|
||||||
LauncherSettings launcherSettings;
|
LauncherSettings launcher_settings;
|
||||||
|
|
||||||
// transient properties
|
// transient properties
|
||||||
int16_t current_widget;
|
int16_t current_widget;
|
||||||
|
@ -5,12 +5,12 @@ void fake_widget_setup(LauncherSettings *settings, void ** context_ptr) {
|
|||||||
*context_ptr = NULL;
|
*context_ptr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fake_widget_enter_foreground(LauncherSettings *settings, void *context) {
|
void fake_widget_activate(LauncherSettings *settings, void *context) {
|
||||||
(void) settings;
|
(void) settings;
|
||||||
(void) context;
|
(void) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fake_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) {
|
void fake_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) {
|
||||||
(void) event;
|
(void) event;
|
||||||
(void) settings;
|
(void) settings;
|
||||||
(void) context;
|
(void) context;
|
||||||
@ -18,7 +18,7 @@ bool fake_widget_loop(LauncherEvent event, LauncherSettings *settings, void *con
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fake_widget_enter_background(LauncherSettings *settings, void *context) {
|
void fake_widget_resign(LauncherSettings *settings, void *context) {
|
||||||
(void) settings;
|
(void) settings;
|
||||||
(void) context;
|
(void) context;
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,17 @@
|
|||||||
#include "launcher.h"
|
#include "launcher.h"
|
||||||
|
|
||||||
void fake_widget_setup(LauncherSettings *settings, void ** context_ptr);
|
void fake_widget_setup(LauncherSettings *settings, void ** context_ptr);
|
||||||
void fake_widget_enter_foreground(LauncherSettings *settings, void *context);
|
void fake_widget_activate(LauncherSettings *settings, void *context);
|
||||||
bool fake_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context);
|
void fake_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context);
|
||||||
void fake_widget_enter_background(LauncherSettings *settings, void *context);
|
void fake_widget_resign(LauncherSettings *settings, void *context);
|
||||||
|
|
||||||
#define fake_widget { \
|
#define fake_widget { \
|
||||||
|
"WI dGIt01", \
|
||||||
|
true, \
|
||||||
fake_widget_setup, \
|
fake_widget_setup, \
|
||||||
fake_widget_enter_foreground, \
|
fake_widget_activate, \
|
||||||
fake_widget_loop, \
|
fake_widget_loop, \
|
||||||
fake_widget_enter_background, \
|
fake_widget_resign, \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FAKE_WIDGET_H_
|
#endif // FAKE_WIDGET_H_
|
Loading…
x
Reference in New Issue
Block a user