Initialize default travel_acceleration from EEPROM

When reading uninitialized memory, preset the travel acceleration to be
the same as the default acceleration.
This commit is contained in:
Yuri D'Elia 2020-09-20 19:04:08 +02:00
parent 5589954b77
commit 45811f82aa

View File

@ -235,6 +235,18 @@ static const M500_conf default_conf PROGMEM =
DEFAULT_TRAVEL_ACCELERATION,
};
static bool is_uninitialized(void* addr, uint8_t len)
{
while(len--)
{
if(reinterpret_cast<uint8_t*>(addr)[len] != 0xff)
return false;
}
return true;
}
//! @brief Read M500 configuration
//! @retval true Succeeded. Stored settings retrieved or default settings retrieved in case EEPROM has been erased.
//! @retval false Failed. Default settings has been retrieved, because of older version or corrupted data.
@ -294,6 +306,9 @@ bool Config_RetrieveSettings()
tmc2130_set_res(E_AXIS, cs.axis_ustep_resolution[E_AXIS]);
#endif //TMC2130
if(is_uninitialized(&cs.travel_acceleration, sizeof(cs.travel_acceleration)))
cs.travel_acceleration = cs.acceleration;
reset_acceleration_rates();
// Call updatePID (similar to when we have processed M301)