mirror of
https://git.wetfence.xyz/RandyTheSilly/Trigalarm.git
synced 2026-09-05 10:07:26 -04:00
Assume user means to set an alarm for tomorrow, not later today, when returning to the setter from a disarmed alarm
This commit is contained in:
+24
-20
@@ -56,6 +56,7 @@ static GBitmap *s_check_bmp;
|
||||
// global vars
|
||||
static GColor s_setter_highlight_color;
|
||||
static uint8_t s_highlight_pos = 0;
|
||||
static bool s_skip_current_day = false;
|
||||
//// alarm
|
||||
static WakeupReason s_alarm_reason;
|
||||
static uint8_t s_solution_indices[3] = {8, 8, 8};
|
||||
@@ -100,6 +101,7 @@ static void click_handler_disable_tutorial(void *recognizer, void *ctx) {
|
||||
|
||||
static void click_handler_push_setter(void *recognizer, void *ctx) {
|
||||
s_highlight_pos = 0;
|
||||
s_skip_current_day = true; // setting the next alarm should assume the user meant tomorrow
|
||||
s_alarm_reason = WAKE_MAIN_ALARM; // going back to setter means alarm was disarmed or failed to set; do not punish user
|
||||
window_stack_pop_all(true);
|
||||
push_setter_window();
|
||||
@@ -230,21 +232,32 @@ static void send_zap(uint8_t intensity) {
|
||||
|
||||
////////////////////// MISC //////////////////////
|
||||
|
||||
static time_t compute_alarm_time(uint8_t hour, uint8_t minute) {
|
||||
time_t now = time(NULL);
|
||||
struct tm target_tm = *localtime(&now);
|
||||
|
||||
bool already_passed_today =
|
||||
(hour < target_tm.tm_hour) ||
|
||||
(hour == target_tm.tm_hour && minute <= target_tm.tm_min);
|
||||
|
||||
target_tm.tm_hour = hour;
|
||||
target_tm.tm_min = minute;
|
||||
target_tm.tm_sec = 0;
|
||||
|
||||
if (s_skip_current_day || already_passed_today) {
|
||||
target_tm.tm_mday += 1;
|
||||
}
|
||||
|
||||
return mktime(&target_tm);
|
||||
}
|
||||
|
||||
static bool schedule_alarm(WakeupReason schedule_reason) {
|
||||
time_t target;
|
||||
WakeupId status;
|
||||
|
||||
switch (schedule_reason) {
|
||||
case WAKE_MAIN_ALARM: {
|
||||
time_t now = time(NULL);
|
||||
struct tm target_tm = *localtime(&now);
|
||||
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) {
|
||||
target += SECONDS_PER_DAY;
|
||||
}
|
||||
target = compute_alarm_time(the_time.HourWIP, the_time.MinuteWIP);
|
||||
wakeup_cancel_all();
|
||||
status = wakeup_schedule_simple_robust(target, SECONDS_PER_MINUTE, schedule_reason);
|
||||
if (settings.PavlokEnabled) {
|
||||
@@ -807,18 +820,8 @@ static void push_alarm_window() {
|
||||
static void setter_seconds_handler(struct tm *tick_time, TimeUnits units_changed) {
|
||||
struct tm now_tm = *tick_time;
|
||||
|
||||
// build the target time today
|
||||
struct tm target_tm = now_tm;
|
||||
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);
|
||||
time_t target = mktime(&target_tm);
|
||||
|
||||
if (target <= now) {
|
||||
target += SECONDS_PER_DAY;
|
||||
}
|
||||
time_t target = compute_alarm_time(the_time.HourSet, the_time.MinuteSet);
|
||||
|
||||
int32_t diff = (int32_t)(target - now);
|
||||
|
||||
@@ -948,6 +951,7 @@ static void setter_click_config_provider(void *ctx) {
|
||||
|
||||
static void live_wakeup_handler_for_setter(WakeupId id, int32_t reason) {
|
||||
s_highlight_pos = 0;
|
||||
s_skip_current_day = false; // reset
|
||||
window_stack_pop_all(false);
|
||||
push_alarm_window();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user