Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Made vibrations optional
Browse files Browse the repository at this point in the history
This version makes the vibrations upon inhale and option in the configuration. It also prevents the select button from restarting the main animation, which caused problems in the previous version.
  • Loading branch information
aaronhktan committed Nov 12, 2016
1 parent 0471f61 commit e1b1ba3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 32 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"enableMultiJS": true,
"messageKeys": [
"backgroundColor",
"circleColor"
"circleColor",
"vibrationEnabled"
],
"projectType": "native",
"resources": {
Expand Down
72 changes: 41 additions & 31 deletions src/c/breathe_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static void load_settings() {
settings.backgroundColor = GColorBlack;
settings.circleColor = PBL_IF_COLOR_ELSE(GColorJaegerGreen, GColorWhite);
settings.textColor = GColorWhite;
settings.vibrationEnabled = true;
persist_read_data(SETTINGS_KEY, &settings, sizeof(settings));
}

Expand Down Expand Up @@ -254,13 +255,15 @@ static void main_animation() {
animation_schedule(circle_animation_sequence);
s_times_played++;

// vibrations!
static const uint32_t const segments[] = {0, 5500, 25, 25, 25, 25, 25, 25, 25, 25, 25, 50, 25, 75, 25, 125, 25, 125, 25, 125, 25, 125, 25, 200, 25, 325, 25, 550, 25};
VibePattern vibes = {
.durations = segments,
.num_segments = ARRAY_LENGTH(segments),
};
vibes_enqueue_custom_pattern(vibes);
if (settings.vibrationEnabled) {
// vibrations!
static const uint32_t const segments[] = {0, 5500, 25, 25, 25, 25, 25, 25, 25, 25, 25, 50, 25, 75, 25, 125, 25, 125, 25, 125, 25, 125, 25, 200, 25, 325, 25, 550, 25};
VibePattern vibes = {
.durations = segments,
.num_segments = ARRAY_LENGTH(segments),
};
vibes_enqueue_custom_pattern(vibes);
}
}

// schedules next animation
Expand Down Expand Up @@ -346,31 +349,33 @@ static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
}

static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
s_animating = true;
s_times_played = 0;
s_times_clicked_select += 1;
s_animation_completed = false;
layer_set_hidden(s_inside_text_layer, true);
layer_set_hidden(s_upper_text_layer, true);
layer_set_hidden(s_lower_text_layer, true);
if (s_times_clicked_select > 9) {
snprintf(s_min_today, 19, "BREATHED TODAY: %dd", s_times_clicked_select);
} else {
snprintf(s_min_today, 19, "BREATHED TODAY: %d", s_times_clicked_select);
if (!s_animating) {
s_animating = true;
s_times_played = 0;
s_times_clicked_select += 1;
s_animation_completed = false;
layer_set_hidden(s_inside_text_layer, true);
layer_set_hidden(s_upper_text_layer, true);
layer_set_hidden(s_lower_text_layer, true);
if (s_times_clicked_select > 9) {
snprintf(s_min_today, 19, "BREATHED TODAY: %dd", s_times_clicked_select);
} else {
snprintf(s_min_today, 19, "BREATHED TODAY: %d", s_times_clicked_select);
}

main_animation_start();

s_show_relax_text_timer = app_timer_register(2100, animation_start_callback, NULL);
s_show_inhale_timer = app_timer_register(10600, first_breath_in_callback, NULL);
s_show_exhale_timer = app_timer_register(14100, first_breath_out_callback, NULL);
s_hide_exhale_timer = app_timer_register(18000, first_breath_out_hide_callback, NULL);

animationTimer[0] = app_timer_register(6000, main_animation_callback, NULL);

s_main_animation_ended_timer = app_timer_register(s_min_to_breathe * 56000 + 7000, main_animation_end, NULL);
int s_animation_completed_delay = s_min_to_breathe * 56000 + 11000;
s_animation_completed_timer = app_timer_register(s_animation_completed_delay, animation_end_callback, NULL);
}

main_animation_start();

s_show_relax_text_timer = app_timer_register(2100, animation_start_callback, NULL);
s_show_inhale_timer = app_timer_register(10600, first_breath_in_callback, NULL);
s_show_exhale_timer = app_timer_register(14100, first_breath_out_callback, NULL);
s_hide_exhale_timer = app_timer_register(18000, first_breath_out_hide_callback, NULL);

animationTimer[0] = app_timer_register(6000, main_animation_callback, NULL);

s_main_animation_ended_timer = app_timer_register(s_min_to_breathe * 56000 + 7000, main_animation_end, NULL);
int s_animation_completed_delay = s_min_to_breathe * 56000 + 11000;
s_animation_completed_timer = app_timer_register(s_animation_completed_delay, animation_end_callback, NULL);
}

static void click_config_provider(void *context) {
Expand Down Expand Up @@ -408,6 +413,11 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
settings.circleColor = GColorFromHEX(circle_color_t->value->int32);
}

Tuple *vibration_enabled_t = dict_find(iter, MESSAGE_KEY_vibrationEnabled);
if (vibration_enabled_t) {
settings.vibrationEnabled = vibration_enabled_t->value->int32 == 1;
}

save_settings();
}

Expand Down
1 change: 1 addition & 0 deletions src/c/breathe_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typedef struct ClaySettings {
GColor backgroundColor;
GColor circleColor;
GColor textColor;
bool vibrationEnabled;
} ClaySettings;

void breathe_window_push();
14 changes: 14 additions & 0 deletions src/pkjs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ module.exports = [
}
]
},
{
"type": "section",
"items": [
{"type": "heading",
"defaultValue": "Haptic Feedback"
},
{
"type": "toggle",
"messageKey": "vibrationEnabled",
"defaultValue": true,
"label": "Enable vibrations on inhale",
}
]
},
{
"type": "submit",
"defaultValue": "Save Settings"
Expand Down

0 comments on commit e1b1ba3

Please sign in to comment.