From 9a8b56f71f81dc718cdf7eb2013a76deeed11b62 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 20 Sep 2018 13:46:30 +0200 Subject: [PATCH] Fixed displaying bank and voice on LCD. --- MicroDexed.ino | 38 ++++++++++++++++++++++++++-------- config.h | 1 + dexed.cpp | 1 + dexed.h | 1 + dexed_sysex.cpp | 55 ++++++++++++++++++++++++++++++++++++++----------- dexed_sysex.h | 1 + 6 files changed, 76 insertions(+), 21 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 9885954..6a9414e 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -123,9 +123,8 @@ void setup() { //while (!Serial) ; // wait for Arduino Serial Monitor Serial.begin(SERIAL_SPEED); - delay(220); -#ifndef I2C_DISPLAY +#ifdef I2C_DISPLAY lcd.init(); lcd.blink_off(); lcd.cursor_off(); @@ -133,17 +132,18 @@ void setup() lcd.noAutoscroll(); lcd.clear(); lcd.display(); - lcd.show(0, 0, 20, "MicroDexed"); + lcd.show(0, 0, 16, " MicroDexed"); + lcd.show(1, 0, 16, "(c)parasiTstudio"); enc_l.write(INITIAL_ENC_L_VALUE); enc_r.write(INITIAL_ENC_R_VALUE); #endif + delay(220); Serial.println(F("MicroDexed based on https://github.com/asb2m10/dexed")); Serial.println(F("(c)2018 H. Wirtz ")); Serial.println(F("https://github.com/dcoredump/MicroDexed")); Serial.println(F("")); - initial_values_from_eeprom(); // start up USB host @@ -198,8 +198,6 @@ void setup() AudioMemoryUsageMaxReset(); #endif - - #ifdef DEBUG Serial.print(F("Bank/Voice from EEPROM [")); Serial.print(EEPROM.read(EEPROM_OFFSET + EEPROM_BANK_ADDR), DEC); @@ -228,9 +226,13 @@ void setup() cpu_mem_millis = 0; #endif -#ifndef I2C_DISPLAY - lcd.show(1, 0, 3, data1); - lcd.show(1, 4, 3, data2); +#ifdef I2C_DISPLAY + lcd.show(0, 0, 2, bank); + lcd.show(0, 2, 1, " "); + lcd.show(0, 3, 10, bank_name); + lcd.show(1, 0, 2, voice); + lcd.show(1, 2, 1, " "); + lcd.show(1, 3, 10, voice_name); #endif #ifdef TEST_NOTE @@ -379,6 +381,11 @@ bool handle_master_key(uint8_t data) #endif EEPROM.update(EEPROM_OFFSET + EEPROM_VOICE_ADDR, num); update_eeprom_checksum(); +#ifdef I2C_DISPLAY + lcd.show(1, 0, 2, voice); + lcd.show(1, 2, 1, " "); + lcd.show(1, 3, 10, voice_name); +#endif } #ifdef DEBUG else @@ -406,6 +413,19 @@ bool handle_master_key(uint8_t data) #ifdef DEBUG Serial.print(F("Bank switch to: ")); Serial.println(bank, DEC); +#endif +#ifdef I2C_DISPLAY +if(get_bank_name(bank)) +{ + lcd.show(0, 0, 2, bank); + lcd.show(0, 2, 1, " "); + lcd.show(0, 3, 10, bank_name); +} +else +{ + lcd.show(0, 0, 2, bank); + lcd.show(0, 2, 10, " *ERROR*"); +} #endif return (true); } diff --git a/config.h b/config.h index 89e9953..f99104c 100644 --- a/config.h +++ b/config.h @@ -40,6 +40,7 @@ //#define DEXED_ENGINE DEXED_ENGINE_MODERN #define AUDIO_MEM 2 #define SAMPLE_RATE 44100 +#define MAX_BANKS 99 #if !defined(__MK66FX1M0__) // check for Teensy-3.6 #define MAX_NOTES 11 // No? diff --git a/dexed.cpp b/dexed.cpp index 83ac62d..15905ec 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -683,6 +683,7 @@ bool Dexed::loadSysexVoice(uint8_t* new_data) char voicename[11]; memset(voicename, 0, sizeof(voicename)); strncpy(voicename, (char *)&data[145], sizeof(voicename) - 1); + strncpy(voice_name, (char *)&data[145], sizeof(voicename) - 1); Serial.print(F("Voice [")); Serial.print(voicename); Serial.println(F("] loaded.")); diff --git a/dexed.h b/dexed.h index 3f6a94f..218b179 100644 --- a/dexed.h +++ b/dexed.h @@ -44,6 +44,7 @@ extern float vol; extern float vol_right; extern float vol_left; extern void set_volume(float master_volume, float volume_right, float volume_left); +extern char voice_name[10]; struct ProcessorVoice { uint8_t midi_note; diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index f93c31c..d3be7f3 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -31,13 +31,52 @@ #include "dexed_sysex.h" #include "config.h" +bool get_bank_name(uint8_t b) +{ + File root; + b %= MAX_BANKS; + + if (sd_card_available) + { + char bankdir[3]; + + bankdir[0] = '/'; + bankdir[2] = '\0'; + itoa(b, &bankdir[1], 10); + + root = SD.open(bankdir); + if (!root) + { +#ifdef DEBUG + Serial.println(F("E: Cannot open main dir from SD.")); +#endif + return (false); + } + while (42 == 42) + { + File entry = root.openNextFile(); + if (!entry) + { + // No more files + break; + } + else + { + if (!entry.isDirectory()) + strncpy(bank_name, entry.name(), strlen(bank_name) - 1); + } + } + } + return (false); +} + bool load_sysex(uint8_t b, uint8_t v) { File root; bool found = false; v %= 32; - b %= 10; + b %= MAX_BANKS; if (sd_card_available) { @@ -81,9 +120,10 @@ bool load_sysex(uint8_t b, uint8_t v) Serial.print(F(" [")); Serial.print(n); Serial.println(F("]")); - strcpy(bank_name, bankdir); - strcpy(voice_name, entry.name()); + #endif + strncpy(bank_name, entry.name(), strlen(bank_name) - 1); + return (dexed->loadSysexVoice(data)); } else @@ -96,15 +136,6 @@ bool load_sysex(uint8_t b, uint8_t v) } } } -#ifdef I2C_DISPLAY - char tmp[3]; - itoa(bank, tmp, 10); - lcd.show(0, 0, 2, tmp); - lcd.show(0, 3, 10, bank_name); - itoa(voice, tmp, 10); - lcd.show(1, 0, 2, tmp); - lcd.show(1, 3, 10, voice_name); -#endif #ifdef DEBUG if (found == false) diff --git a/dexed_sysex.h b/dexed_sysex.h index 8cf43a6..598bdf6 100644 --- a/dexed_sysex.h +++ b/dexed_sysex.h @@ -37,5 +37,6 @@ extern char bank_name[10]; extern char voice_name[10]; extern LiquidCrystalPlus_I2C lcd; +bool get_bank_name(uint8_t b); bool load_sysex(uint8_t b, uint8_t v); bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data);