From 53ade61b136a302bb087bfb80901e03b656a5271 Mon Sep 17 00:00:00 2001 From: rkcf Date: Sat, 4 Feb 2023 22:41:22 -0600 Subject: [PATCH] Feat: add bpm label to gui --- main/esp32-sequencer.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/main/esp32-sequencer.c b/main/esp32-sequencer.c index 7e4ec11..0458423 100644 --- a/main/esp32-sequencer.c +++ b/main/esp32-sequencer.c @@ -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) {