My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

configuration_store.cpp 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * configuration_store.cpp
  24. *
  25. * Configuration and EEPROM storage
  26. *
  27. * IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
  28. * in the functions below, also increment the version number. This makes sure that
  29. * the default values are used whenever there is a change to the data, to prevent
  30. * wrong data being written to the variables.
  31. *
  32. * ALSO: Variables in the Store and Retrieve sections must be in the same order.
  33. * If a feature is disabled, some data must still be written that, when read,
  34. * either sets a Sane Default, or results in No Change to the existing value.
  35. *
  36. */
  37. #define EEPROM_VERSION "V24"
  38. // Change EEPROM version if these are changed:
  39. #define EEPROM_OFFSET 100
  40. #define MAX_EXTRUDERS 4
  41. /**
  42. * V24 EEPROM Layout:
  43. *
  44. * 100 Version (char x4)
  45. * 104 EEPROM Checksum (uint16_t)
  46. *
  47. * 106 M92 XYZE planner.axis_steps_per_mm (float x4)
  48. * 122 M203 XYZE planner.max_feedrate_mm_s (float x4)
  49. * 138 M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4)
  50. * 154 M204 P planner.acceleration (float)
  51. * 158 M204 R planner.retract_acceleration (float)
  52. * 162 M204 T planner.travel_acceleration (float)
  53. * 166 M205 S planner.min_feedrate_mm_s (float)
  54. * 170 M205 T planner.min_travel_feedrate_mm_s (float)
  55. * 174 M205 B planner.min_segment_time (ulong)
  56. * 178 M205 X planner.max_xy_jerk (float)
  57. * 182 M205 Z planner.max_z_jerk (float)
  58. * 186 M205 E planner.max_e_jerk (float)
  59. * 190 M206 XYZ home_offset (float x3)
  60. *
  61. * Mesh bed leveling:
  62. * 202 M420 S status (uint8)
  63. * 203 z_offset (float)
  64. * 207 mesh_num_x (uint8 as set in firmware)
  65. * 208 mesh_num_y (uint8 as set in firmware)
  66. * 209 G29 S3 XYZ z_values[][] (float x9, by default, up to float x 81)
  67. *
  68. * AUTO BED LEVELING
  69. * 245 M851 zprobe_zoffset (float)
  70. *
  71. * DELTA:
  72. * 249 M666 XYZ endstop_adj (float x3)
  73. * 261 M665 R delta_radius (float)
  74. * 265 M665 L delta_diagonal_rod (float)
  75. * 269 M665 S delta_segments_per_second (float)
  76. * 273 M665 A delta_diagonal_rod_trim_tower_1 (float)
  77. * 277 M665 B delta_diagonal_rod_trim_tower_2 (float)
  78. * 281 M665 C delta_diagonal_rod_trim_tower_3 (float)
  79. *
  80. * Z_DUAL_ENDSTOPS:
  81. * 285 M666 Z z_endstop_adj (float)
  82. *
  83. * ULTIPANEL:
  84. * 289 M145 S0 H preheatHotendTemp1 (int)
  85. * 291 M145 S0 B preheatBedTemp1 (int)
  86. * 293 M145 S0 F preheatFanSpeed1 (int)
  87. * 295 M145 S1 H preheatHotendTemp2 (int)
  88. * 297 M145 S1 B preheatBedTemp2 (int)
  89. * 299 M145 S1 F preheatFanSpeed2 (int)
  90. *
  91. * PIDTEMP:
  92. * 301 M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
  93. * 317 M301 E1 PIDC Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
  94. * 333 M301 E2 PIDC Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
  95. * 349 M301 E3 PIDC Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
  96. * 365 M301 L lpq_len (int)
  97. *
  98. * PIDTEMPBED:
  99. * 367 M304 PID thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
  100. *
  101. * DOGLCD:
  102. * 379 M250 C lcd_contrast (int)
  103. *
  104. * SCARA:
  105. * 381 M365 XYZ axis_scaling (float x3)
  106. *
  107. * FWRETRACT:
  108. * 393 M209 S autoretract_enabled (bool)
  109. * 394 M207 S retract_length (float)
  110. * 398 M207 W retract_length_swap (float)
  111. * 402 M207 F retract_feedrate_mm_s (float)
  112. * 406 M207 Z retract_zlift (float)
  113. * 410 M208 S retract_recover_length (float)
  114. * 414 M208 W retract_recover_length_swap (float)
  115. * 418 M208 F retract_recover_feedrate_mm_s (float)
  116. *
  117. * Volumetric Extrusion:
  118. * 422 M200 D volumetric_enabled (bool)
  119. * 423 M200 T D filament_size (float x4) (T0..3)
  120. *
  121. * 439 This Slot is Available!
  122. *
  123. */
  124. #include "Marlin.h"
  125. #include "language.h"
  126. #include "endstops.h"
  127. #include "planner.h"
  128. #include "temperature.h"
  129. #include "ultralcd.h"
  130. #include "configuration_store.h"
  131. #if ENABLED(MESH_BED_LEVELING)
  132. #include "mesh_bed_leveling.h"
  133. #endif
  134. uint16_t eeprom_checksum;
  135. const char version[4] = EEPROM_VERSION;
  136. void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
  137. uint8_t c;
  138. while (size--) {
  139. eeprom_write_byte((unsigned char*)pos, *value);
  140. c = eeprom_read_byte((unsigned char*)pos);
  141. if (c != *value) {
  142. SERIAL_ECHO_START;
  143. SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
  144. }
  145. eeprom_checksum += c;
  146. pos++;
  147. value++;
  148. };
  149. }
  150. void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
  151. do {
  152. uint8_t c = eeprom_read_byte((unsigned char*)pos);
  153. *value = c;
  154. eeprom_checksum += c;
  155. pos++;
  156. value++;
  157. } while (--size);
  158. }
  159. /**
  160. * Post-process after Retrieve or Reset
  161. */
  162. void Config_Postprocess() {
  163. // steps per s2 needs to be updated to agree with units per s2
  164. planner.reset_acceleration_rates();
  165. // Make sure delta kinematics are updated before refreshing the
  166. // planner position so the stepper counts will be set correctly.
  167. #if ENABLED(DELTA)
  168. recalc_delta_settings(delta_radius, delta_diagonal_rod);
  169. #endif
  170. // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
  171. // and init stepper.count[], planner.position[] with current_position
  172. planner.refresh_positioning();
  173. #if ENABLED(PIDTEMP)
  174. thermalManager.updatePID();
  175. #endif
  176. calculate_volumetric_multipliers();
  177. }
  178. #if ENABLED(EEPROM_SETTINGS)
  179. #define DUMMY_PID_VALUE 3000.0f
  180. #define EEPROM_START() int eeprom_index = EEPROM_OFFSET
  181. #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
  182. #define EEPROM_WRITE(VAR) _EEPROM_writeData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
  183. #define EEPROM_READ(VAR) _EEPROM_readData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
  184. /**
  185. * M500 - Store Configuration
  186. */
  187. void Config_StoreSettings() {
  188. float dummy = 0.0f;
  189. char ver[4] = "000";
  190. EEPROM_START();
  191. EEPROM_WRITE(ver); // invalidate data first
  192. EEPROM_SKIP(eeprom_checksum); // Skip the checksum slot
  193. eeprom_checksum = 0; // clear before first "real data"
  194. EEPROM_WRITE(planner.axis_steps_per_mm);
  195. EEPROM_WRITE(planner.max_feedrate_mm_s);
  196. EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
  197. EEPROM_WRITE(planner.acceleration);
  198. EEPROM_WRITE(planner.retract_acceleration);
  199. EEPROM_WRITE(planner.travel_acceleration);
  200. EEPROM_WRITE(planner.min_feedrate_mm_s);
  201. EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
  202. EEPROM_WRITE(planner.min_segment_time);
  203. EEPROM_WRITE(planner.max_xy_jerk);
  204. EEPROM_WRITE(planner.max_z_jerk);
  205. EEPROM_WRITE(planner.max_e_jerk);
  206. EEPROM_WRITE(home_offset);
  207. #if ENABLED(MESH_BED_LEVELING)
  208. // Compile time test that sizeof(mbl.z_values) is as expected
  209. typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
  210. uint8_t mesh_num_x = MESH_NUM_X_POINTS,
  211. mesh_num_y = MESH_NUM_Y_POINTS,
  212. dummy_uint8 = mbl.status & _BV(MBL_STATUS_HAS_MESH_BIT);
  213. EEPROM_WRITE(dummy_uint8);
  214. EEPROM_WRITE(mbl.z_offset);
  215. EEPROM_WRITE(mesh_num_x);
  216. EEPROM_WRITE(mesh_num_y);
  217. EEPROM_WRITE(mbl.z_values);
  218. #else
  219. // For disabled MBL write a default mesh
  220. uint8_t mesh_num_x = 3,
  221. mesh_num_y = 3,
  222. dummy_uint8 = 0;
  223. dummy = 0.0f;
  224. EEPROM_WRITE(dummy_uint8);
  225. EEPROM_WRITE(dummy);
  226. EEPROM_WRITE(mesh_num_x);
  227. EEPROM_WRITE(mesh_num_y);
  228. for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_WRITE(dummy);
  229. #endif // MESH_BED_LEVELING
  230. #if !HAS_BED_PROBE
  231. float zprobe_zoffset = 0;
  232. #endif
  233. EEPROM_WRITE(zprobe_zoffset);
  234. // 9 floats for DELTA / Z_DUAL_ENDSTOPS
  235. #if ENABLED(DELTA)
  236. EEPROM_WRITE(endstop_adj); // 3 floats
  237. EEPROM_WRITE(delta_radius); // 1 float
  238. EEPROM_WRITE(delta_diagonal_rod); // 1 float
  239. EEPROM_WRITE(delta_segments_per_second); // 1 float
  240. EEPROM_WRITE(delta_diagonal_rod_trim_tower_1); // 1 float
  241. EEPROM_WRITE(delta_diagonal_rod_trim_tower_2); // 1 float
  242. EEPROM_WRITE(delta_diagonal_rod_trim_tower_3); // 1 float
  243. #elif ENABLED(Z_DUAL_ENDSTOPS)
  244. EEPROM_WRITE(z_endstop_adj); // 1 float
  245. dummy = 0.0f;
  246. for (uint8_t q = 8; q--;) EEPROM_WRITE(dummy);
  247. #else
  248. dummy = 0.0f;
  249. for (uint8_t q = 9; q--;) EEPROM_WRITE(dummy);
  250. #endif
  251. #if DISABLED(ULTIPANEL)
  252. int preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND, preheatBedTemp1 = PREHEAT_1_TEMP_BED, preheatFanSpeed1 = PREHEAT_1_FAN_SPEED,
  253. preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND, preheatBedTemp2 = PREHEAT_2_TEMP_BED, preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
  254. #endif // !ULTIPANEL
  255. EEPROM_WRITE(preheatHotendTemp1);
  256. EEPROM_WRITE(preheatBedTemp1);
  257. EEPROM_WRITE(preheatFanSpeed1);
  258. EEPROM_WRITE(preheatHotendTemp2);
  259. EEPROM_WRITE(preheatBedTemp2);
  260. EEPROM_WRITE(preheatFanSpeed2);
  261. for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
  262. #if ENABLED(PIDTEMP)
  263. if (e < HOTENDS) {
  264. EEPROM_WRITE(PID_PARAM(Kp, e));
  265. EEPROM_WRITE(PID_PARAM(Ki, e));
  266. EEPROM_WRITE(PID_PARAM(Kd, e));
  267. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  268. EEPROM_WRITE(PID_PARAM(Kc, e));
  269. #else
  270. dummy = 1.0f; // 1.0 = default kc
  271. EEPROM_WRITE(dummy);
  272. #endif
  273. }
  274. else
  275. #endif // !PIDTEMP
  276. {
  277. dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
  278. EEPROM_WRITE(dummy); // Kp
  279. dummy = 0.0f;
  280. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy); // Ki, Kd, Kc
  281. }
  282. } // Hotends Loop
  283. #if DISABLED(PID_ADD_EXTRUSION_RATE)
  284. int lpq_len = 20;
  285. #endif
  286. EEPROM_WRITE(lpq_len);
  287. #if DISABLED(PIDTEMPBED)
  288. dummy = DUMMY_PID_VALUE;
  289. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
  290. #else
  291. EEPROM_WRITE(thermalManager.bedKp);
  292. EEPROM_WRITE(thermalManager.bedKi);
  293. EEPROM_WRITE(thermalManager.bedKd);
  294. #endif
  295. #if !HAS_LCD_CONTRAST
  296. const int lcd_contrast = 32;
  297. #endif
  298. EEPROM_WRITE(lcd_contrast);
  299. #if ENABLED(SCARA)
  300. EEPROM_WRITE(axis_scaling); // 3 floats
  301. #else
  302. dummy = 1.0f;
  303. EEPROM_WRITE(dummy);
  304. #endif
  305. #if ENABLED(FWRETRACT)
  306. EEPROM_WRITE(autoretract_enabled);
  307. EEPROM_WRITE(retract_length);
  308. #if EXTRUDERS > 1
  309. EEPROM_WRITE(retract_length_swap);
  310. #else
  311. dummy = 0.0f;
  312. EEPROM_WRITE(dummy);
  313. #endif
  314. EEPROM_WRITE(retract_feedrate_mm_s);
  315. EEPROM_WRITE(retract_zlift);
  316. EEPROM_WRITE(retract_recover_length);
  317. #if EXTRUDERS > 1
  318. EEPROM_WRITE(retract_recover_length_swap);
  319. #else
  320. dummy = 0.0f;
  321. EEPROM_WRITE(dummy);
  322. #endif
  323. EEPROM_WRITE(retract_recover_feedrate_mm_s);
  324. #endif // FWRETRACT
  325. EEPROM_WRITE(volumetric_enabled);
  326. // Save filament sizes
  327. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  328. if (q < COUNT(filament_size)) dummy = filament_size[q];
  329. EEPROM_WRITE(dummy);
  330. }
  331. uint16_t final_checksum = eeprom_checksum,
  332. eeprom_size = eeprom_index;
  333. eeprom_index = EEPROM_OFFSET;
  334. EEPROM_WRITE(version);
  335. EEPROM_WRITE(final_checksum);
  336. // Report storage size
  337. SERIAL_ECHO_START;
  338. SERIAL_ECHOPAIR("Settings Stored (", eeprom_size);
  339. SERIAL_ECHOLNPGM(" bytes)");
  340. }
  341. /**
  342. * M501 - Retrieve Configuration
  343. */
  344. void Config_RetrieveSettings() {
  345. EEPROM_START();
  346. char stored_ver[4];
  347. EEPROM_READ(stored_ver);
  348. uint16_t stored_checksum;
  349. EEPROM_READ(stored_checksum);
  350. // SERIAL_ECHOPAIR("Version: [", ver);
  351. // SERIAL_ECHOPAIR("] Stored version: [", stored_ver);
  352. // SERIAL_ECHOLNPGM("]");
  353. if (strncmp(version, stored_ver, 3) != 0) {
  354. Config_ResetDefault();
  355. }
  356. else {
  357. float dummy = 0;
  358. eeprom_checksum = 0; // clear before reading first "real data"
  359. // version number match
  360. EEPROM_READ(planner.axis_steps_per_mm);
  361. EEPROM_READ(planner.max_feedrate_mm_s);
  362. EEPROM_READ(planner.max_acceleration_mm_per_s2);
  363. EEPROM_READ(planner.acceleration);
  364. EEPROM_READ(planner.retract_acceleration);
  365. EEPROM_READ(planner.travel_acceleration);
  366. EEPROM_READ(planner.min_feedrate_mm_s);
  367. EEPROM_READ(planner.min_travel_feedrate_mm_s);
  368. EEPROM_READ(planner.min_segment_time);
  369. EEPROM_READ(planner.max_xy_jerk);
  370. EEPROM_READ(planner.max_z_jerk);
  371. EEPROM_READ(planner.max_e_jerk);
  372. EEPROM_READ(home_offset);
  373. uint8_t dummy_uint8 = 0, mesh_num_x = 0, mesh_num_y = 0;
  374. EEPROM_READ(dummy_uint8);
  375. EEPROM_READ(dummy);
  376. EEPROM_READ(mesh_num_x);
  377. EEPROM_READ(mesh_num_y);
  378. #if ENABLED(MESH_BED_LEVELING)
  379. mbl.status = dummy_uint8;
  380. mbl.z_offset = dummy;
  381. if (mesh_num_x == MESH_NUM_X_POINTS && mesh_num_y == MESH_NUM_Y_POINTS) {
  382. // EEPROM data fits the current mesh
  383. EEPROM_READ(mbl.z_values);
  384. }
  385. else {
  386. // EEPROM data is stale
  387. mbl.reset();
  388. for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ(dummy);
  389. }
  390. #else
  391. // MBL is disabled - skip the stored data
  392. for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ(dummy);
  393. #endif // MESH_BED_LEVELING
  394. #if !HAS_BED_PROBE
  395. float zprobe_zoffset = 0;
  396. #endif
  397. EEPROM_READ(zprobe_zoffset);
  398. #if ENABLED(DELTA)
  399. EEPROM_READ(endstop_adj); // 3 floats
  400. EEPROM_READ(delta_radius); // 1 float
  401. EEPROM_READ(delta_diagonal_rod); // 1 float
  402. EEPROM_READ(delta_segments_per_second); // 1 float
  403. EEPROM_READ(delta_diagonal_rod_trim_tower_1); // 1 float
  404. EEPROM_READ(delta_diagonal_rod_trim_tower_2); // 1 float
  405. EEPROM_READ(delta_diagonal_rod_trim_tower_3); // 1 float
  406. #elif ENABLED(Z_DUAL_ENDSTOPS)
  407. EEPROM_READ(z_endstop_adj);
  408. dummy = 0.0f;
  409. for (uint8_t q=8; q--;) EEPROM_READ(dummy);
  410. #else
  411. dummy = 0.0f;
  412. for (uint8_t q=9; q--;) EEPROM_READ(dummy);
  413. #endif
  414. #if DISABLED(ULTIPANEL)
  415. int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
  416. preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2;
  417. #endif
  418. EEPROM_READ(preheatHotendTemp1);
  419. EEPROM_READ(preheatBedTemp1);
  420. EEPROM_READ(preheatFanSpeed1);
  421. EEPROM_READ(preheatHotendTemp2);
  422. EEPROM_READ(preheatBedTemp2);
  423. EEPROM_READ(preheatFanSpeed2);
  424. #if ENABLED(PIDTEMP)
  425. for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
  426. EEPROM_READ(dummy); // Kp
  427. if (e < HOTENDS && dummy != DUMMY_PID_VALUE) {
  428. // do not need to scale PID values as the values in EEPROM are already scaled
  429. PID_PARAM(Kp, e) = dummy;
  430. EEPROM_READ(PID_PARAM(Ki, e));
  431. EEPROM_READ(PID_PARAM(Kd, e));
  432. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  433. EEPROM_READ(PID_PARAM(Kc, e));
  434. #else
  435. EEPROM_READ(dummy);
  436. #endif
  437. }
  438. else {
  439. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // Ki, Kd, Kc
  440. }
  441. }
  442. #else // !PIDTEMP
  443. // 4 x 4 = 16 slots for PID parameters
  444. for (uint8_t q = MAX_EXTRUDERS * 4; q--;) EEPROM_READ(dummy); // Kp, Ki, Kd, Kc
  445. #endif // !PIDTEMP
  446. #if DISABLED(PID_ADD_EXTRUSION_RATE)
  447. int lpq_len;
  448. #endif
  449. EEPROM_READ(lpq_len);
  450. #if ENABLED(PIDTEMPBED)
  451. EEPROM_READ(dummy); // bedKp
  452. if (dummy != DUMMY_PID_VALUE) {
  453. thermalManager.bedKp = dummy;
  454. EEPROM_READ(thermalManager.bedKi);
  455. EEPROM_READ(thermalManager.bedKd);
  456. }
  457. #else
  458. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // bedKp, bedKi, bedKd
  459. #endif
  460. #if !HAS_LCD_CONTRAST
  461. int lcd_contrast;
  462. #endif
  463. EEPROM_READ(lcd_contrast);
  464. #if ENABLED(SCARA)
  465. EEPROM_READ(axis_scaling); // 3 floats
  466. #else
  467. EEPROM_READ(dummy);
  468. #endif
  469. #if ENABLED(FWRETRACT)
  470. EEPROM_READ(autoretract_enabled);
  471. EEPROM_READ(retract_length);
  472. #if EXTRUDERS > 1
  473. EEPROM_READ(retract_length_swap);
  474. #else
  475. EEPROM_READ(dummy);
  476. #endif
  477. EEPROM_READ(retract_feedrate_mm_s);
  478. EEPROM_READ(retract_zlift);
  479. EEPROM_READ(retract_recover_length);
  480. #if EXTRUDERS > 1
  481. EEPROM_READ(retract_recover_length_swap);
  482. #else
  483. EEPROM_READ(dummy);
  484. #endif
  485. EEPROM_READ(retract_recover_feedrate_mm_s);
  486. #endif // FWRETRACT
  487. EEPROM_READ(volumetric_enabled);
  488. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  489. EEPROM_READ(dummy);
  490. if (q < COUNT(filament_size)) filament_size[q] = dummy;
  491. }
  492. if (eeprom_checksum == stored_checksum) {
  493. Config_Postprocess();
  494. SERIAL_ECHO_START;
  495. SERIAL_ECHO(version);
  496. SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index);
  497. SERIAL_ECHOLNPGM(" bytes)");
  498. }
  499. else {
  500. SERIAL_ERROR_START;
  501. SERIAL_ERRORLNPGM("EEPROM checksum mismatch");
  502. Config_ResetDefault();
  503. }
  504. }
  505. #if ENABLED(EEPROM_CHITCHAT)
  506. Config_PrintSettings();
  507. #endif
  508. }
  509. #endif // EEPROM_SETTINGS
  510. /**
  511. * M502 - Reset Configuration
  512. */
  513. void Config_ResetDefault() {
  514. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  515. float tmp2[] = DEFAULT_MAX_FEEDRATE;
  516. long tmp3[] = DEFAULT_MAX_ACCELERATION;
  517. LOOP_XYZE(i) {
  518. planner.axis_steps_per_mm[i] = tmp1[i];
  519. planner.max_feedrate_mm_s[i] = tmp2[i];
  520. planner.max_acceleration_mm_per_s2[i] = tmp3[i];
  521. #if ENABLED(SCARA)
  522. if (i < COUNT(axis_scaling))
  523. axis_scaling[i] = 1;
  524. #endif
  525. }
  526. planner.acceleration = DEFAULT_ACCELERATION;
  527. planner.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  528. planner.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  529. planner.min_feedrate_mm_s = DEFAULT_MINIMUMFEEDRATE;
  530. planner.min_segment_time = DEFAULT_MINSEGMENTTIME;
  531. planner.min_travel_feedrate_mm_s = DEFAULT_MINTRAVELFEEDRATE;
  532. planner.max_xy_jerk = DEFAULT_XYJERK;
  533. planner.max_z_jerk = DEFAULT_ZJERK;
  534. planner.max_e_jerk = DEFAULT_EJERK;
  535. home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
  536. #if ENABLED(MESH_BED_LEVELING)
  537. mbl.reset();
  538. #endif
  539. #if HAS_BED_PROBE
  540. zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER;
  541. #endif
  542. #if ENABLED(DELTA)
  543. endstop_adj[X_AXIS] = endstop_adj[Y_AXIS] = endstop_adj[Z_AXIS] = 0;
  544. delta_radius = DELTA_RADIUS;
  545. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  546. delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
  547. delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1;
  548. delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2;
  549. delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3;
  550. #elif ENABLED(Z_DUAL_ENDSTOPS)
  551. z_endstop_adj = 0;
  552. #endif
  553. #if ENABLED(ULTIPANEL)
  554. preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND;
  555. preheatBedTemp1 = PREHEAT_1_TEMP_BED;
  556. preheatFanSpeed1 = PREHEAT_1_FAN_SPEED;
  557. preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND;
  558. preheatBedTemp2 = PREHEAT_2_TEMP_BED;
  559. preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
  560. #endif
  561. #if HAS_LCD_CONTRAST
  562. lcd_contrast = DEFAULT_LCD_CONTRAST;
  563. #endif
  564. #if ENABLED(PIDTEMP)
  565. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  566. HOTEND_LOOP()
  567. #else
  568. int e = 0; UNUSED(e); // only need to write once
  569. #endif
  570. {
  571. PID_PARAM(Kp, e) = DEFAULT_Kp;
  572. PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
  573. PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
  574. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  575. PID_PARAM(Kc, e) = DEFAULT_Kc;
  576. #endif
  577. }
  578. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  579. lpq_len = 20; // default last-position-queue size
  580. #endif
  581. #endif // PIDTEMP
  582. #if ENABLED(PIDTEMPBED)
  583. thermalManager.bedKp = DEFAULT_bedKp;
  584. thermalManager.bedKi = scalePID_i(DEFAULT_bedKi);
  585. thermalManager.bedKd = scalePID_d(DEFAULT_bedKd);
  586. #endif
  587. #if ENABLED(FWRETRACT)
  588. autoretract_enabled = false;
  589. retract_length = RETRACT_LENGTH;
  590. #if EXTRUDERS > 1
  591. retract_length_swap = RETRACT_LENGTH_SWAP;
  592. #endif
  593. retract_feedrate_mm_s = RETRACT_FEEDRATE;
  594. retract_zlift = RETRACT_ZLIFT;
  595. retract_recover_length = RETRACT_RECOVER_LENGTH;
  596. #if EXTRUDERS > 1
  597. retract_recover_length_swap = RETRACT_RECOVER_LENGTH_SWAP;
  598. #endif
  599. retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE;
  600. #endif
  601. volumetric_enabled = false;
  602. for (uint8_t q = 0; q < COUNT(filament_size); q++)
  603. filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
  604. endstops.enable_globally(
  605. #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
  606. (true)
  607. #else
  608. (false)
  609. #endif
  610. );
  611. Config_Postprocess();
  612. SERIAL_ECHO_START;
  613. SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
  614. }
  615. #if DISABLED(DISABLE_M503)
  616. #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START; }while(0)
  617. /**
  618. * M503 - Print Configuration
  619. */
  620. void Config_PrintSettings(bool forReplay) {
  621. // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown
  622. CONFIG_ECHO_START;
  623. if (!forReplay) {
  624. SERIAL_ECHOLNPGM("Steps per unit:");
  625. CONFIG_ECHO_START;
  626. }
  627. SERIAL_ECHOPAIR(" M92 X", planner.axis_steps_per_mm[X_AXIS]);
  628. SERIAL_ECHOPAIR(" Y", planner.axis_steps_per_mm[Y_AXIS]);
  629. SERIAL_ECHOPAIR(" Z", planner.axis_steps_per_mm[Z_AXIS]);
  630. SERIAL_ECHOPAIR(" E", planner.axis_steps_per_mm[E_AXIS]);
  631. SERIAL_EOL;
  632. CONFIG_ECHO_START;
  633. #if ENABLED(SCARA)
  634. if (!forReplay) {
  635. SERIAL_ECHOLNPGM("Scaling factors:");
  636. CONFIG_ECHO_START;
  637. }
  638. SERIAL_ECHOPAIR(" M365 X", axis_scaling[X_AXIS]);
  639. SERIAL_ECHOPAIR(" Y", axis_scaling[Y_AXIS]);
  640. SERIAL_ECHOPAIR(" Z", axis_scaling[Z_AXIS]);
  641. SERIAL_EOL;
  642. CONFIG_ECHO_START;
  643. #endif // SCARA
  644. if (!forReplay) {
  645. SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
  646. CONFIG_ECHO_START;
  647. }
  648. SERIAL_ECHOPAIR(" M203 X", planner.max_feedrate_mm_s[X_AXIS]);
  649. SERIAL_ECHOPAIR(" Y", planner.max_feedrate_mm_s[Y_AXIS]);
  650. SERIAL_ECHOPAIR(" Z", planner.max_feedrate_mm_s[Z_AXIS]);
  651. SERIAL_ECHOPAIR(" E", planner.max_feedrate_mm_s[E_AXIS]);
  652. SERIAL_EOL;
  653. CONFIG_ECHO_START;
  654. if (!forReplay) {
  655. SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
  656. CONFIG_ECHO_START;
  657. }
  658. SERIAL_ECHOPAIR(" M201 X", planner.max_acceleration_mm_per_s2[X_AXIS]);
  659. SERIAL_ECHOPAIR(" Y", planner.max_acceleration_mm_per_s2[Y_AXIS]);
  660. SERIAL_ECHOPAIR(" Z", planner.max_acceleration_mm_per_s2[Z_AXIS]);
  661. SERIAL_ECHOPAIR(" E", planner.max_acceleration_mm_per_s2[E_AXIS]);
  662. SERIAL_EOL;
  663. CONFIG_ECHO_START;
  664. if (!forReplay) {
  665. SERIAL_ECHOLNPGM("Accelerations: P=printing, R=retract and T=travel");
  666. CONFIG_ECHO_START;
  667. }
  668. SERIAL_ECHOPAIR(" M204 P", planner.acceleration);
  669. SERIAL_ECHOPAIR(" R", planner.retract_acceleration);
  670. SERIAL_ECHOPAIR(" T", planner.travel_acceleration);
  671. SERIAL_EOL;
  672. CONFIG_ECHO_START;
  673. if (!forReplay) {
  674. SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)");
  675. CONFIG_ECHO_START;
  676. }
  677. SERIAL_ECHOPAIR(" M205 S", planner.min_feedrate_mm_s);
  678. SERIAL_ECHOPAIR(" T", planner.min_travel_feedrate_mm_s);
  679. SERIAL_ECHOPAIR(" B", planner.min_segment_time);
  680. SERIAL_ECHOPAIR(" X", planner.max_xy_jerk);
  681. SERIAL_ECHOPAIR(" Z", planner.max_z_jerk);
  682. SERIAL_ECHOPAIR(" E", planner.max_e_jerk);
  683. SERIAL_EOL;
  684. CONFIG_ECHO_START;
  685. if (!forReplay) {
  686. SERIAL_ECHOLNPGM("Home offset (mm)");
  687. CONFIG_ECHO_START;
  688. }
  689. SERIAL_ECHOPAIR(" M206 X", home_offset[X_AXIS]);
  690. SERIAL_ECHOPAIR(" Y", home_offset[Y_AXIS]);
  691. SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
  692. SERIAL_EOL;
  693. #if ENABLED(MESH_BED_LEVELING)
  694. if (!forReplay) {
  695. SERIAL_ECHOLNPGM("Mesh bed leveling:");
  696. CONFIG_ECHO_START;
  697. }
  698. SERIAL_ECHOPAIR(" M420 S", mbl.has_mesh() ? 1 : 0);
  699. SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
  700. SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
  701. SERIAL_EOL;
  702. for (uint8_t py = 1; py <= MESH_NUM_Y_POINTS; py++) {
  703. for (uint8_t px = 1; px <= MESH_NUM_X_POINTS; px++) {
  704. CONFIG_ECHO_START;
  705. SERIAL_ECHOPAIR(" G29 S3 X", px);
  706. SERIAL_ECHOPAIR(" Y", py);
  707. SERIAL_ECHOPGM(" Z");
  708. SERIAL_PROTOCOL_F(mbl.z_values[py-1][px-1], 5);
  709. SERIAL_EOL;
  710. }
  711. }
  712. #endif
  713. #if ENABLED(DELTA)
  714. CONFIG_ECHO_START;
  715. if (!forReplay) {
  716. SERIAL_ECHOLNPGM("Endstop adjustment (mm):");
  717. CONFIG_ECHO_START;
  718. }
  719. SERIAL_ECHOPAIR(" M666 X", endstop_adj[X_AXIS]);
  720. SERIAL_ECHOPAIR(" Y", endstop_adj[Y_AXIS]);
  721. SERIAL_ECHOPAIR(" Z", endstop_adj[Z_AXIS]);
  722. SERIAL_EOL;
  723. CONFIG_ECHO_START;
  724. if (!forReplay) {
  725. SERIAL_ECHOLNPGM("Delta settings: L=diagonal_rod, R=radius, S=segments_per_second, ABC=diagonal_rod_trim_tower_[123]");
  726. CONFIG_ECHO_START;
  727. }
  728. SERIAL_ECHOPAIR(" M665 L", delta_diagonal_rod);
  729. SERIAL_ECHOPAIR(" R", delta_radius);
  730. SERIAL_ECHOPAIR(" S", delta_segments_per_second);
  731. SERIAL_ECHOPAIR(" A", delta_diagonal_rod_trim_tower_1);
  732. SERIAL_ECHOPAIR(" B", delta_diagonal_rod_trim_tower_2);
  733. SERIAL_ECHOPAIR(" C", delta_diagonal_rod_trim_tower_3);
  734. SERIAL_EOL;
  735. #elif ENABLED(Z_DUAL_ENDSTOPS)
  736. CONFIG_ECHO_START;
  737. if (!forReplay) {
  738. SERIAL_ECHOLNPGM("Z2 Endstop adjustment (mm):");
  739. CONFIG_ECHO_START;
  740. }
  741. SERIAL_ECHOPAIR(" M666 Z", z_endstop_adj);
  742. SERIAL_EOL;
  743. #endif // DELTA
  744. #if ENABLED(ULTIPANEL)
  745. CONFIG_ECHO_START;
  746. if (!forReplay) {
  747. SERIAL_ECHOLNPGM("Material heatup parameters:");
  748. CONFIG_ECHO_START;
  749. }
  750. SERIAL_ECHOPAIR(" M145 S0 H", preheatHotendTemp1);
  751. SERIAL_ECHOPAIR(" B", preheatBedTemp1);
  752. SERIAL_ECHOPAIR(" F", preheatFanSpeed1);
  753. SERIAL_EOL;
  754. CONFIG_ECHO_START;
  755. SERIAL_ECHOPAIR(" M145 S1 H", preheatHotendTemp2);
  756. SERIAL_ECHOPAIR(" B", preheatBedTemp2);
  757. SERIAL_ECHOPAIR(" F", preheatFanSpeed2);
  758. SERIAL_EOL;
  759. #endif // ULTIPANEL
  760. #if HAS_PID_HEATING
  761. CONFIG_ECHO_START;
  762. if (!forReplay) {
  763. SERIAL_ECHOLNPGM("PID settings:");
  764. }
  765. #if ENABLED(PIDTEMP)
  766. #if HOTENDS > 1
  767. if (forReplay) {
  768. HOTEND_LOOP() {
  769. CONFIG_ECHO_START;
  770. SERIAL_ECHOPAIR(" M301 E", e);
  771. SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, e));
  772. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, e)));
  773. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, e)));
  774. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  775. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
  776. if (e == 0) SERIAL_ECHOPAIR(" L", lpq_len);
  777. #endif
  778. SERIAL_EOL;
  779. }
  780. }
  781. else
  782. #endif // HOTENDS > 1
  783. // !forReplay || HOTENDS == 1
  784. {
  785. CONFIG_ECHO_START;
  786. SERIAL_ECHOPAIR(" M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echo values for E0
  787. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
  788. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
  789. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  790. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, 0));
  791. SERIAL_ECHOPAIR(" L", lpq_len);
  792. #endif
  793. SERIAL_EOL;
  794. }
  795. #endif // PIDTEMP
  796. #if ENABLED(PIDTEMPBED)
  797. CONFIG_ECHO_START;
  798. SERIAL_ECHOPAIR(" M304 P", thermalManager.bedKp);
  799. SERIAL_ECHOPAIR(" I", unscalePID_i(thermalManager.bedKi));
  800. SERIAL_ECHOPAIR(" D", unscalePID_d(thermalManager.bedKd));
  801. SERIAL_EOL;
  802. #endif
  803. #endif // PIDTEMP || PIDTEMPBED
  804. #if HAS_LCD_CONTRAST
  805. CONFIG_ECHO_START;
  806. if (!forReplay) {
  807. SERIAL_ECHOLNPGM("LCD Contrast:");
  808. CONFIG_ECHO_START;
  809. }
  810. SERIAL_ECHOPAIR(" M250 C", lcd_contrast);
  811. SERIAL_EOL;
  812. #endif
  813. #if ENABLED(FWRETRACT)
  814. CONFIG_ECHO_START;
  815. if (!forReplay) {
  816. SERIAL_ECHOLNPGM("Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)");
  817. CONFIG_ECHO_START;
  818. }
  819. SERIAL_ECHOPAIR(" M207 S", retract_length);
  820. #if EXTRUDERS > 1
  821. SERIAL_ECHOPAIR(" W", retract_length_swap);
  822. #endif
  823. SERIAL_ECHOPAIR(" F", MMS_TO_MMM(retract_feedrate_mm_s));
  824. SERIAL_ECHOPAIR(" Z", retract_zlift);
  825. SERIAL_EOL;
  826. CONFIG_ECHO_START;
  827. if (!forReplay) {
  828. SERIAL_ECHOLNPGM("Recover: S=Extra length (mm) F:Speed (mm/m)");
  829. CONFIG_ECHO_START;
  830. }
  831. SERIAL_ECHOPAIR(" M208 S", retract_recover_length);
  832. #if EXTRUDERS > 1
  833. SERIAL_ECHOPAIR(" W", retract_recover_length_swap);
  834. #endif
  835. SERIAL_ECHOPAIR(" F", MMS_TO_MMM(retract_recover_feedrate_mm_s));
  836. SERIAL_EOL;
  837. CONFIG_ECHO_START;
  838. if (!forReplay) {
  839. SERIAL_ECHOLNPGM("Auto-Retract: S=0 to disable, 1 to interpret extrude-only moves as retracts or recoveries");
  840. CONFIG_ECHO_START;
  841. }
  842. SERIAL_ECHOPAIR(" M209 S", autoretract_enabled ? 1 : 0);
  843. SERIAL_EOL;
  844. #endif // FWRETRACT
  845. /**
  846. * Volumetric extrusion M200
  847. */
  848. if (!forReplay) {
  849. CONFIG_ECHO_START;
  850. SERIAL_ECHOPGM("Filament settings:");
  851. if (volumetric_enabled)
  852. SERIAL_EOL;
  853. else
  854. SERIAL_ECHOLNPGM(" Disabled");
  855. }
  856. CONFIG_ECHO_START;
  857. SERIAL_ECHOPAIR(" M200 D", filament_size[0]);
  858. SERIAL_EOL;
  859. #if EXTRUDERS > 1
  860. CONFIG_ECHO_START;
  861. SERIAL_ECHOPAIR(" M200 T1 D", filament_size[1]);
  862. SERIAL_EOL;
  863. #if EXTRUDERS > 2
  864. CONFIG_ECHO_START;
  865. SERIAL_ECHOPAIR(" M200 T2 D", filament_size[2]);
  866. SERIAL_EOL;
  867. #if EXTRUDERS > 3
  868. CONFIG_ECHO_START;
  869. SERIAL_ECHOPAIR(" M200 T3 D", filament_size[3]);
  870. SERIAL_EOL;
  871. #endif
  872. #endif
  873. #endif
  874. if (!volumetric_enabled) {
  875. CONFIG_ECHO_START;
  876. SERIAL_ECHOLNPGM(" M200 D0");
  877. }
  878. /**
  879. * Auto Bed Leveling
  880. */
  881. #if HAS_BED_PROBE
  882. if (!forReplay) {
  883. CONFIG_ECHO_START;
  884. SERIAL_ECHOLNPGM("Z-Probe Offset (mm):");
  885. }
  886. CONFIG_ECHO_START;
  887. SERIAL_ECHOPAIR(" M851 Z", zprobe_zoffset);
  888. SERIAL_EOL;
  889. #endif
  890. }
  891. #endif // !DISABLE_M503