Feat: add bpm label to gui

main
rkcf 2023-02-04 22:41:22 -06:00
parent 6145ad8ace
commit 53ade61b13
1 changed files with 13 additions and 3 deletions

View File

@ -87,6 +87,7 @@ portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
static const uint32_t DEFAULT_BPM = 120;
static uint16_t current_bpm = DEFAULT_BPM;
lv_obj_t * bpm_label = NULL;
#define SEQ_MAX_LEN 8
static uint8_t sequence[SEQ_MAX_LEN] = {0};
@ -104,6 +105,10 @@ uint32_t ms_to_bpm(uint32_t ms) {
return 60000 / ms;
}
static void update_bpm(void) {
lv_label_set_text_fmt(bpm_label, "BPM: %d", current_bpm);
}
// updates the sequence for the GUI display
static void update_seq(uint8_t *sequence) {
char seq_str[seq_len];
@ -148,6 +153,7 @@ static void tap_tempo_handler(){
ESP_ERROR_CHECK(gptimer_stop(tap_tempo_timer));
ESP_ERROR_CHECK(gptimer_set_raw_count(tap_tempo_timer, 0));
current_bpm = ms_to_bpm(count / 1000);
update_bpm();
ESP_LOGI(TAG, "Stopping tap tempo monitoring at %" PRIu64 "ms", count / 1000);
}
}
@ -434,13 +440,17 @@ static void gui_create(void) {
lv_obj_add_style(title_label, &gui_style, LV_STATE_DEFAULT);
lv_obj_align(title_label, LV_ALIGN_TOP_MID, 0, 5);
// Create and set BPM lable text
bpm_label = lv_label_create(lv_scr_act());
lv_label_set_text_fmt(bpm_label, "BPM: %d", current_bpm);
lv_obj_add_style(bpm_label, &gui_style, LV_STATE_DEFAULT);
lv_obj_align(bpm_label, LV_ALIGN_BOTTOM_LEFT, 5, -5);
// Create sequence text area
sequence_label = lv_label_create(lv_scr_act());
lv_label_set_text(sequence_label, "oooooooo");
lv_obj_add_style(sequence_label, &gui_style, LV_STATE_DEFAULT);
// Align label to center top
lv_obj_align(sequence_label, LV_ALIGN_TOP_LEFT, 0, 30);
lv_obj_align(sequence_label, LV_ALIGN_CENTER, 0, 0);
}
static void gui_task(void *pvParameter) {