Send continuous pavlok zaps on the first triangle once any timer has expired
This commit is contained in:
1 parent
f6a10475ca
commit
601b1641d8
1 file changed
+22
-10
+22
-10
@@ -70,7 +70,9 @@ static uint8_t s_solution_indices[3];
|
||||
static uint8_t s_selected_indices[3] = {9, 9, 9};
|
||||
static uint8_t s_secs_since_last_input;
|
||||
static uint8_t s_shake_cooldown;
|
||||
static uint8_t s_zap_cooldown;
|
||||
static uint8_t s_countdown_int = 0;
|
||||
static bool s_continuous_zap_on_first_triangle;
|
||||
static char s_countdown_buf[4];
|
||||
static char s_progress_buf[9];
|
||||
|
||||
@@ -83,6 +85,7 @@ static const GColor s_primary_color = GColorJaegerGreen;
|
||||
//// alarm
|
||||
#define MAX_SECS_WITHOUT_INPUT 10
|
||||
#define SHAKE_COOLDOWN_SECS 2
|
||||
#define ZAP_COOLDOWN_SECS 4
|
||||
static const uint8_t s_drop_height = 22;
|
||||
static const GRect s_drop_function_grect = GRect(PBL_IF_ROUND_ELSE(55, 45), s_bottom_bar_grect.origin.y + ((s_bottom_bar_grect.size.h / 2) - PBL_IF_ROUND_ELSE(s_drop_height - 1, s_drop_height / 2)), 50, s_drop_height);
|
||||
static const GRect s_drop_over_grect = GRect(s_drop_function_grect.origin.x + 78, s_drop_function_grect.origin.y - 13, s_drop_function_grect.size.w + 1, s_drop_function_grect.size.h);
|
||||
@@ -281,8 +284,8 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
|
||||
}
|
||||
|
||||
static void send_zap(uint8_t intensity) {
|
||||
if (!settings.PavlokEnabled) {
|
||||
static void send_zap() {
|
||||
if (!settings.PavlokEnabled || s_zap_cooldown != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -291,11 +294,13 @@ static void send_zap(uint8_t intensity) {
|
||||
if (result != APP_MSG_OK) {
|
||||
return;
|
||||
}
|
||||
dict_write_uint8(out, MESSAGE_KEY_PKJS_PAVLOK_ZAP, intensity);
|
||||
dict_write_uint8(out, MESSAGE_KEY_PKJS_PAVLOK_ZAP, settings.PavlokIntensity);
|
||||
result = app_message_outbox_send();
|
||||
if (result != APP_MSG_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_zap_cooldown = ZAP_COOLDOWN_SECS;
|
||||
}
|
||||
|
||||
////////////////////// ALARM //////////////////////
|
||||
@@ -450,25 +455,30 @@ static void increment_secs_since_last_input() {
|
||||
}
|
||||
}
|
||||
|
||||
static void decrement_shake_cooldown() {
|
||||
if (s_shake_cooldown != 0) {
|
||||
s_shake_cooldown--;
|
||||
static void decrement_cooldown(uint8_t *cooldown) {
|
||||
if (*cooldown != 0) {
|
||||
(*cooldown)--;
|
||||
}
|
||||
}
|
||||
|
||||
static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed) {
|
||||
s_countdown_int--;
|
||||
decrement_shake_cooldown();
|
||||
decrement_cooldown(&s_shake_cooldown);
|
||||
if (s_current_triangle_num == 1) {
|
||||
decrement_cooldown(&s_zap_cooldown);
|
||||
increment_secs_since_last_input();
|
||||
if (s_secs_since_last_input >= MAX_SECS_WITHOUT_INPUT) { // pause vibrations during user input; this fixes shake detection and saves battery
|
||||
if (s_secs_since_last_input >= MAX_SECS_WITHOUT_INPUT) { // pause stimulus during user input; this fixes shake detection and saves battery
|
||||
vibes_enqueue_custom_pattern(s_first_triangle_vibe_pattern);
|
||||
if (s_continuous_zap_on_first_triangle) {
|
||||
send_zap();
|
||||
}
|
||||
}
|
||||
}
|
||||
snprintf(s_countdown_buf, sizeof(s_countdown_buf), "%03u", s_countdown_int);
|
||||
text_layer_set_text(s_countdown_txt_layer, s_countdown_buf);
|
||||
if (s_countdown_int == 0) {
|
||||
send_zap(settings.PavlokIntensity);
|
||||
s_continuous_zap_on_first_triangle = true; // begin zapping once the first countdown expires
|
||||
send_zap();
|
||||
if (s_current_triangle_num > 1) {
|
||||
s_current_triangle_num--;
|
||||
}
|
||||
@@ -784,6 +794,8 @@ static void alarm_window_load() {
|
||||
// configure UI around current triangle in s_triangle_layer
|
||||
s_current_triangle_num = 1;
|
||||
s_secs_since_last_input = MAX_SECS_WITHOUT_INPUT;
|
||||
s_continuous_zap_on_first_triangle = false;
|
||||
s_zap_cooldown = 0;
|
||||
update_for_new_triangle();
|
||||
|
||||
// schedule recovery alarm and begin countdown :)
|
||||
@@ -824,7 +836,7 @@ static void alarm_window_unload() {
|
||||
|
||||
static void push_alarm_window() {
|
||||
if (s_alarm_reason == WAKE_RECOVERY_ALARM) {
|
||||
send_zap(settings.PavlokIntensity);
|
||||
send_zap();
|
||||
}
|
||||
|
||||
window_set_window_handlers(
|
||||
|
||||
Reference in new issue
Block a user