瀏覽代碼

Initialize default travel_acceleration from EEPROM

When reading uninitialized memory, preset the travel acceleration to be
the same as the default acceleration.
Yuri D'Elia 4 年之前
父節點
當前提交
45811f82aa
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      Firmware/ConfigurationStore.cpp

+ 15 - 0
Firmware/ConfigurationStore.cpp

@@ -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)