screensaver mode is now low energy mode

This commit is contained in:
Joey Castillo 2021-10-16 13:40:17 -04:00
parent 8f5de18b94
commit 3e539a9e63
4 changed files with 29 additions and 29 deletions

View file

@ -7,7 +7,7 @@
movement_state_t movement_state;
void * watch_face_contexts[MOVEMENT_NUM_FACES];
const int32_t movement_screensaver_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
const int32_t movement_inactivity_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
movement_event_t event;
void cb_mode_btn_interrupt();
@ -17,9 +17,9 @@ void cb_alarm_btn_extwake();
void cb_alarm_fired();
void cb_tick();
static inline void _movement_reset_screensaver_countdown() {
static inline void _movement_reset_inactivity_countdown() {
// for testing, make the timeout happen 60x faster.
movement_state.screensaver_ticks = movement_screensaver_deadlines[movement_state.settings.bit.screensaver_interval] / 60;
movement_state.le_mode_ticks = movement_inactivity_deadlines[movement_state.settings.bit.le_inactivity_interval] / 60;
}
void movement_request_tick_frequency(uint8_t freq) {
@ -47,8 +47,8 @@ void app_init() {
movement_state.settings.bit.led_green_color = 0xF;
movement_state.settings.bit.button_should_sound = true;
movement_state.settings.bit.screensaver_interval = 1;
_movement_reset_screensaver_countdown();
movement_state.settings.bit.le_inactivity_interval = 1;
_movement_reset_inactivity_countdown();
}
void app_wake_from_deep_sleep() {
@ -64,7 +64,7 @@ void app_setup() {
is_first_launch = false;
}
}
if (movement_state.screensaver_ticks != -1) {
if (movement_state.le_mode_ticks != -1) {
watch_disable_extwake_interrupt(BTN_ALARM);
watch_rtc_disable_alarm_callback();
@ -129,9 +129,9 @@ bool app_loop() {
}
}
// if we have timed out of our screensaver countdown, enter screensaver mode.
if (movement_state.screensaver_ticks == 0) {
movement_state.screensaver_ticks = -1;
// if we have timed out of our low energy mode countdown, enter low energy mode.
if (movement_state.le_mode_ticks == 0) {
movement_state.le_mode_ticks = -1;
watch_date_time alarm_time;
alarm_time.reg = 0;
alarm_time.unit.second = 59; // after a match, the alarm fires at the next rising edge of CLK_RTC_CNT, so 59 seconds lets us update at :00
@ -141,13 +141,13 @@ bool app_loop() {
event.subsecond = 0;
// this is a little mini-runloop.
// as long as screensaver_ticks is -1 (i.e. screensaver is active), we wake up here, update the screen, and go right back to sleep.
while (movement_state.screensaver_ticks == -1) {
event.event_type = EVENT_SCREENSAVER;
// as long as le_mode_ticks is -1 (i.e. we are in low energy mode), we wake up here, update the screen, and go right back to sleep.
while (movement_state.le_mode_ticks == -1) {
event.event_type = EVENT_LOW_POWER_TICK;
watch_faces[movement_state.current_watch_face].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_watch_face]);
watch_enter_shallow_sleep(true);
}
// as soon as screensaver_ticks is reset by the extwake handler, we bail out of the loop and reactivate ourselves.
// as soon as le_mode_ticks is reset by the extwake handler, we bail out of the loop and reactivate ourselves.
event.event_type = EVENT_ACTIVATE;
// this is a hack tho: waking from shallow sleep, app_setup does get called, but it happens before we have reset our ticks.
// need to figure out if there's a better heuristic for determining how we woke up.
@ -180,27 +180,27 @@ movement_event_type_t _figure_out_button_event(movement_event_type_t button_down
}
void cb_light_btn_interrupt() {
_movement_reset_screensaver_countdown();
_movement_reset_inactivity_countdown();
event.event_type = _figure_out_button_event(EVENT_LIGHT_BUTTON_DOWN, &movement_state.light_down_timestamp);
}
void cb_mode_btn_interrupt() {
_movement_reset_screensaver_countdown();
_movement_reset_inactivity_countdown();
event.event_type = _figure_out_button_event(EVENT_MODE_BUTTON_DOWN, &movement_state.mode_down_timestamp);
}
void cb_alarm_btn_interrupt() {
_movement_reset_screensaver_countdown();
_movement_reset_inactivity_countdown();
event.event_type = _figure_out_button_event(EVENT_ALARM_BUTTON_DOWN, &movement_state.alarm_down_timestamp);
}
void cb_alarm_btn_extwake() {
// wake up!
_movement_reset_screensaver_countdown();
_movement_reset_inactivity_countdown();
}
void cb_alarm_fired() {
event.event_type = EVENT_SCREENSAVER;
event.event_type = EVENT_LOW_POWER_TICK;
}
void cb_tick() {
@ -208,7 +208,7 @@ void cb_tick() {
watch_date_time date_time = watch_rtc_get_date_time();
if (date_time.unit.second != movement_state.last_second) {
if (movement_state.light_ticks) movement_state.light_ticks--;
if (movement_state.settings.bit.screensaver_interval && movement_state.screensaver_ticks > 0) movement_state.screensaver_ticks--;
if (movement_state.settings.bit.le_inactivity_interval && movement_state.le_mode_ticks > 0) movement_state.le_mode_ticks--;
movement_state.last_second = date_time.unit.second;
movement_state.subsecond = 0;

View file

@ -13,7 +13,7 @@ typedef union {
uint32_t alarm_should_sound : 1; // if true, the alarm interrupt can match a time and play a song.
uint32_t alarm_minute : 6; // the minute of the alarm we want to match
uint32_t alarm_hour : 5; // the second of the alarm we want to match
uint32_t screensaver_interval : 3; // 0 to disable screensaver, or a screensaver activation interval.
uint32_t le_inactivity_interval : 3;// 0 to disable low energy mode, or an inactivity interval for going into low energy mode.
uint32_t led_duration : 3; // how many seconds to shine the LED for, or 0 to disable it.
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)
@ -25,7 +25,7 @@ typedef enum {
EVENT_NONE = 0, // There is no event to report.
EVENT_ACTIVATE, // Your watch face is entering the foreground.
EVENT_TICK, // Most common event type. Your watch face is being called from the tick callback.
EVENT_SCREENSAVER, // Your watch face is being asked to display its output for screensaver mode.
EVENT_LOW_POWER_TICK, // The watch is in low energy mode, and you are getting the once-per-minute tick callback.
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_LONG_PRESS, // The light button was held for >2 seconds, and released.
@ -72,8 +72,8 @@ typedef struct {
uint8_t mode_down_timestamp;
uint8_t alarm_down_timestamp;
// screensaver countdown
int32_t screensaver_ticks;
// low energy mode countdown
int32_t le_mode_ticks;
// stuff for subsecond tracking
uint8_t tick_frequency;

View file

@ -28,16 +28,16 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
switch (event.event_type) {
case EVENT_ACTIVATE:
case EVENT_TICK:
case EVENT_SCREENSAVER:
case EVENT_LOW_POWER_TICK:
date_time = watch_rtc_get_date_time();
previous_date_time = *((uint32_t *)context);
*((uint32_t *)context) = date_time.reg;
if (date_time.reg >> 6 == previous_date_time >> 6 && event.event_type != EVENT_SCREENSAVER) {
if (date_time.reg >> 6 == previous_date_time >> 6 && event.event_type != EVENT_LOW_POWER_TICK) {
// everything before seconds is the same, don't waste cycles setting those segments.
pos = 8;
sprintf(buf, "%02d", date_time.unit.second);
} else if (date_time.reg >> 12 == previous_date_time >> 12 && event.event_type != EVENT_SCREENSAVER) {
} else if (date_time.reg >> 12 == previous_date_time >> 12 && event.event_type != EVENT_LOW_POWER_TICK) {
// everything before minutes is the same.
pos = 6;
sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second);
@ -54,7 +54,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
}
pos = 0;
if (event.event_type == EVENT_SCREENSAVER) {
if (event.event_type == EVENT_LOW_POWER_TICK) {
sprintf(buf, "%s%2d%2d%02d ", weekdays[simple_clock_face_get_weekday(date_time.unit.year, date_time.unit.month, date_time.unit.day)], date_time.unit.day, date_time.unit.hour, date_time.unit.minute);
} else {
sprintf(buf, "%s%2d%2d%02d%02d", weekdays[simple_clock_face_get_weekday(date_time.unit.year, date_time.unit.month, date_time.unit.day)], date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);

View file

@ -37,7 +37,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
settings->bit.button_should_sound = !(settings->bit.button_should_sound);
break;
case 2:
settings->bit.screensaver_interval = settings->bit.screensaver_interval + 1;
settings->bit.le_inactivity_interval = settings->bit.le_inactivity_interval + 1;
break;
case 3:
settings->bit.led_green_color = settings->bit.led_green_color + 1;
@ -65,7 +65,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
else watch_display_string("n", 9);
break;
case 2:
switch (settings->bit.screensaver_interval) {
switch (settings->bit.le_inactivity_interval) {
case 0:
watch_display_string(" never", 4);
break;