Fixes for autostoring configuration data to EEPROM.

pull/4/head
Holger Wirtz 6 years ago
parent 1866ed69a1
commit 0560f84b12
  1. 25
      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 voice_names[MAX_VOICES][VOICE_NAME_LEN];
elapsedMillis autostore;
uint8_t eeprom_update_status = 0;
uint16_t autostore_value = AUTOSTORE_MS;
uint8_t midi_timing_counter = 0; // 24 per qarter
elapsedMillis midi_timing_timestep;
uint16_t midi_timing_quarter = 0;
@ -125,6 +123,7 @@ uint8_t active_voices = 0;
elapsedMillis cpu_mem_millis;
#endif
config_t configuration = {0xffff, 0, 0, VOLUME, 0.5f, DEFAULT_MIDI_CHANNEL};
bool update_flag = false;
void setup()
{
@ -153,7 +152,6 @@ void setup()
Serial.println(F("https://github.com/dcoredump/MicroDexed"));
Serial.println(F("<setup start>"));
//init_eeprom();
initial_values_from_eeprom();
setup_midi_devices();
@ -323,7 +321,7 @@ void loop()
}
// 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
eeprom_update();
@ -773,24 +771,30 @@ inline float logvol(float x)
void initial_values_from_eeprom(void)
{
uint32_t checksum;
config_t tmp_conf;
EEPROM_readAnything(EEPROM_START_ADDRESS, configuration);
checksum = crc32((byte*)&configuration + 4, sizeof(configuration) - 4);
EEPROM_readAnything(EEPROM_START_ADDRESS, tmp_conf);
checksum = crc32((byte*)&tmp_conf + 4, sizeof(tmp_conf) - 4);
#ifdef DEBUG
Serial.print(F("EEPROM checksum: 0x"));
Serial.print(configuration.checksum, HEX);
Serial.print(tmp_conf.checksum, HEX);
Serial.print(F(" / 0x"));
Serial.print(checksum, HEX);
#endif
if (checksum != configuration.checksum)
if (checksum != tmp_conf.checksum)
{
#ifdef DEBUG
Serial.print(F(" - mismatch -> initializing EEPROM!"));
#endif
eeprom_update();
}
else
{
EEPROM_readAnything(EEPROM_START_ADDRESS, configuration);
Serial.print(F(" - OK, loading!"));
}
#ifdef DEBUG
Serial.println();
#endif
@ -799,12 +803,15 @@ void initial_values_from_eeprom(void)
void eeprom_write(void)
{
autostore = 0;
update_flag = true;
}
void eeprom_update(void)
{
autostore = 0;
update_flag = false;
configuration.checksum = crc32((byte*)&configuration + 4, sizeof(configuration) - 4);
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

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

Loading…
Cancel
Save