Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down
29 changes: 24 additions & 5 deletions src/tap_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -55,17 +61,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_enqueue_custom_pattern(pat);

}

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) {
Expand All @@ -82,10 +93,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);
}

}

Expand Down