My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

configuration_store.cpp 29KB

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