Fixed and optimized simple UI handling.

pull/4/head
Holger Wirtz 6 years ago
parent d4fe310fff
commit f43164b7d6
  1. 5
      MicroDexed.ino
  2. 68
      UI.cpp
  3. 2
      UI.h
  4. 1
      config.h
  5. 2
      dexed_sysex.cpp

@ -47,7 +47,7 @@ int32_t enc_val[2] = {INITIAL_ENC_L_VALUE, INITIAL_ENC_R_VALUE};
Bounce but[2] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)};
elapsedMillis master_timer;
uint8_t ui_state = UI_MAIN;
uint8_t ui_main_state = UI_MAIN_VOICE_SELECTED;
uint8_t ui_main_state = UI_MAIN_VOICE;
#endif
// GUItool: begin automatically generated code
@ -250,9 +250,10 @@ void setup()
#endif
#ifdef I2C_DISPLAY
lcd.clear();
ui_show_main();
#endif
Serial.println(F("<setup end>"));
#ifdef TEST_NOTE

@ -38,6 +38,7 @@ void handle_ui(void)
{
if (ui_back_to_main >= UI_AUTO_BACK_MS && ui_state != UI_MAIN)
{
lcd.clear();
ui_show_main();
EEPROM.update(EEPROM_OFFSET + EEPROM_MASTER_VOLUME_ADDR, uint8_t(vol * UCHAR_MAX));
EEPROM.update(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR, uint8_t(vol_right * UCHAR_MAX));
@ -58,15 +59,12 @@ void handle_ui(void)
switch (ui_main_state)
{
case UI_MAIN_BANK:
case UI_MAIN_BANK_SELECTED:
ui_main_state = UI_MAIN_VOICE;
enc[1].write(voice);
enc_val[1] = enc[1].read();
break;
case UI_MAIN_VOICE:
ui_main_state = UI_MAIN_VOICE_SELECTED;
enc[1].write(voice);
enc_val[1] = enc[1].read();
break;
case UI_MAIN_VOICE_SELECTED:
ui_main_state = UI_MAIN_BANK;
enc[1].write(bank);
@ -75,11 +73,14 @@ void handle_ui(void)
}
break;
case 1: // right button pressed
ui_main_state = UI_MAIN_VOICE_SELECTED;
load_sysex(bank, voice);
EEPROM.update(EEPROM_OFFSET + EEPROM_BANK_ADDR, bank);
EEPROM.update(EEPROM_OFFSET + EEPROM_VOICE_ADDR, voice);
update_eeprom_checksum();
if (ui_main_state == UI_MAIN_VOICE_SELECTED)
{
ui_main_state = UI_MAIN_VOICE;
load_sysex(bank, voice);
EEPROM.update(EEPROM_OFFSET + EEPROM_BANK_ADDR, bank);
EEPROM.update(EEPROM_OFFSET + EEPROM_VOICE_ADDR, voice);
update_eeprom_checksum();
}
break;
}
ui_show_main();
@ -107,35 +108,25 @@ void handle_ui(void)
switch (ui_main_state)
{
case UI_MAIN_BANK:
ui_main_state = UI_MAIN_BANK_SELECTED;
case UI_MAIN_BANK_SELECTED:
if (enc[i].read() <= 0)
enc[i].write(0);
else if (enc[i].read() > max_loaded_banks-1)
enc[i].write(max_loaded_banks-1);
else if (enc[i].read() > max_loaded_banks - 1)
enc[i].write(max_loaded_banks - 1);
bank = enc[i].read();
if (!get_voice_names_from_bank(bank))
{
bank--;
enc[i].write(bank);
get_voice_names_from_bank(bank);
}
get_voice_names_from_bank(bank);
break;
case UI_MAIN_VOICE:
if (enc[i].read() <= 0)
enc[i].write(0);
else if (enc[i].read() > MAX_VOICES-1)
enc[i].write(MAX_VOICES-1);
voice = enc[i].read();
break;
ui_main_state = UI_MAIN_VOICE_SELECTED;
case UI_MAIN_VOICE_SELECTED:
ui_main_state = UI_MAIN_VOICE;
if (enc[i].read() <= 0)
enc[i].write(0);
else if (enc[i].read() >= MAX_VOICES-1)
enc[i].write(MAX_VOICES);
else if (enc[i].read() > MAX_VOICES - 1)
enc[i].write(MAX_VOICES - 1);
voice = enc[i].read();
break;
}
get_voice_names_from_bank(bank);
ui_show_main();
break;
}
@ -154,7 +145,6 @@ void ui_show_main(void)
{
ui_state = UI_MAIN;
lcd.clear();
lcd.show(0, 0, 2, bank + 1);
lcd.show(0, 2, 1, " ");
strip_extension(bank_names[bank], bank_name);
@ -165,25 +155,39 @@ void ui_show_main(void)
lcd.show(0, 3, 10, bank_name);
lcd.show(0, 14, 1, "]");
}
else if (ui_main_state == UI_MAIN_BANK_SELECTED)
{
lcd.show(0, 2, 1, "<");
lcd.show(0, 3, 10, bank_name);
lcd.show(0, 14, 1, ">");
}
else
{
lcd.show(0, 2, 1, " ");
lcd.show(0, 3, 10, bank_name);
lcd.show(0, 14, 1, " ");
}
lcd.show(1, 0, 2, voice + 1);
lcd.show(1, 2, 1, " ");
if (ui_main_state == UI_MAIN_VOICE)
{
lcd.show(1, 2, 1, "<");
lcd.show(1, 2, 1, "[");
lcd.show(1, 3, 10, voice_names[voice]);
lcd.show(1, 14, 1, ">");
lcd.show(1, 14, 1, "]");
}
else if (ui_main_state == UI_MAIN_VOICE_SELECTED)
{
lcd.show(1, 2, 1, "[");
lcd.show(1, 2, 1, "<");
lcd.show(1, 3, 10, voice_names[voice]);
lcd.show(1, 14, 1, "]");
lcd.show(1, 14, 1, ">");
}
else
{
lcd.show(1, 2, 1, " ");
lcd.show(1, 3, 10, voice_names[voice]);
lcd.show(1, 14, 1, " ");
}
}
void ui_show_volume(void)

@ -54,7 +54,7 @@ void ui_show_main(void);
void ui_show_volume(void);
enum ui_states {UI_MAIN, UI_VOLUME};
enum ui_main_states {UI_MAIN_BANK, UI_MAIN_VOICE, UI_MAIN_VOICE_SELECTED};
enum ui_main_states {UI_MAIN_BANK, UI_MAIN_VOICE, UI_MAIN_BANK_SELECTED, UI_MAIN_VOICE_SELECTED};
class MyEncoder : public Encoder
{

@ -33,6 +33,7 @@
#define CONFIG_H_INCLUDED
// Initial values
#define VERSION 1.0
#define MIDI_DEVICE Serial1
#define USE_ONBOARD_USB_HOST 1
#define TEENSY_AUDIO_BOARD 1

@ -253,7 +253,7 @@ bool load_sysex(uint8_t b, uint8_t v)
Serial.print(sysex_file_name);
Serial.print(F(" ["));
Serial.print(voice_names[v]);
Serial.println(F(" ["));
Serial.println(F("]"));
#endif
return (dexed->loadSysexVoice(data));
}

Loading…
Cancel
Save