Initial Pavlok integration

This commit is contained in:
2026-08-18 00:11:00 -04:00
parent 692077f4c4
commit 04bf4b2c45
6 changed files with 168 additions and 4 deletions
+36 -1
View File
@@ -170,6 +170,34 @@ static void push_status_window(StatusWindowPurpose purpose) {
window_stack_push(s_status_window, true);
}
////////////////////// PKJS //////////////////////
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
if (ready_tuple) {
return; // TODO use ready signal better
}
Tuple *clay_tuple = dict_find(iter, MESSAGE_KEY_PKJS_PAVLOK_ENABLE);
if (clay_tuple) {
persist_write_bool(STORAGE_KEY_PAVLOK_ENABLED, clay_tuple->value->uint8);
return;
}
}
static void send_stimulus() {
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);
result = app_message_outbox_send();
if (result != APP_MSG_OK) {
return;
}
}
////////////////////// MISC //////////////////////
static bool schedule_alarm(WakeupReason schedule_reason) {
@@ -247,8 +275,11 @@ 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();
}
// fall back to main alarm and resume vibes
// if the user fails to solve within a minute
if (s_alarming_for_awareness) {
s_alarming_for_awareness = false;
}
@@ -928,6 +959,10 @@ static void init() {
the_time.HourSet = the_time.HourWIP;
the_time.MinuteSet = the_time.MinuteWIP;
// initialize pkjs TODO maybe only do in alarm mode?
app_message_register_inbox_received(inbox_received_handler);
app_message_open(64, 64); // TODO tighten sizes
switch (launch_reason()) {
case APP_LAUNCH_PHONE: // DEBUG, REMOVE PRIOR TO RELEASE!
case APP_LAUNCH_WAKEUP:
+1
View File
@@ -4,6 +4,7 @@
#define STORAGE_KEY_ALARM_MINUTE 1
#define STORAGE_KEY_ALARMING_FOR_AWARENESS 2
#define STORAGE_KEY_DISABLE_TUTORIAL 3
#define STORAGE_KEY_PAVLOK_ENABLED 4
typedef enum
{