#define CONFIG_VERSION "md4" // ID of the E settings block, change if structure changes
struct config_t {
unsigned long calibration_factor;
long calibration_constant;
//unsigned long long freq[NUM_BANDS]; //these don't need to be in eeprom as they are in rom and don't change
//int mode[NUM_BANDS];
//int bwu[NUM_BANDS];
//int bwl[NUM_BANDS];
//int rfg[NUM_BANDS];
int band;
float32_t LPFcoeff;
int audio_volume;
int8_t AGC_mode;
float32_t pll_fmax;
float32_t omegaN;
int zeta_help;
uint8_t rate;
float32_t bass;
float32_t treble;
int agc_thresh;
int agc_decay;
int agc_slope;
uint8_t auto_IQ_correction;
float32_t midbass;
float32_t mid;
float32_t midtreble;
int8_t RF_attenuation;
uint8_t show_spectrum_flag;
float32_t stereo_factor;
float32_t spectrum_display_scale;
int32_t spectrum_zoom;
uint8_t NR_use_X;
float32_t NR_PSI;
float32_t NR_alpha;
float32_t NR_beta;
char version_of_settings[4]; // validation string
} E ={ //these will be the default settings when saved values are not found
calibration_factor,
calibration_constant,
band,
LPF_spectrum,
audio_volume,
AGC_mode,
pll_fmax,
omegaN,
zeta_help,
SAMPLE_RATE,
bass,
treble,
agc_thresh,
agc_decay,
agc_slope,
auto_IQ_correction,
midbass,
mid,
midtreble,
RF_attenuation,
show_spectrum_flag,
stereo_factor,
spectrum_display_scale,
spectrum_zoom,
NR_use_X,
NR_PSI,
NR_alpha,
NR_beta,
CONFIG_VERSION
};
void EEPROM_LOAD() {
// To make sure there are settings, and they are YOURS!
if (EEPROM.read(0 + sizeof(E) - 1) == E.version_of_settings[3] &&// this is '\0'
EEPROM.read(0 + sizeof(E) - 2) == E.version_of_settings[2] &&
EEPROM.read(0 + sizeof(E) - 3) == E.version_of_settings[1] &&
EEPROM.read(0 + sizeof(E) - 4) == E.version_of_settings[0])
{ // ID correct, use settings from EEPROM
eeprom_read_block(&E, 0, sizeof(E));
delay(100);
Serial.println("loaded settings from EEPROM");
calibration_factor = E.calibration_factor;
calibration_constant = E.calibration_constant;
//for (int i = 0; i < (NUM_BANDS); i++) //these don't need to be in eeprom as they are in rom and don't change
// bands[i].freq = E.freq[i];
//for (int i = 0; i < (NUM_BANDS); i++)
// bands[i].mode = E.mode[i];
//for (int i = 0; i < (NUM_BANDS); i++)
// bands[i].FHiCut = E.bwu[i];
//for (int i = 0; i < (NUM_BANDS); i++)
// bands[i].FLoCut = E.bwl[i];
//for (int i = 0; i < (NUM_BANDS); i++)
// bands[i].RFgain = E.rfg[i];
band = E.band;
LPF_spectrum = E.LPFcoeff;
audio_volume = E.audio_volume;
AGC_mode = E.AGC_mode;
pll_fmax = E.pll_fmax;
omegaN = E.omegaN;
zeta_help = E.zeta_help;
zeta = (float32_t) zeta_help / 100.0;
SAMPLE_RATE = E.rate;
bass = E.bass;
treble = E.treble;
agc_thresh = E.agc_thresh;
agc_decay = E.agc_decay;
agc_slope = E.agc_slope;
auto_IQ_correction = E.auto_IQ_correction;
midbass = E.midbass;
mid = E.mid;
midtreble = E.midtreble;
RF_attenuation = E.RF_attenuation;
show_spectrum_flag = E.show_spectrum_flag;
stereo_factor = E.stereo_factor;
spectrum_display_scale = E.spectrum_display_scale;
spectrum_zoom = E.spectrum_zoom;
NR_use_X = E.NR_use_X;
NR_PSI = E.NR_PSI;
NR_alpha = E.NR_alpha;
NR_beta = E.NR_beta;
} else {
// settings aren't valid! will overwrite with default settings
Serial.println("Couldn't find saved settings in EEprom, will use defaults");
EEPROM_SAVE(); //save with default values read during setup
}
} // end void eeProm LOAD
void EEPROM_SAVE() {
E.calibration_factor = calibration_factor;
E.band = band;
E.calibration_constant = calibration_constant;
E.LPFcoeff = LPF_spectrum;
E.audio_volume = audio_volume;
E.AGC_mode = AGC_mode;
E.pll_fmax = pll_fmax;
E.omegaN = omegaN;
E.zeta_help = zeta_help;
E.rate = SAMPLE_RATE;
E.bass = bass;
E.treble = treble;
E.agc_thresh = agc_thresh;
E.agc_decay = agc_decay;
E.agc_slope = agc_slope;
E.auto_IQ_correction = auto_IQ_correction;
E.midbass = midbass;
E.mid = mid;
E.midtreble = midtreble;
E.RF_attenuation = RF_attenuation;
E.show_spectrum_flag = show_spectrum_flag;
E.stereo_factor = stereo_factor;
E.spectrum_display_scale = spectrum_display_scale;
E.spectrum_zoom = spectrum_zoom;
E.NR_use_X = NR_use_X;
E.NR_PSI = NR_PSI;
E.NR_alpha = NR_alpha;
E.NR_beta = NR_beta;
eeprom_write_block (&E, 0, sizeof(E));
Serial.print("saved settings version: ");Serial.print(E.version_of_settings);Serial.println(" in EEPROM");
} // end void eeProm SAVE