From ec9559072506211caf16d7ec0626dca10a9fb3e8 Mon Sep 17 00:00:00 2001 From: Christian Reinbacher Date: Wed, 4 May 2016 15:50:25 +0200 Subject: [PATCH 1/2] added vibration and possibility to manually set bpm --- src/detector.c | 6 ++++++ src/detector.h | 1 + src/main.c | 4 ++-- src/tap_window.c | 23 ++++++++++++++++++----- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/detector.c b/src/detector.c index 19f6eca..0b9930e 100644 --- a/src/detector.c +++ b/src/detector.c @@ -39,3 +39,9 @@ uint detector_get_bpm() { uint detector_get_beat_duration(uint bpm) { return 60000 / bpm; } + +void detector_set_bpm(uint bpm){ + for(uint i = 0; i < SAMPLE_SIZE; i++) { + last_bpm[i] = bpm; + } +} \ No newline at end of file diff --git a/src/detector.h b/src/detector.h index bdcf841..10585a1 100644 --- a/src/detector.h +++ b/src/detector.h @@ -4,6 +4,7 @@ void detector_beat_happend(); uint detector_get_bpm(); +void detector_set_bpm(uint bpm); uint detector_get_beat_duration(uint bpm); char detector_get_beat_in_bar(); \ No newline at end of file diff --git a/src/main.c b/src/main.c index db0dfb7..d979193 100644 --- a/src/main.c +++ b/src/main.c @@ -7,9 +7,9 @@ static void click_config_provider(void *context) { ButtonId id = BUTTON_ID_SELECT; window_single_click_subscribe(id, tap_window_select_handler); id = BUTTON_ID_UP; - window_single_click_subscribe(id, tap_window_up_handler); + window_single_repeating_click_subscribe(id, 100, tap_window_up_handler); id = BUTTON_ID_DOWN; - window_single_click_subscribe(id, tap_window_down_handler); + window_single_repeating_click_subscribe(id, 100, tap_window_down_handler); } diff --git a/src/tap_window.c b/src/tap_window.c index 13ebe4d..2033d24 100644 --- a/src/tap_window.c +++ b/src/tap_window.c @@ -55,17 +55,22 @@ static void toggle_screen() { } static void auto_beat_handler(void *data) { - toggle_screen(); uint bpm = detector_get_bpm(); s_auto_beat_timer = app_timer_register(detector_get_beat_duration(bpm), auto_beat_handler, NULL); + toggle_screen(); + vibes_short_pulse(); + } -static void beat_happend() { - detector_beat_happend(); - uint bpm = detector_get_bpm(); +static void update_bpm_text(unsigned int bpm) { static char s_buffer[16]; snprintf(s_buffer, 16, "%u", bpm); text_layer_set_text(s_time_layer, s_buffer); +} +static void beat_happend() { + detector_beat_happend(); + uint bpm = detector_get_bpm(); + update_bpm_text(bpm); if(bpm != 0) { if(s_auto_beat_timer == NULL) { @@ -82,10 +87,18 @@ void tap_window_select_handler(ClickRecognizerRef recognizer, void *context) { } void tap_window_up_handler(ClickRecognizerRef recognizer, void *context) { - progress_circle_reset_beats(); + //progress_circle_reset_beats(); + uint bpm = detector_get_bpm(); + detector_set_bpm(bpm+1); + update_bpm_text(bpm+1); } void tap_window_down_handler(ClickRecognizerRef recognizer, void *context) { + uint bpm = detector_get_bpm(); + if(bpm>1) { + detector_set_bpm(bpm-1); + update_bpm_text(bpm-1); + } } From 3685208fbea10e41e283fbe12feb55ff35a62d3f Mon Sep 17 00:00:00 2001 From: Christian Reinbacher Date: Wed, 4 May 2016 15:53:32 +0200 Subject: [PATCH 2/2] added shorter vibes --- src/tap_window.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tap_window.c b/src/tap_window.c index 2033d24..347597f 100644 --- a/src/tap_window.c +++ b/src/tap_window.c @@ -10,6 +10,12 @@ static Layer *s_arc_layer; static AppTimer *s_auto_beat_timer = NULL; +static const uint32_t const segments[] = { 50 }; +VibePattern pat = { + .durations = segments, + .num_segments = ARRAY_LENGTH(segments), +}; + void tap_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); @@ -58,7 +64,7 @@ static void auto_beat_handler(void *data) { uint bpm = detector_get_bpm(); s_auto_beat_timer = app_timer_register(detector_get_beat_duration(bpm), auto_beat_handler, NULL); toggle_screen(); - vibes_short_pulse(); + vibes_enqueue_custom_pattern(pat); }