Add alarm reset button to phone-side settings

This commit is contained in:
RandyTheSilly committed 2026-08-23 22:38:31 -04:00
1 parent 0fe121f9ca
commit 86c250a052
6 files changed
+103 -51

No files matched your search

+59 -49
View File
@@ -182,54 +182,6 @@ static void push_status_window(StatusWindowPurpose purpose) {
window_stack_push(s_status_window, true);
}
////////////////////// PKJS //////////////////////
static void apply_uint8_from_tuple(DictionaryIterator *iter, uint32_t key, void *dest) {
Tuple *t = dict_find(iter, key);
if (!t)
return;
*(uint8_t *)dest = t->value->uint8;
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
if (ready_tuple) {
return;
}
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ENABLE, &settings.PavlokEnabled);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_INTERVAL, &settings.PavlokIntervalSeconds);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_MIN, &settings.PavlokMin);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_STEP, &settings.PavlokStep);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_MAX, &settings.PavlokMax);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_AWARENESS_TIME_GAP, &settings.AwarenessTimeGapMinutes);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_AWARENESS_TIME_LIMIT, &settings.AwarenessTimeLimitSeconds);
if (settings.PavlokStep == 0) {
// match min and max values if disabling step mode, as the max is used for force exit/overwrite punishments
settings.PavlokMax = settings.PavlokMin;
} else if (settings.PavlokMax <= settings.PavlokMin) {
// disable step mode if max is not higher than min
settings.PavlokStep = 0;
}
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
}
static void send_zap(uint8_t intensity) {
if (!settings.PavlokEnabled) {
return;
}
DictionaryIterator *out;
AppMessageResult result = app_message_outbox_begin(&out);
if (result != APP_MSG_OK) {
return;
}
dict_write_uint8(out, MESSAGE_KEY_PKJS_PAVLOK_ZAP, intensity);
result = app_message_outbox_send();
if (result != APP_MSG_OK) {
return;
}
}
////////////////////// MISC //////////////////////
static time_t compute_alarm_time(uint8_t hour, uint8_t minute) {
@@ -317,6 +269,64 @@ static void add_bar_layers_to_window(Layer *window_layer, bool small_top) {
layer_add_child(window_layer, s_bottom_bar_layer);
}
////////////////////// PKJS //////////////////////
static void apply_uint8_from_tuple(DictionaryIterator *iter, uint32_t key, void *dest) {
Tuple *t = dict_find(iter, key);
if (!t)
return;
*(uint8_t *)dest = t->value->uint8;
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
if (ready_tuple) {
return;
}
// handle alarm reset requests
if (dict_find(iter, MESSAGE_KEY_PKJS_ALARM_RESET)) {
the_time.HourWIP = 0;
the_time.MinuteWIP = 0;
s_alarm_reason = WAKE_MAIN_ALARM;
schedule_alarm(WAKE_MAIN_ALARM);
return;
}
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ENABLE, &settings.PavlokEnabled);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_INTERVAL, &settings.PavlokIntervalSeconds);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_MIN, &settings.PavlokMin);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_STEP, &settings.PavlokStep);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_PAVLOK_ZAP_MAX, &settings.PavlokMax);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_AWARENESS_TIME_GAP, &settings.AwarenessTimeGapMinutes);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_AWARENESS_TIME_LIMIT, &settings.AwarenessTimeLimitSeconds);
if (settings.PavlokStep == 0) {
// match min and max values if disabling step mode, as the max is used for force exit/overwrite punishments
settings.PavlokMax = settings.PavlokMin;
} else if (settings.PavlokMax <= settings.PavlokMin) {
// disable step mode if max is not higher than min
settings.PavlokStep = 0;
}
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
}
static void send_zap(uint8_t intensity) {
if (!settings.PavlokEnabled) {
return;
}
DictionaryIterator *out;
AppMessageResult result = app_message_outbox_begin(&out);
if (result != APP_MSG_OK) {
return;
}
dict_write_uint8(out, MESSAGE_KEY_PKJS_PAVLOK_ZAP, intensity);
result = app_message_outbox_send();
if (result != APP_MSG_OK) {
return;
}
}
////////////////////// ALARM //////////////////////
static void main_alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed) {
@@ -1047,7 +1057,7 @@ static void init() {
// initialize pkjs
app_message_register_inbox_received(inbox_received_handler);
app_message_open(64, 64); // TODO tighten sizes
app_message_open(128, 128); // TODO tighten sizes
// load settings from persist (or set defaults if not present)
if (persist_exists(STORAGE_KEY_SETTINGS)) {