[Pavlok] Zap force-quitters
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@
|
||||
"messageKeys": [
|
||||
"PKJS_READY",
|
||||
"PKJS_PAVLOK_ENABLE",
|
||||
"PKJS_PAVLOK_ENGAGE"
|
||||
"PKJS_PAVLOK_ZAP"
|
||||
],
|
||||
"resources": {
|
||||
"media": [
|
||||
|
||||
+35
-28
@@ -53,7 +53,7 @@ static GBitmap *s_check_bmp;
|
||||
static GColor s_setter_highlight_color;
|
||||
static uint8_t s_highlight_pos = 0;
|
||||
//// alarm
|
||||
static bool s_alarming_for_awareness;
|
||||
static WakeupReason s_alarm_reason;
|
||||
static uint8_t s_solution_indices[3] = {8, 8, 8};
|
||||
static uint8_t s_selected_indices[3] = {9, 9, 9};
|
||||
static uint8_t s_stopwatch_time[2] = {0, 0};
|
||||
@@ -185,13 +185,17 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||
}
|
||||
}
|
||||
|
||||
static void send_stimulus() {
|
||||
static void send_zap() {
|
||||
if (persist_read_bool(STORAGE_KEY_PAVLOK_ENABLED) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
DictionaryIterator *out;
|
||||
AppMessageResult result = app_message_outbox_begin(&out);
|
||||
if (result != APP_MSG_OK) {
|
||||
return;
|
||||
}
|
||||
dict_write_uint8(out, MESSAGE_KEY_PKJS_PAVLOK_ENGAGE, 1);
|
||||
dict_write_uint8(out, MESSAGE_KEY_PKJS_PAVLOK_ZAP, 1);
|
||||
result = app_message_outbox_send();
|
||||
if (result != APP_MSG_OK) {
|
||||
return;
|
||||
@@ -205,23 +209,23 @@ static bool schedule_alarm(WakeupReason schedule_reason) {
|
||||
WakeupId status;
|
||||
|
||||
switch (schedule_reason) {
|
||||
case RECOVERY_ALARM:
|
||||
case WAKE_RECOVERY_ALARM:
|
||||
target = time(NULL) + 15;
|
||||
// no need to cancel alarms, as RECOVERY_ALARM is short-lived and is expired by the time another is being scheduled
|
||||
status = wakeup_schedule_simple_robust(target, 15, schedule_reason);
|
||||
if (s_alarming_for_awareness) {
|
||||
persist_write_bool(STORAGE_KEY_ALARMING_FOR_AWARENESS, false);
|
||||
if (s_alarm_reason != WAKE_RECOVERY_ALARM) {
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_RECOVERY_ALARM);
|
||||
}
|
||||
break;
|
||||
case AWARENESS_ALARM:
|
||||
case WAKE_AWARENESS_ALARM:
|
||||
target = time(NULL) + 9 * SECONDS_PER_MINUTE;
|
||||
wakeup_cancel_all();
|
||||
status = wakeup_schedule_simple_robust(target, SECONDS_PER_MINUTE, schedule_reason);
|
||||
if (!s_alarming_for_awareness) {
|
||||
persist_write_bool(STORAGE_KEY_ALARMING_FOR_AWARENESS, true);
|
||||
if (s_alarm_reason != WAKE_AWARENESS_ALARM) {
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_AWARENESS_ALARM);
|
||||
}
|
||||
break;
|
||||
case MAIN_ALARM: {
|
||||
case WAKE_MAIN_ALARM: {
|
||||
time_t now = time(NULL);
|
||||
struct tm target_tm = *localtime(&now);
|
||||
target_tm.tm_hour = the_time.HourWIP;
|
||||
@@ -233,8 +237,8 @@ static bool schedule_alarm(WakeupReason schedule_reason) {
|
||||
}
|
||||
wakeup_cancel_all();
|
||||
status = wakeup_schedule_simple_robust(target, SECONDS_PER_MINUTE, schedule_reason);
|
||||
if (s_alarming_for_awareness) {
|
||||
persist_write_bool(STORAGE_KEY_ALARMING_FOR_AWARENESS, false);
|
||||
if (s_alarm_reason != WAKE_MAIN_ALARM) {
|
||||
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_MAIN_ALARM);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,13 +279,13 @@ static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed)
|
||||
if (s_stopwatch_time[1] == 59) {
|
||||
s_stopwatch_time[1] = 0;
|
||||
s_stopwatch_time[0]++;
|
||||
// zap Pavlok user as punishment for being a total failure
|
||||
if (persist_read_bool(STORAGE_KEY_PAVLOK_ENABLED) == true) {
|
||||
send_stimulus();
|
||||
}
|
||||
send_zap();
|
||||
// fall back to main alarm and resume vibes
|
||||
if (s_alarming_for_awareness) {
|
||||
s_alarming_for_awareness = false;
|
||||
if (s_alarm_reason != WAKE_MAIN_ALARM) {
|
||||
// this may be overwritten when the recovery alarm is set,
|
||||
// but it will still allow vibes to occur since the alarm reason
|
||||
// will not be awareness
|
||||
s_alarm_reason = WAKE_MAIN_ALARM;
|
||||
}
|
||||
} else {
|
||||
s_stopwatch_time[1]++;
|
||||
@@ -289,7 +293,7 @@ static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed)
|
||||
static char s_stopwatch_buffer[9];
|
||||
snprintf(s_stopwatch_buffer, sizeof(s_stopwatch_buffer), "%02u:%02u", s_stopwatch_time[0], s_stopwatch_time[1]);
|
||||
text_layer_set_text(s_counter_txt_layer, s_stopwatch_buffer);
|
||||
if (!s_alarming_for_awareness) {
|
||||
if (s_alarm_reason != WAKE_AWARENESS_ALARM) {
|
||||
vibes_enqueue_custom_pattern(s_vibe_pattern);
|
||||
}
|
||||
}
|
||||
@@ -378,8 +382,8 @@ static void drop_menu_window_unload(Window *window) {
|
||||
}
|
||||
|
||||
static void live_wakeup_handler_for_alarm(WakeupId id, int32_t wakeup_reason) {
|
||||
if (wakeup_reason == RECOVERY_ALARM) { // if recovery alarm, re-schedule it
|
||||
schedule_alarm(RECOVERY_ALARM); // output is not captured, as it is not actionable
|
||||
if (wakeup_reason == WAKE_RECOVERY_ALARM) { // if recovery alarm, re-schedule it
|
||||
schedule_alarm(WAKE_RECOVERY_ALARM); // output is not captured, as it is not actionable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,7 +624,7 @@ static void alarm_window_load() {
|
||||
.num_segments = ARRAY_LENGTH(s_vibe_segments),
|
||||
};
|
||||
|
||||
schedule_alarm(RECOVERY_ALARM); // output is not captured, as it is not actionable
|
||||
schedule_alarm(WAKE_RECOVERY_ALARM); // output is not captured, as it is not actionable
|
||||
tick_timer_service_subscribe(SECOND_UNIT, alarm_seconds_handler);
|
||||
}
|
||||
|
||||
@@ -698,15 +702,15 @@ static void alarm_select_hold_handler(void *recognizer, void *ctx) {
|
||||
// no-longer-important recovery alarm
|
||||
wakeup_service_subscribe(NULL);
|
||||
|
||||
if (s_alarming_for_awareness) {
|
||||
if (s_alarm_reason == WAKE_AWARENESS_ALARM) {
|
||||
// set main alarm if the awareness alarm was solved
|
||||
tick_timer_service_unsubscribe(); // alarm is fully disarmed - stop vibes+countdown for confirmation window
|
||||
if (schedule_alarm(MAIN_ALARM)) {
|
||||
if (schedule_alarm(WAKE_MAIN_ALARM)) {
|
||||
push_status_window(STATUS_CONFIRMATION);
|
||||
}
|
||||
} else {
|
||||
// otherwise, set awareness alarm and exit
|
||||
if (schedule_alarm(AWARENESS_ALARM)) {
|
||||
if (schedule_alarm(WAKE_AWARENESS_ALARM)) {
|
||||
if (persist_read_bool(STORAGE_KEY_DISABLE_TUTORIAL)) {
|
||||
window_stack_pop_all(true);
|
||||
} else {
|
||||
@@ -834,7 +838,7 @@ static void setter_down_click_handler(void *recognizer, void *ctx) {
|
||||
|
||||
static void setter_select_click_handler(void *recognizer, void *ctx) {
|
||||
if (s_highlight_pos == 2) {
|
||||
bool success = schedule_alarm(MAIN_ALARM);
|
||||
bool success = schedule_alarm(WAKE_MAIN_ALARM);
|
||||
if (!success) {
|
||||
return; // early return to avoid indicating alarm was set when it was not
|
||||
}
|
||||
@@ -873,7 +877,7 @@ static void setter_click_config_provider(void *ctx) {
|
||||
}
|
||||
|
||||
static void live_wakeup_handler_for_setter(WakeupId id, int32_t reason) {
|
||||
s_alarming_for_awareness = persist_read_bool(STORAGE_KEY_ALARMING_FOR_AWARENESS);
|
||||
s_alarm_reason = persist_read_int(STORAGE_KEY_ALARM_REASON);
|
||||
s_highlight_pos = 0;
|
||||
window_stack_pop_all(false);
|
||||
push_alarm_window();
|
||||
@@ -966,7 +970,10 @@ static void init() {
|
||||
switch (launch_reason()) {
|
||||
// case APP_LAUNCH_PHONE: // DEBUG, REMOVE PRIOR TO RELEASE!
|
||||
case APP_LAUNCH_WAKEUP:
|
||||
s_alarming_for_awareness = persist_read_bool(STORAGE_KEY_ALARMING_FOR_AWARENESS);
|
||||
s_alarm_reason = persist_read_int(STORAGE_KEY_ALARM_REASON);
|
||||
if (s_alarm_reason == WAKE_RECOVERY_ALARM) {
|
||||
send_zap();
|
||||
}
|
||||
push_alarm_window();
|
||||
break;
|
||||
default:
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
#define STORAGE_KEY_ALARM_HOUR 0
|
||||
#define STORAGE_KEY_ALARM_MINUTE 1
|
||||
#define STORAGE_KEY_ALARMING_FOR_AWARENESS 2
|
||||
#define STORAGE_KEY_ALARM_REASON 2
|
||||
#define STORAGE_KEY_DISABLE_TUTORIAL 3
|
||||
#define STORAGE_KEY_PAVLOK_ENABLED 4
|
||||
|
||||
|
||||
+3
-3
@@ -3,9 +3,9 @@
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MAIN_ALARM = 0,
|
||||
AWARENESS_ALARM = 1,
|
||||
RECOVERY_ALARM = 2
|
||||
WAKE_MAIN_ALARM = 0,
|
||||
WAKE_AWARENESS_ALARM = 1,
|
||||
WAKE_RECOVERY_ALARM = 2
|
||||
} WakeupReason;
|
||||
|
||||
typedef struct TheTime {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ Pebble.addEventListener("ready", function () {
|
||||
});
|
||||
|
||||
Pebble.addEventListener("appmessage", function (dict) {
|
||||
if (dict.payload["PKJS_PAVLOK_ENGAGE"]) {
|
||||
if (dict.payload["PKJS_PAVLOK_ZAP"]) {
|
||||
const cfg = JSON.parse(localStorage.getItem('clay-settings'));
|
||||
callAPI(cfg.PKJS_PAVLOK_API_KEY, cfg.PKJS_PAVLOK_ZAP_INTENSITY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user