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