Fixes for autostoring configuration data to EEPROM.

pull/4/head
Holger Wirtz 6 years ago
parent 1866ed69a1
commit 0560f84b12
  1. 31
      MicroDexed.ino
  2. 3
      config.h

@ -105,8 +105,6 @@ char voice_name[VOICE_NAME_LEN];
char bank_names[MAX_BANKS][BANK_NAME_LEN]; char bank_names[MAX_BANKS][BANK_NAME_LEN];
char voice_names[MAX_VOICES][VOICE_NAME_LEN]; char voice_names[MAX_VOICES][VOICE_NAME_LEN];
elapsedMillis autostore; elapsedMillis autostore;
uint8_t eeprom_update_status = 0;
uint16_t autostore_value = AUTOSTORE_MS;
uint8_t midi_timing_counter = 0; // 24 per qarter uint8_t midi_timing_counter = 0; // 24 per qarter
elapsedMillis midi_timing_timestep; elapsedMillis midi_timing_timestep;
uint16_t midi_timing_quarter = 0; uint16_t midi_timing_quarter = 0;
@ -125,6 +123,7 @@ uint8_t active_voices = 0;
elapsedMillis cpu_mem_millis; elapsedMillis cpu_mem_millis;
#endif #endif
config_t configuration = {0xffff, 0, 0, VOLUME, 0.5f, DEFAULT_MIDI_CHANNEL}; config_t configuration = {0xffff, 0, 0, VOLUME, 0.5f, DEFAULT_MIDI_CHANNEL};
bool update_flag = false;
void setup() void setup()
{ {
@ -153,7 +152,6 @@ void setup()
Serial.println(F("https://github.com/dcoredump/MicroDexed")); Serial.println(F("https://github.com/dcoredump/MicroDexed"));
Serial.println(F("<setup start>")); Serial.println(F("<setup start>"));
//init_eeprom();
initial_values_from_eeprom(); initial_values_from_eeprom();
setup_midi_devices(); setup_midi_devices();
@ -241,9 +239,9 @@ void setup()
mixer2.gain(2, mapfloat(effect_delay_volume, 0, ENC_DELAY_VOLUME_STEPS, 0.0, 1.0)); // only delayed signal (without feedback) mixer2.gain(2, mapfloat(effect_delay_volume, 0, ENC_DELAY_VOLUME_STEPS, 0.0, 1.0)); // only delayed signal (without feedback)
// just for testing: // just for testing:
dexed->fx.uiReso=0.5; dexed->fx.uiReso = 0.5;
dexed->fx.uiGain=0.5; dexed->fx.uiGain = 0.5;
dexed->fx.uiCutoff=0.5; dexed->fx.uiCutoff = 0.5;
// load default SYSEX data // load default SYSEX data
load_sysex(configuration.bank, configuration.voice); load_sysex(configuration.bank, configuration.voice);
@ -323,7 +321,7 @@ void loop()
} }
// EEPROM update handling // EEPROM update handling
if (autostore >= AUTOSTORE_MS && active_voices == 0) if (autostore >= AUTOSTORE_MS && active_voices == 0 && update_flag == true)
{ {
// only store configuration data to EEPROM when AUTOSTORE_MS is reached and no voices are activated anymore // only store configuration data to EEPROM when AUTOSTORE_MS is reached and no voices are activated anymore
eeprom_update(); eeprom_update();
@ -773,24 +771,30 @@ inline float logvol(float x)
void initial_values_from_eeprom(void) void initial_values_from_eeprom(void)
{ {
uint32_t checksum; uint32_t checksum;
config_t tmp_conf;
EEPROM_readAnything(EEPROM_START_ADDRESS, configuration); EEPROM_readAnything(EEPROM_START_ADDRESS, tmp_conf);
checksum = crc32((byte*)&configuration + 4, sizeof(configuration) - 4); checksum = crc32((byte*)&tmp_conf + 4, sizeof(tmp_conf) - 4);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("EEPROM checksum: 0x")); Serial.print(F("EEPROM checksum: 0x"));
Serial.print(configuration.checksum, HEX); Serial.print(tmp_conf.checksum, HEX);
Serial.print(F(" / 0x")); Serial.print(F(" / 0x"));
Serial.print(checksum, HEX); Serial.print(checksum, HEX);
#endif #endif
if (checksum != configuration.checksum) if (checksum != tmp_conf.checksum)
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.print(F(" - mismatch -> initializing EEPROM!")); Serial.print(F(" - mismatch -> initializing EEPROM!"));
#endif #endif
eeprom_update(); eeprom_update();
} }
else
{
EEPROM_readAnything(EEPROM_START_ADDRESS, configuration);
Serial.print(F(" - OK, loading!"));
}
#ifdef DEBUG #ifdef DEBUG
Serial.println(); Serial.println();
#endif #endif
@ -799,12 +803,15 @@ void initial_values_from_eeprom(void)
void eeprom_write(void) void eeprom_write(void)
{ {
autostore = 0; autostore = 0;
update_flag = true;
} }
void eeprom_update(void) void eeprom_update(void)
{ {
autostore = 0; update_flag = false;
configuration.checksum = crc32((byte*)&configuration + 4, sizeof(configuration) - 4);
EEPROM_writeAnything(EEPROM_START_ADDRESS, configuration); EEPROM_writeAnything(EEPROM_START_ADDRESS, configuration);
Serial.println(F("Updating EEPROM with configuration data"));
} }
uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https://www.arduino.cc/en/Tutorial/EEPROMCrc uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https://www.arduino.cc/en/Tutorial/EEPROMCrc

@ -31,7 +31,7 @@
// ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from
// 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h // 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h
#define VERSION "0.9.3" #define VERSION "0.9.4"
//************************************************************************************************* //*************************************************************************************************
//* DEVICE SETTINGS //* DEVICE SETTINGS
@ -41,6 +41,7 @@
#define MIDI_DEVICE_DIN Serial1 #define MIDI_DEVICE_DIN Serial1
#define MIDI_DEVICE_USB 1 #define MIDI_DEVICE_USB 1
#define MIDI_DEVICE_USB_HOST 1 #define MIDI_DEVICE_USB_HOST 1
#define MIDI_DEVICE_NUMBER 0
// AUDIO // AUDIO
// If nothing is defined PT8211 is used as audio output device! // If nothing is defined PT8211 is used as audio output device!

Loading…
Cancel
Save