Fix handling of uninitialised EEPROM values

PWM channels now set to 0, CC channel to 30mA, dt to 1000us
This commit is contained in:
Filip Ayazi 2023-03-13 14:50:03 +00:00
parent c237226428
commit 144093e252
2 changed files with 23 additions and 2 deletions

View file

@ -125,14 +125,27 @@ void illumination_setup()
#ifdef WIRING_CC_LED #ifdef WIRING_CC_LED
EEPROM.get(cc_value_eeprom, cc_value); EEPROM.get(cc_value_eeprom, cc_value);
pinMode(WIRING_CC_LED, OUTPUT); pinMode(WIRING_CC_LED, OUTPUT);
if (cc_value > 32.0)
{
//default value ~30mA
cc_value = 10;
EEPROM.put(cc_value_eeprom, cc_value);
}
if (cc_value > 0) if (cc_value > 0)
cc_set_value(cc_value/32.0); cc_set_value(cc_value/32.0);
#endif #endif
bool frequency_valid = false;
#ifdef MCU_PICO #ifdef MCU_PICO
frequency_valid = true;
EEPROM.get(pwm_frequency_eeprom, pwm_frequency); EEPROM.get(pwm_frequency_eeprom, pwm_frequency);
if (pwm_frequency < 1) if (pwm_frequency < 1 || pwm_frequency > 2000000)
{
frequency_valid = false;
pwm_frequency = 64000; pwm_frequency = 64000;
EEPROM.put(pwm_frequency_eeprom, pwm_frequency);
}
analogWriteRange(65535); analogWriteRange(65535);
analogWriteFreq(pwm_frequency);//32khz seems sensible analogWriteFreq(pwm_frequency);//32khz seems sensible
#endif #endif
@ -140,6 +153,14 @@ void illumination_setup()
for(int i = 0; i < PWM_NUM; i++) for(int i = 0; i < PWM_NUM; i++)
{ {
EEPROM.get(pwm_values_eeprom+i*sizeof(uint16_t), pwm_values[i]); EEPROM.get(pwm_values_eeprom+i*sizeof(uint16_t), pwm_values[i]);
//rp2040 has 16bit PWM range so we rely on frequency to check if this
//is the first start. On other platforms this value is enough
if (pwm_values[i] == 65535 && !frequency_valid)
{
pwm_values[i] = 0;
EEPROM.put(pwm_values_eeprom+i*sizeof(uint16_t), pwm_values[i]);
}
if (pwm_values[i] > 0) if (pwm_values[i] > 0)
analogWrite(pwm_led_pins[i], pwm_values[i]); analogWrite(pwm_led_pins[i], pwm_values[i]);
} }

View file

@ -54,7 +54,7 @@ void stage_setup()
} }
EEPROM.get(min_step_delay_eeprom, min_step_delay); EEPROM.get(min_step_delay_eeprom, min_step_delay);
if (min_step_delay < 0) if (min_step_delay <= 0)
{ // -1 seems to be what we get if it's uninitialised. { // -1 seems to be what we get if it's uninitialised.
min_step_delay = 1000; min_step_delay = 1000;
EEPROM.put(min_step_delay_eeprom, min_step_delay); EEPROM.put(min_step_delay_eeprom, min_step_delay);