Feat: Add display of sequence steps to GUI
parent
1b9afed3d0
commit
6145ad8ace
|
|
@ -91,6 +91,7 @@ static uint16_t current_bpm = DEFAULT_BPM;
|
|||
#define SEQ_MAX_LEN 8
|
||||
static uint8_t sequence[SEQ_MAX_LEN] = {0};
|
||||
static uint8_t seq_len = SEQ_MAX_LEN;
|
||||
lv_obj_t * sequence_label = NULL;
|
||||
|
||||
static const char *TAG = "sequencer";
|
||||
|
||||
|
|
@ -103,10 +104,24 @@ uint32_t ms_to_bpm(uint32_t ms) {
|
|||
return 60000 / ms;
|
||||
}
|
||||
|
||||
// updates the sequence for the GUI display
|
||||
static void update_seq(uint8_t *sequence) {
|
||||
char seq_str[seq_len];
|
||||
for (uint8_t i = 0; i < seq_len; i++) {
|
||||
if (sequence[i] == 1) {
|
||||
seq_str[i] = 'x';
|
||||
} else {
|
||||
seq_str[i] = 'o';
|
||||
}
|
||||
}
|
||||
lv_label_set_text(sequence_label, seq_str);
|
||||
}
|
||||
|
||||
static void randomize_seq(uint8_t *sequence) {
|
||||
for (uint8_t i = 0; i < SEQ_MAX_LEN; i++) {
|
||||
sequence[i] = esp_random() % 2;
|
||||
}
|
||||
update_seq(sequence);
|
||||
}
|
||||
|
||||
static void mutate_seq(uint8_t *sequence) {
|
||||
|
|
@ -118,6 +133,7 @@ static void mutate_seq(uint8_t *sequence) {
|
|||
} else if (sequence[step] == 0) {
|
||||
sequence[step] = 1;
|
||||
}
|
||||
update_seq(sequence);
|
||||
}
|
||||
|
||||
/* Handle tap tempo button presses */
|
||||
|
|
@ -393,9 +409,9 @@ static void display_init(void) {
|
|||
|
||||
static void gui_create(void) {
|
||||
// Setup flex layout
|
||||
lv_obj_t * seq_row = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(seq_row, 300, 70);
|
||||
lv_obj_set_flex_flow(seq_row, LV_FLEX_FLOW_ROW);
|
||||
/* lv_obj_t * seq_row = lv_obj_create(lv_scr_act()); */
|
||||
/* lv_obj_set_size(seq_row, 300, 70); */
|
||||
/* lv_obj_set_flex_flow(seq_row, LV_FLEX_FLOW_ROW); */
|
||||
|
||||
// Initialize style
|
||||
static lv_style_t gui_style;
|
||||
|
|
@ -416,9 +432,15 @@ static void gui_create(void) {
|
|||
lv_obj_t * title_label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(title_label, "ESP32 Sequencer\n");
|
||||
lv_obj_add_style(title_label, &gui_style, LV_STATE_DEFAULT);
|
||||
lv_obj_align(title_label, LV_ALIGN_TOP_MID, 0, 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(title_label, LV_ALIGN_BOTTOM_RIGHT, 0, 0); */
|
||||
lv_obj_align(sequence_label, LV_ALIGN_TOP_LEFT, 0, 30);
|
||||
}
|
||||
|
||||
static void gui_task(void *pvParameter) {
|
||||
|
|
|
|||
Reference in New Issue