Add zap repeat interval; flash countdown when expired

This commit is contained in:
2026-08-18 23:55:45 -04:00
parent 66b2d5e53e
commit 1cb88560ef
6 changed files with 31 additions and 7 deletions
+1
View File
@@ -34,6 +34,7 @@
"messageKeys": [
"PKJS_READY",
"PKJS_PAVLOK_ENABLE",
"PKJS_PAVLOK_ZAP_INTERVAL",
"PKJS_PAVLOK_ZAP",
"PKJS_AWARENESS_TIME_GAP",
"PKJS_AWARENESS_TIME_LIMIT",
+17 -3
View File
@@ -62,6 +62,8 @@ static uint8_t s_solution_indices[3] = {8, 8, 8};
static uint8_t s_selected_indices[3] = {9, 9, 9};
static uint8_t s_awareness_countdown_int = 0;
static char s_awareness_countdown_buf[4];
static uint8_t s_zap_repeat_countdown = 0;
static bool s_hide_countdown = true;
static uint32_t s_vibe_segments[5];
static VibePattern s_vibe_pattern;
@@ -189,9 +191,10 @@ static void apply_uint8_from_tuple(DictionaryIterator *iter, uint32_t key, void
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
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_AWARENESS_TIME_GAP, &settings.AwarenessTimeGapMinutes);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_AWARENESS_TIME_LIMIT, &settings.AwarenessTimeLimitSeconds);
apply_uint8_from_tuple(iter, MESSAGE_KEY_PKJS_AWARENESS_NUDGE_ENABLE, &settings.AwarenessNudgeEnabled);
@@ -292,10 +295,19 @@ static void awareness_alarm_seconds_handler(struct tm *tick_time, TimeUnits unit
snprintf(s_awareness_countdown_buf, sizeof(s_awareness_countdown_buf), "%03u", s_awareness_countdown_int);
text_layer_set_text(s_countdown_txt_layer, s_awareness_countdown_buf);
if (s_awareness_countdown_int == 0) {
send_zap(); // TODO implement repeat interval
send_zap();
s_zap_repeat_countdown = settings.PavlokIntervalSeconds;
}
} else {
// TODO flash countdown txt layer every second
if (s_zap_repeat_countdown > 0) {
s_zap_repeat_countdown--;
if (s_zap_repeat_countdown == 0) {
send_zap();
s_zap_repeat_countdown = settings.PavlokIntervalSeconds;
}
}
layer_set_hidden(text_layer_get_layer(s_countdown_txt_layer), s_hide_countdown);
s_hide_countdown = !s_hide_countdown;
vibes_enqueue_custom_pattern(s_vibe_pattern);
}
}
@@ -617,6 +629,7 @@ static void alarm_window_load() {
if (s_alarm_reason == WAKE_AWARENESS_ALARM) {
text_layer_set_font(s_countdown_txt_layer, s_font_lecoish_small);
s_awareness_countdown_int = settings.AwarenessTimeLimitSeconds;
s_zap_repeat_countdown = 0;
snprintf(s_awareness_countdown_buf, sizeof(s_awareness_countdown_buf), "%03u", s_awareness_countdown_int);
text_layer_set_text(s_countdown_txt_layer, s_awareness_countdown_buf);
} else {
@@ -993,6 +1006,7 @@ static void init() {
} else {
settings.TutorialEnabled = true;
settings.PavlokEnabled = false;
settings.PavlokIntervalSeconds = 10;
settings.AwarenessTimeGapMinutes = 9;
settings.AwarenessTimeLimitSeconds = 30;
settings.AwarenessNudgeEnabled = true;
+1
View File
@@ -12,6 +12,7 @@
typedef struct AppSettings {
bool TutorialEnabled;
bool PavlokEnabled;
uint8_t PavlokIntervalSeconds;
uint8_t AwarenessTimeGapMinutes;
uint8_t AwarenessTimeLimitSeconds;
uint8_t AwarenessNudgeEnabled;
+10
View File
@@ -34,6 +34,16 @@ module.exports = [
"step": 5,
"label": "Zap Intensity"
},
{
"id": "pavlok_zap_interval",
"type": "slider",
"messageKey": "PKJS_PAVLOK_ZAP_INTERVAL",
"defaultValue": 10,
"min": 1,
"max": 60,
"step": 1,
"label": "Zap Repeat Interval"
},
{
"id": "pavlok_test_button",
"type": "button",
+2 -2
View File
@@ -8,10 +8,12 @@ module.exports = function (minified) {
if (this.get()) {
clayConfig.getItemById('pavlok_api_key').show();
clayConfig.getItemById('pavlok_zap_intensity').show();
clayConfig.getItemById('pavlok_zap_interval').show();
clayConfig.getItemById('pavlok_test_button').show();
} else {
clayConfig.getItemById('pavlok_api_key').hide();
clayConfig.getItemById('pavlok_zap_intensity').hide();
clayConfig.getItemById('pavlok_zap_interval').hide();
clayConfig.getItemById('pavlok_test_button').hide();
}
}
@@ -24,10 +26,8 @@ module.exports = function (minified) {
reason: 'Trigalarm Test'
}
});
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open('POST', 'https://api.pavlok.com/api/v5/stimulus/send');
xhr.setRequestHeader('accept', 'application/json');
xhr.setRequestHeader('content-type', 'application/json');
-2
View File
@@ -23,10 +23,8 @@ function callAPI(apiKey, zap_intensity) {
reason: 'Trigalarm'
}
});
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open('POST', 'https://api.pavlok.com/api/v5/stimulus/send');
xhr.setRequestHeader('accept', 'application/json');
xhr.setRequestHeader('content-type', 'application/json');