wakeup_schedule_simple_robust: Check result twice to account for re-tests; change the set time in the_time from the scheduler to ensure time is accurate
This commit is contained in:
+23
-34
@@ -3,14 +3,6 @@
|
||||
#include <pebble.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// types
|
||||
typedef struct TheTime {
|
||||
uint8_t HourWIP;
|
||||
uint8_t MinuteWIP;
|
||||
uint8_t HourSet;
|
||||
uint8_t MinuteSet;
|
||||
} __attribute__((__packed__)) TheTime;
|
||||
|
||||
// layer-age
|
||||
static Window *s_window;
|
||||
static Window *s_drop_window;
|
||||
@@ -56,7 +48,6 @@ static GBitmap *s_check_bmp;
|
||||
// global vars
|
||||
static GColor s_setter_highlight_color;
|
||||
static uint8_t s_highlight_pos = 0;
|
||||
static struct TheTime s_the_time;
|
||||
//// setter
|
||||
//// alarm
|
||||
static uint8_t s_solution_indices[3] = {8, 8, 8};
|
||||
@@ -99,8 +90,8 @@ static bool schedule_alarm(bool is_fallback) {
|
||||
} else {
|
||||
time_t now = time(NULL);
|
||||
struct tm target_tm = *localtime(&now);
|
||||
target_tm.tm_hour = s_the_time.HourWIP;
|
||||
target_tm.tm_min = s_the_time.MinuteWIP;
|
||||
target_tm.tm_hour = the_time.HourWIP;
|
||||
target_tm.tm_min = the_time.MinuteWIP;
|
||||
target_tm.tm_sec = 0;
|
||||
target = mktime(&target_tm);
|
||||
if (target <= now) {
|
||||
@@ -112,8 +103,6 @@ static bool schedule_alarm(bool is_fallback) {
|
||||
if (status < 0) {
|
||||
return false; // TODO show failure window - user must acknowledge this window to close it
|
||||
}
|
||||
s_the_time.HourSet = s_the_time.HourWIP;
|
||||
s_the_time.MinuteSet = s_the_time.MinuteWIP;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -576,8 +565,8 @@ static void setter_seconds_handler(struct tm *tick_time, TimeUnits units_changed
|
||||
|
||||
// build the target time today
|
||||
struct tm target_tm = now_tm;
|
||||
target_tm.tm_hour = s_the_time.HourSet;
|
||||
target_tm.tm_min = s_the_time.MinuteSet;
|
||||
target_tm.tm_hour = the_time.HourSet;
|
||||
target_tm.tm_min = the_time.MinuteSet;
|
||||
target_tm.tm_sec = 0;
|
||||
|
||||
time_t now = mktime(&now_tm);
|
||||
@@ -605,7 +594,7 @@ static void update_countdown_display() {
|
||||
|
||||
static void update_setter_display() {
|
||||
static char s_setter_buffer[PBL_IF_ROUND_ELSE(10, 14)];
|
||||
snprintf(s_setter_buffer, sizeof(s_setter_buffer), PBL_IF_ROUND_ELSE("%02u : %02u", "%02u : %02u"), s_the_time.HourWIP, s_the_time.MinuteWIP);
|
||||
snprintf(s_setter_buffer, sizeof(s_setter_buffer), PBL_IF_ROUND_ELSE("%02u : %02u", "%02u : %02u"), the_time.HourWIP, the_time.MinuteWIP);
|
||||
text_layer_set_text(s_setter_txt_layer, s_setter_buffer);
|
||||
}
|
||||
|
||||
@@ -627,17 +616,17 @@ static void setter_highlight_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
static void setter_up_click_handler(void *recognizer, void *ctx) {
|
||||
switch (s_highlight_pos) {
|
||||
case 0:
|
||||
if (s_the_time.HourWIP == 23) {
|
||||
s_the_time.HourWIP = 0;
|
||||
if (the_time.HourWIP == 23) {
|
||||
the_time.HourWIP = 0;
|
||||
} else {
|
||||
s_the_time.HourWIP++;
|
||||
the_time.HourWIP++;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (s_the_time.MinuteWIP == 59) {
|
||||
s_the_time.MinuteWIP = 0;
|
||||
if (the_time.MinuteWIP == 59) {
|
||||
the_time.MinuteWIP = 0;
|
||||
} else {
|
||||
s_the_time.MinuteWIP++;
|
||||
the_time.MinuteWIP++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -649,17 +638,17 @@ static void setter_up_click_handler(void *recognizer, void *ctx) {
|
||||
static void setter_down_click_handler(void *recognizer, void *ctx) {
|
||||
switch (s_highlight_pos) {
|
||||
case 0:
|
||||
if (s_the_time.HourWIP == 0) {
|
||||
s_the_time.HourWIP = 23;
|
||||
if (the_time.HourWIP == 0) {
|
||||
the_time.HourWIP = 23;
|
||||
} else {
|
||||
s_the_time.HourWIP--;
|
||||
the_time.HourWIP--;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (s_the_time.MinuteWIP == 0) {
|
||||
s_the_time.MinuteWIP = 59;
|
||||
if (the_time.MinuteWIP == 0) {
|
||||
the_time.MinuteWIP = 59;
|
||||
} else {
|
||||
s_the_time.MinuteWIP--;
|
||||
the_time.MinuteWIP--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -676,8 +665,8 @@ static void setter_select_click_handler(void *recognizer, void *ctx) {
|
||||
}
|
||||
|
||||
// persist
|
||||
persist_write_int(STORAGE_KEY_ALARM_HOUR, s_the_time.HourSet);
|
||||
persist_write_int(STORAGE_KEY_ALARM_MINUTE, s_the_time.MinuteSet);
|
||||
persist_write_int(STORAGE_KEY_ALARM_HOUR, the_time.HourSet);
|
||||
persist_write_int(STORAGE_KEY_ALARM_MINUTE, the_time.MinuteSet);
|
||||
|
||||
// update countdown immediately
|
||||
update_countdown_display();
|
||||
@@ -780,10 +769,10 @@ static void setter_window_unload() {
|
||||
static void init() {
|
||||
s_window = window_create();
|
||||
s_font_lecoish_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LECOISH_MONO_BOLD_20));
|
||||
s_the_time.HourWIP = persist_read_int(STORAGE_KEY_ALARM_HOUR);
|
||||
s_the_time.MinuteWIP = persist_read_int(STORAGE_KEY_ALARM_MINUTE);
|
||||
s_the_time.HourSet = s_the_time.HourWIP;
|
||||
s_the_time.MinuteSet = s_the_time.MinuteWIP;
|
||||
the_time.HourWIP = persist_read_int(STORAGE_KEY_ALARM_HOUR);
|
||||
the_time.MinuteWIP = persist_read_int(STORAGE_KEY_ALARM_MINUTE);
|
||||
the_time.HourSet = the_time.HourWIP;
|
||||
the_time.MinuteSet = the_time.MinuteWIP;
|
||||
|
||||
switch (launch_reason()) {
|
||||
case APP_LAUNCH_PHONE: // DEBUG, REMOVE PRIOR TO RELEASE!
|
||||
|
||||
+6
-1
@@ -1,3 +1,4 @@
|
||||
#include "scheduler.h"
|
||||
#include <pebble.h>
|
||||
|
||||
static void glance_reload_callback(AppGlanceReloadSession *session, size_t limit, void *target) {
|
||||
@@ -36,7 +37,11 @@ WakeupId wakeup_schedule_simple_robust(time_t wakeup_time, int8_t retry_diff, bo
|
||||
result = wakeup_schedule(wakeup_time, is_fallback, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (result >= 0) {
|
||||
the_time.HourSet = the_time.HourWIP;
|
||||
the_time.MinuteSet = the_time.MinuteWIP;
|
||||
app_glance_reload(glance_reload_callback, (void *)(uintptr_t)wakeup_time);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
#pragma once
|
||||
#include <pebble.h>
|
||||
|
||||
typedef struct TheTime {
|
||||
uint8_t HourWIP;
|
||||
uint8_t MinuteWIP;
|
||||
uint8_t HourSet;
|
||||
uint8_t MinuteSet;
|
||||
} __attribute__((__packed__)) TheTime;
|
||||
|
||||
struct TheTime the_time;
|
||||
|
||||
WakeupId wakeup_schedule_simple_robust(time_t wakeup_time, int8_t retry_diff, bool is_fallback);
|
||||
|
||||
Reference in New Issue
Block a user