diff --git a/package.json b/package.json index e8c5001..791c806 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/c/main.c b/src/c/main.c index 1e8a1a7..e65bf24 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -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; diff --git a/src/c/settings.h b/src/c/settings.h index 2bec52c..1706a46 100644 --- a/src/c/settings.h +++ b/src/c/settings.h @@ -12,6 +12,7 @@ typedef struct AppSettings { bool TutorialEnabled; bool PavlokEnabled; + uint8_t PavlokIntervalSeconds; uint8_t AwarenessTimeGapMinutes; uint8_t AwarenessTimeLimitSeconds; uint8_t AwarenessNudgeEnabled; diff --git a/src/pkjs/config.js b/src/pkjs/config.js index 2f8e7af..796d1d8 100644 --- a/src/pkjs/config.js +++ b/src/pkjs/config.js @@ -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", diff --git a/src/pkjs/customClay.js b/src/pkjs/customClay.js index 9f384a1..3d5d0a0 100644 --- a/src/pkjs/customClay.js +++ b/src/pkjs/customClay.js @@ -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'); diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 91b571f..e03f260 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -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');