Write app glance in wakeup_schedule_simple_robust to ensure time is accurate
This commit is contained in:
1 parent
5911295363
commit
38500b14d8
3 files changed
+17
-17
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#include <pebble.h>
|
||||
|
||||
static void glance_reload_callback(AppGlanceReloadSession *session, size_t limit, void *target) {
|
||||
static char s_glance_buffer[22];
|
||||
time_t alarm_time = (time_t)(uintptr_t)target;
|
||||
struct tm wakeup_tm = *localtime(&alarm_time);
|
||||
snprintf(s_glance_buffer, sizeof(s_glance_buffer), "%02u:%02u:%02u, %02u/%02u", wakeup_tm.tm_hour, wakeup_tm.tm_min, wakeup_tm.tm_sec, wakeup_tm.tm_mon, wakeup_tm.tm_mday);
|
||||
AppGlanceSlice slice = {
|
||||
.expiration_time = (time_t)(uintptr_t)target,
|
||||
.layout.icon = APP_GLANCE_SLICE_DEFAULT_ICON,
|
||||
.layout.subtitle_template_string = s_glance_buffer,
|
||||
};
|
||||
app_glance_add_slice(session, slice);
|
||||
}
|
||||
|
||||
// Mostly stolen from https://github.com/SeaPea/GentleWake;
|
||||
// A slightly more robust wakeup scheduler that retries on certain errors and
|
||||
// can retry for a different wakeup time offset by retry_diff up to retry_max times
|
||||
WakeupId wakeup_schedule_simple_robust(time_t wakeup_time, int8_t retry_diff, bool is_fallback) {
|
||||
WakeupId result = 0;
|
||||
uint8_t try_count = 0;
|
||||
|
||||
result = wakeup_schedule(wakeup_time, is_fallback, true);
|
||||
|
||||
if (result < 0) {
|
||||
// If result is negative, something went wrong, so make sure all wakeups for this app are cancelled and try again
|
||||
wakeup_cancel_all();
|
||||
|
||||
result = wakeup_schedule(wakeup_time, is_fallback, true);
|
||||
|
||||
if (result == E_RANGE) {
|
||||
// E_RANGE means some other app has the same wakeup time +/- 1 minute, so try to set
|
||||
// the wakeup for a time up to (retry_diff * 8) minutes before/after.
|
||||
while (result == E_RANGE && try_count++ < 8) {
|
||||
wakeup_time += retry_diff;
|
||||
result = wakeup_schedule(wakeup_time, is_fallback, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
app_glance_reload(glance_reload_callback, (void *)(uintptr_t)wakeup_time);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user