#include #include "ui.h" #include #include "adc.h" #include "button.h" #include "system.h" #include "unicore-mx/stm32/gpio.h" #include "unicore-mx/stm32/rcc.h" #include "pot.h" #include "dac.h" #include "settings.h" #include "timer.h" static int sel_pos = 1; static int sel_track = 0; static int sel_val = 0; extern volatile uint32_t jiffies; void ui_pattern_refresh_action(struct display_menu_entry *e, uint8_t b) { int i; int off; sel_val = drums_get(sel_track, sel_pos - 1); led_beat(0); off = ((sel_pos - 1)/ 8) * 8; for (i = 0; i < 8; i++) { if (drums_get(sel_track, (off + i))) led_on(i+1); else led_off(i+1); } } void ui_pattern_update_action(struct display_menu_entry *e, uint8_t b) { if (sel_val) { drums_set(sel_track, sel_pos - 1); drums_oneshot(sel_track); } else drums_clear(sel_track, sel_pos - 1); } void ui_pattern_keepalive(void) { static uint32_t blink_time = 0; if (jiffies - blink_time > 20) { led_toggle(((sel_pos - 1) % 8) + 1); blink_time = jiffies; } } void ui_pattern_menu_return_to_main(struct display_menu_entry *e, uint8_t b) { display_clear(NULL); clear_input_callback(); clear_keepalive(); led_beat(0); ui_display_menu(&MainMenu); } struct display_menu PatternMenu = { .entry_n = 4, .entry = { /* TYPE, label, action, min, max, var, arg */ { ENTRY_TYPE_DEC, "Track: ", ui_pattern_refresh_action, 0, (MAX_TRACKS - 1), 1, &sel_track, NULL }, { ENTRY_TYPE_DEC, "Pos : ", ui_pattern_refresh_action, 1, 8, 1, &sel_pos, NULL }, { ENTRY_TYPE_BOOL, "Value : ", ui_pattern_update_action, 0, 0, 0, &sel_val, NULL }, { ENTRY_TYPE_TEXT, "Back to main", ui_pattern_menu_return_to_main, 0, 0, 0, NULL, NULL }, {0, "", NULL, 0,0,0,NULL,NULL} } }; void ui_pattern_input(int press, int hold) { if (press == '*' && (ui_get_menu_selection() == 1)) { sel_val = !sel_val; ui_pattern_update_action(NULL, 0); ui_pattern_refresh_action(NULL, 0); press = 0; return; } ui_button_press(press, hold); if ((press == '+' || press == '-') && (ui_get_menu_selection() == 0)) { drums_oneshot(sel_track); } } const char instr_txt[MAX_TRACKS][14] = { "Kick", "Snare", "HitHat", "Tom1", "Tom2", "Clap", "Cow", "", }; void ui_pattern_menu_action(struct display_menu_entry *e, uint8_t b) { PatternMenu.entry[1].max = Settings.pattern_len; sel_val = drums_get(sel_track, sel_pos - 1); ui_display_menu(e->arg); set_keepalive(ui_pattern_keepalive); set_input_callback(ui_pattern_input); ui_pattern_refresh_action(e, b); }