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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
  317. if (strncmp(ver, stored_ver, 3) != 0) {
  318. Config_ResetDefault();
  319. }
  320. else {
  321. float dummy = 0;
  322. // version number match
  323. EEPROM_READ_VAR(i, planner.axis_steps_per_mm);
  324. EEPROM_READ_VAR(i, planner.max_feedrate);
  325. EEPROM_READ_VAR(i, planner.max_acceleration_mm_per_s2);
  326. // 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)
  327. planner.reset_acceleration_rates();
  328. EEPROM_READ_VAR(i, planner.acceleration);
  329. EEPROM_READ_VAR(i, planner.retract_acceleration);
  330. EEPROM_READ_VAR(i, planner.travel_acceleration);
  331. EEPROM_READ_VAR(i, planner.min_feedrate);
  332. EEPROM_READ_VAR(i, planner.min_travel_feedrate);
  333. EEPROM_READ_VAR(i, planner.min_segment_time);
  334. EEPROM_READ_VAR(i, planner.max_xy_jerk);
  335. EEPROM_READ_VAR(i, planner.max_z_jerk);
  336. EEPROM_READ_VAR(i, planner.max_e_jerk);
  337. EEPROM_READ_VAR(i, home_offset);
  338. uint8_t dummy_uint8 = 0, mesh_num_x = 0, mesh_num_y = 0;
  339. EEPROM_READ_VAR(i, dummy_uint8);
  340. EEPROM_READ_VAR(i, dummy);
  341. EEPROM_READ_VAR(i, mesh_num_x);
  342. EEPROM_READ_VAR(i, mesh_num_y);
  343. #if ENABLED(MESH_BED_LEVELING)
  344. mbl.status = dummy_uint8;
  345. mbl.z_offset = dummy;
  346. if (mesh_num_x == MESH_NUM_X_POINTS && mesh_num_y == MESH_NUM_Y_POINTS) {
  347. EEPROM_READ_VAR(i, mbl.z_values);
  348. } else {
  349. mbl.reset();
  350. for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ_VAR(i, dummy);
  351. }
  352. #else
  353. for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ_VAR(i, dummy);
  354. #endif // MESH_BED_LEVELING
  355. #if !HAS_BED_PROBE
  356. float zprobe_zoffset = 0;
  357. #endif
  358. EEPROM_READ_VAR(i, zprobe_zoffset);
  359. #if ENABLED(DELTA)
  360. EEPROM_READ_VAR(i, endstop_adj); // 3 floats
  361. EEPROM_READ_VAR(i, delta_radius); // 1 float
  362. EEPROM_READ_VAR(i, delta_diagonal_rod); // 1 float
  363. EEPROM_READ_VAR(i, delta_segments_per_second); // 1 float
  364. EEPROM_READ_VAR(i, delta_diagonal_rod_trim_tower_1); // 1 float
  365. EEPROM_READ_VAR(i, delta_diagonal_rod_trim_tower_2); // 1 float
  366. EEPROM_READ_VAR(i, delta_diagonal_rod_trim_tower_3); // 1 float
  367. recalc_delta_settings(delta_radius, delta_diagonal_rod);
  368. #elif ENABLED(Z_DUAL_ENDSTOPS)
  369. EEPROM_READ_VAR(i, z_endstop_adj);
  370. dummy = 0.0f;
  371. for (uint8_t q=8; q--;) EEPROM_READ_VAR(i, dummy);
  372. #else
  373. dummy = 0.0f;
  374. for (uint8_t q=9; q--;) EEPROM_READ_VAR(i, dummy);
  375. #endif
  376. #if DISABLED(ULTIPANEL)
  377. int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed,
  378. absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed;
  379. #endif
  380. EEPROM_READ_VAR(i, plaPreheatHotendTemp);
  381. EEPROM_READ_VAR(i, plaPreheatHPBTemp);
  382. EEPROM_READ_VAR(i, plaPreheatFanSpeed);
  383. EEPROM_READ_VAR(i, absPreheatHotendTemp);
  384. EEPROM_READ_VAR(i, absPreheatHPBTemp);
  385. EEPROM_READ_VAR(i, absPreheatFanSpeed);
  386. #if ENABLED(PIDTEMP)
  387. for (uint8_t e = 0; e < 4; e++) { // 4 = max extruders currently supported by Marlin
  388. EEPROM_READ_VAR(i, dummy); // Kp
  389. if (e < HOTENDS && dummy != DUMMY_PID_VALUE) {
  390. // do not need to scale PID values as the values in EEPROM are already scaled
  391. PID_PARAM(Kp, e) = dummy;
  392. EEPROM_READ_VAR(i, PID_PARAM(Ki, e));
  393. EEPROM_READ_VAR(i, PID_PARAM(Kd, e));
  394. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  395. EEPROM_READ_VAR(i, PID_PARAM(Kc, e));
  396. #else
  397. EEPROM_READ_VAR(i, dummy);
  398. #endif
  399. }
  400. else {
  401. for (uint8_t q=3; q--;) EEPROM_READ_VAR(i, dummy); // Ki, Kd, Kc
  402. }
  403. }
  404. #else // !PIDTEMP
  405. // 4 x 4 = 16 slots for PID parameters
  406. for (uint8_t q=16; q--;) EEPROM_READ_VAR(i, dummy); // 4x Kp, Ki, Kd, Kc
  407. #endif // !PIDTEMP
  408. #if DISABLED(PID_ADD_EXTRUSION_RATE)
  409. int lpq_len;
  410. #endif
  411. EEPROM_READ_VAR(i, lpq_len);
  412. #if ENABLED(PIDTEMPBED)
  413. EEPROM_READ_VAR(i, dummy); // bedKp
  414. if (dummy != DUMMY_PID_VALUE) {
  415. thermalManager.bedKp = dummy;
  416. EEPROM_READ_VAR(i, thermalManager.bedKi);
  417. EEPROM_READ_VAR(i, thermalManager.bedKd);
  418. }
  419. #else
  420. for (uint8_t q=3; q--;) EEPROM_READ_VAR(i, dummy); // bedKp, bedKi, bedKd
  421. #endif
  422. #if !HAS_LCD_CONTRAST
  423. int lcd_contrast;
  424. #endif
  425. EEPROM_READ_VAR(i, lcd_contrast);
  426. #if ENABLED(SCARA)
  427. EEPROM_READ_VAR(i, axis_scaling); // 3 floats
  428. #else
  429. EEPROM_READ_VAR(i, dummy);
  430. #endif
  431. #if ENABLED(FWRETRACT)
  432. EEPROM_READ_VAR(i, autoretract_enabled);
  433. EEPROM_READ_VAR(i, retract_length);
  434. #if EXTRUDERS > 1
  435. EEPROM_READ_VAR(i, retract_length_swap);
  436. #else
  437. EEPROM_READ_VAR(i, dummy);
  438. #endif
  439. EEPROM_READ_VAR(i, retract_feedrate_mm_s);
  440. EEPROM_READ_VAR(i, retract_zlift);
  441. EEPROM_READ_VAR(i, retract_recover_length);
  442. #if EXTRUDERS > 1
  443. EEPROM_READ_VAR(i, retract_recover_length_swap);
  444. #else
  445. EEPROM_READ_VAR(i, dummy);
  446. #endif
  447. EEPROM_READ_VAR(i, retract_recover_feedrate);
  448. #endif // FWRETRACT
  449. EEPROM_READ_VAR(i, volumetric_enabled);
  450. for (uint8_t q = 0; q < 4; q++) {
  451. EEPROM_READ_VAR(i, dummy);
  452. if (q < EXTRUDERS) filament_size[q] = dummy;
  453. }
  454. calculate_volumetric_multipliers();
  455. // Call thermalManager.updatePID (similar to when we have processed M301)
  456. thermalManager.updatePID();
  457. // Report settings retrieved and length
  458. SERIAL_ECHO_START;
  459. SERIAL_ECHO(ver);
  460. SERIAL_ECHOPAIR(" stored settings retrieved (", i);
  461. SERIAL_ECHOLNPGM(" bytes)");
  462. }
  463. #if ENABLED(EEPROM_CHITCHAT)
  464. Config_PrintSettings();
  465. #endif
  466. }
  467. #endif // EEPROM_SETTINGS
  468. /**
  469. * Reset Configuration Settings - M502
  470. */
  471. void Config_ResetDefault() {
  472. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  473. float tmp2[] = DEFAULT_MAX_FEEDRATE;
  474. long tmp3[] = DEFAULT_MAX_ACCELERATION;
  475. for (uint8_t i = 0; i < NUM_AXIS; i++) {
  476. planner.axis_steps_per_mm[i] = tmp1[i];
  477. planner.max_feedrate[i] = tmp2[i];
  478. planner.max_acceleration_mm_per_s2[i] = tmp3[i];
  479. #if ENABLED(SCARA)
  480. if (i < COUNT(axis_scaling))
  481. axis_scaling[i] = 1;
  482. #endif
  483. }
  484. // steps per sq second need to be updated to agree with the units per sq second
  485. planner.reset_acceleration_rates();
  486. planner.acceleration = DEFAULT_ACCELERATION;
  487. planner.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  488. planner.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  489. planner.min_feedrate = DEFAULT_MINIMUMFEEDRATE;
  490. planner.min_segment_time = DEFAULT_MINSEGMENTTIME;
  491. planner.min_travel_feedrate = DEFAULT_MINTRAVELFEEDRATE;
  492. planner.max_xy_jerk = DEFAULT_XYJERK;
  493. planner.max_z_jerk = DEFAULT_ZJERK;
  494. planner.max_e_jerk = DEFAULT_EJERK;
  495. home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
  496. #if ENABLED(MESH_BED_LEVELING)
  497. mbl.reset();
  498. #endif
  499. #if HAS_BED_PROBE
  500. zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER;
  501. #endif
  502. #if ENABLED(DELTA)
  503. endstop_adj[X_AXIS] = endstop_adj[Y_AXIS] = endstop_adj[Z_AXIS] = 0;
  504. delta_radius = DELTA_RADIUS;
  505. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  506. delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
  507. delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1;
  508. delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2;
  509. delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3;
  510. recalc_delta_settings(delta_radius, delta_diagonal_rod);
  511. #elif ENABLED(Z_DUAL_ENDSTOPS)
  512. z_endstop_adj = 0;
  513. #endif
  514. #if ENABLED(ULTIPANEL)
  515. plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
  516. plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
  517. plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
  518. absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
  519. absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
  520. absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  521. #endif
  522. #if HAS_LCD_CONTRAST
  523. lcd_contrast = DEFAULT_LCD_CONTRAST;
  524. #endif
  525. #if ENABLED(PIDTEMP)
  526. #if ENABLED(PID_PARAMS_PER_HOTEND)
  527. for (uint8_t e = 0; e < HOTENDS; e++)
  528. #else
  529. int e = 0; UNUSED(e); // only need to write once
  530. #endif
  531. {
  532. PID_PARAM(Kp, e) = DEFAULT_Kp;
  533. PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
  534. PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
  535. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  536. PID_PARAM(Kc, e) = DEFAULT_Kc;
  537. #endif
  538. }
  539. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  540. lpq_len = 20; // default last-position-queue size
  541. #endif
  542. // call thermalManager.updatePID (similar to when we have processed M301)
  543. thermalManager.updatePID();
  544. #endif // PIDTEMP
  545. #if ENABLED(PIDTEMPBED)
  546. thermalManager.bedKp = DEFAULT_bedKp;
  547. thermalManager.bedKi = scalePID_i(DEFAULT_bedKi);
  548. thermalManager.bedKd = scalePID_d(DEFAULT_bedKd);
  549. #endif
  550. #if ENABLED(FWRETRACT)
  551. autoretract_enabled = false;
  552. retract_length = RETRACT_LENGTH;
  553. #if EXTRUDERS > 1
  554. retract_length_swap = RETRACT_LENGTH_SWAP;
  555. #endif
  556. retract_feedrate_mm_s = RETRACT_FEEDRATE;
  557. retract_zlift = RETRACT_ZLIFT;
  558. retract_recover_length = RETRACT_RECOVER_LENGTH;
  559. #if EXTRUDERS > 1
  560. retract_recover_length_swap = RETRACT_RECOVER_LENGTH_SWAP;
  561. #endif
  562. retract_recover_feedrate = RETRACT_RECOVER_FEEDRATE;
  563. #endif
  564. volumetric_enabled = false;
  565. for (uint8_t q = 0; q < COUNT(filament_size); q++)
  566. filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
  567. calculate_volumetric_multipliers();
  568. SERIAL_ECHO_START;
  569. SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
  570. }
  571. #if DISABLED(DISABLE_M503)
  572. /**
  573. * Print Configuration Settings - M503
  574. */
  575. #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START; }while(0)
  576. void Config_PrintSettings(bool forReplay) {
  577. // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown
  578. CONFIG_ECHO_START;
  579. if (!forReplay) {
  580. SERIAL_ECHOLNPGM("Steps per unit:");
  581. CONFIG_ECHO_START;
  582. }
  583. SERIAL_ECHOPAIR(" M92 X", planner.axis_steps_per_mm[X_AXIS]);
  584. SERIAL_ECHOPAIR(" Y", planner.axis_steps_per_mm[Y_AXIS]);
  585. SERIAL_ECHOPAIR(" Z", planner.axis_steps_per_mm[Z_AXIS]);
  586. SERIAL_ECHOPAIR(" E", planner.axis_steps_per_mm[E_AXIS]);
  587. SERIAL_EOL;
  588. CONFIG_ECHO_START;
  589. #if ENABLED(SCARA)
  590. if (!forReplay) {
  591. SERIAL_ECHOLNPGM("Scaling factors:");
  592. CONFIG_ECHO_START;
  593. }
  594. SERIAL_ECHOPAIR(" M365 X", axis_scaling[X_AXIS]);
  595. SERIAL_ECHOPAIR(" Y", axis_scaling[Y_AXIS]);
  596. SERIAL_ECHOPAIR(" Z", axis_scaling[Z_AXIS]);
  597. SERIAL_EOL;
  598. CONFIG_ECHO_START;
  599. #endif // SCARA
  600. if (!forReplay) {
  601. SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
  602. CONFIG_ECHO_START;
  603. }
  604. SERIAL_ECHOPAIR(" M203 X", planner.max_feedrate[X_AXIS]);
  605. SERIAL_ECHOPAIR(" Y", planner.max_feedrate[Y_AXIS]);
  606. SERIAL_ECHOPAIR(" Z", planner.max_feedrate[Z_AXIS]);
  607. SERIAL_ECHOPAIR(" E", planner.max_feedrate[E_AXIS]);
  608. SERIAL_EOL;
  609. CONFIG_ECHO_START;
  610. if (!forReplay) {
  611. SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
  612. CONFIG_ECHO_START;
  613. }
  614. SERIAL_ECHOPAIR(" M201 X", planner.max_acceleration_mm_per_s2[X_AXIS]);
  615. SERIAL_ECHOPAIR(" Y", planner.max_acceleration_mm_per_s2[Y_AXIS]);
  616. SERIAL_ECHOPAIR(" Z", planner.max_acceleration_mm_per_s2[Z_AXIS]);
  617. SERIAL_ECHOPAIR(" E", planner.max_acceleration_mm_per_s2[E_AXIS]);
  618. SERIAL_EOL;
  619. CONFIG_ECHO_START;
  620. if (!forReplay) {
  621. SERIAL_ECHOLNPGM("Accelerations: P=printing, R=retract and T=travel");
  622. CONFIG_ECHO_START;
  623. }
  624. SERIAL_ECHOPAIR(" M204 P", planner.acceleration);
  625. SERIAL_ECHOPAIR(" R", planner.retract_acceleration);
  626. SERIAL_ECHOPAIR(" T", planner.travel_acceleration);
  627. SERIAL_EOL;
  628. CONFIG_ECHO_START;
  629. if (!forReplay) {
  630. 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)");
  631. CONFIG_ECHO_START;
  632. }
  633. SERIAL_ECHOPAIR(" M205 S", planner.min_feedrate);
  634. SERIAL_ECHOPAIR(" T", planner.min_travel_feedrate);
  635. SERIAL_ECHOPAIR(" B", planner.min_segment_time);
  636. SERIAL_ECHOPAIR(" X", planner.max_xy_jerk);
  637. SERIAL_ECHOPAIR(" Z", planner.max_z_jerk);
  638. SERIAL_ECHOPAIR(" E", planner.max_e_jerk);
  639. SERIAL_EOL;
  640. CONFIG_ECHO_START;
  641. if (!forReplay) {
  642. SERIAL_ECHOLNPGM("Home offset (mm):");
  643. CONFIG_ECHO_START;
  644. }
  645. SERIAL_ECHOPAIR(" M206 X", home_offset[X_AXIS]);
  646. SERIAL_ECHOPAIR(" Y", home_offset[Y_AXIS]);
  647. SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
  648. SERIAL_EOL;
  649. #if ENABLED(MESH_BED_LEVELING)
  650. if (!forReplay) {
  651. SERIAL_ECHOLNPGM("Mesh bed leveling:");
  652. CONFIG_ECHO_START;
  653. }
  654. SERIAL_ECHOPAIR(" M420 S", mbl.has_mesh() ? 1 : 0);
  655. SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
  656. SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
  657. SERIAL_EOL;
  658. for (uint8_t py = 1; py <= MESH_NUM_Y_POINTS; py++) {
  659. for (uint8_t px = 1; px <= MESH_NUM_X_POINTS; px++) {
  660. CONFIG_ECHO_START;
  661. SERIAL_ECHOPAIR(" G29 S3 X", px);
  662. SERIAL_ECHOPAIR(" Y", py);
  663. SERIAL_ECHOPGM(" Z");
  664. SERIAL_PROTOCOL_F(mbl.z_values[py-1][px-1], 5);
  665. SERIAL_EOL;
  666. }
  667. }
  668. #endif
  669. #if ENABLED(DELTA)
  670. CONFIG_ECHO_START;
  671. if (!forReplay) {
  672. SERIAL_ECHOLNPGM("Endstop adjustment (mm):");
  673. CONFIG_ECHO_START;
  674. }
  675. SERIAL_ECHOPAIR(" M666 X", endstop_adj[X_AXIS]);
  676. SERIAL_ECHOPAIR(" Y", endstop_adj[Y_AXIS]);
  677. SERIAL_ECHOPAIR(" Z", endstop_adj[Z_AXIS]);
  678. SERIAL_EOL;
  679. CONFIG_ECHO_START;
  680. if (!forReplay) {
  681. SERIAL_ECHOLNPGM("Delta settings: L=diagonal_rod, R=radius, S=segments_per_second, ABC=diagonal_rod_trim_tower_[123]");
  682. CONFIG_ECHO_START;
  683. }
  684. SERIAL_ECHOPAIR(" M665 L", delta_diagonal_rod);
  685. SERIAL_ECHOPAIR(" R", delta_radius);
  686. SERIAL_ECHOPAIR(" S", delta_segments_per_second);
  687. SERIAL_ECHOPAIR(" A", delta_diagonal_rod_trim_tower_1);
  688. SERIAL_ECHOPAIR(" B", delta_diagonal_rod_trim_tower_2);
  689. SERIAL_ECHOPAIR(" C", delta_diagonal_rod_trim_tower_3);
  690. SERIAL_EOL;
  691. #elif ENABLED(Z_DUAL_ENDSTOPS)
  692. CONFIG_ECHO_START;
  693. if (!forReplay) {
  694. SERIAL_ECHOLNPGM("Z2 Endstop adjustment (mm):");
  695. CONFIG_ECHO_START;
  696. }
  697. SERIAL_ECHOPAIR(" M666 Z", z_endstop_adj);
  698. SERIAL_EOL;
  699. #endif // DELTA
  700. #if ENABLED(ULTIPANEL)
  701. CONFIG_ECHO_START;
  702. if (!forReplay) {
  703. SERIAL_ECHOLNPGM("Material heatup parameters:");
  704. CONFIG_ECHO_START;
  705. }
  706. SERIAL_ECHOPAIR(" M145 S0 H", plaPreheatHotendTemp);
  707. SERIAL_ECHOPAIR(" B", plaPreheatHPBTemp);
  708. SERIAL_ECHOPAIR(" F", plaPreheatFanSpeed);
  709. SERIAL_EOL;
  710. CONFIG_ECHO_START;
  711. SERIAL_ECHOPAIR(" M145 S1 H", absPreheatHotendTemp);
  712. SERIAL_ECHOPAIR(" B", absPreheatHPBTemp);
  713. SERIAL_ECHOPAIR(" F", absPreheatFanSpeed);
  714. SERIAL_EOL;
  715. #endif // ULTIPANEL
  716. #if HAS_PID_HEATING
  717. CONFIG_ECHO_START;
  718. if (!forReplay) {
  719. SERIAL_ECHOLNPGM("PID settings:");
  720. }
  721. #if ENABLED(PIDTEMP)
  722. #if HOTENDS > 1
  723. if (forReplay) {
  724. for (uint8_t i = 0; i < HOTENDS; i++) {
  725. CONFIG_ECHO_START;
  726. SERIAL_ECHOPAIR(" M301 E", i);
  727. SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, i));
  728. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, i)));
  729. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, i)));
  730. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  731. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, i));
  732. if (i == 0) SERIAL_ECHOPAIR(" L", lpq_len);
  733. #endif
  734. SERIAL_EOL;
  735. }
  736. }
  737. else
  738. #endif // HOTENDS > 1
  739. // !forReplay || HOTENDS == 1
  740. {
  741. CONFIG_ECHO_START;
  742. SERIAL_ECHOPAIR(" M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echo values for E0
  743. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
  744. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
  745. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  746. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, 0));
  747. SERIAL_ECHOPAIR(" L", lpq_len);
  748. #endif
  749. SERIAL_EOL;
  750. }
  751. #endif // PIDTEMP
  752. #if ENABLED(PIDTEMPBED)
  753. CONFIG_ECHO_START;
  754. SERIAL_ECHOPAIR(" M304 P", thermalManager.bedKp);
  755. SERIAL_ECHOPAIR(" I", unscalePID_i(thermalManager.bedKi));
  756. SERIAL_ECHOPAIR(" D", unscalePID_d(thermalManager.bedKd));
  757. SERIAL_EOL;
  758. #endif
  759. #endif // PIDTEMP || PIDTEMPBED
  760. #if HAS_LCD_CONTRAST
  761. CONFIG_ECHO_START;
  762. if (!forReplay) {
  763. SERIAL_ECHOLNPGM("LCD Contrast:");
  764. CONFIG_ECHO_START;
  765. }
  766. SERIAL_ECHOPAIR(" M250 C", lcd_contrast);
  767. SERIAL_EOL;
  768. #endif
  769. #if ENABLED(FWRETRACT)
  770. CONFIG_ECHO_START;
  771. if (!forReplay) {
  772. SERIAL_ECHOLNPGM("Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)");
  773. CONFIG_ECHO_START;
  774. }
  775. SERIAL_ECHOPAIR(" M207 S", retract_length);
  776. #if EXTRUDERS > 1
  777. SERIAL_ECHOPAIR(" W", retract_length_swap);
  778. #endif
  779. SERIAL_ECHOPAIR(" F", retract_feedrate_mm_s * 60);
  780. SERIAL_ECHOPAIR(" Z", retract_zlift);
  781. SERIAL_EOL;
  782. CONFIG_ECHO_START;
  783. if (!forReplay) {
  784. SERIAL_ECHOLNPGM("Recover: S=Extra length (mm) F:Speed (mm/m)");
  785. CONFIG_ECHO_START;
  786. }
  787. SERIAL_ECHOPAIR(" M208 S", retract_recover_length);
  788. #if EXTRUDERS > 1
  789. SERIAL_ECHOPAIR(" W", retract_recover_length_swap);
  790. #endif
  791. SERIAL_ECHOPAIR(" F", retract_recover_feedrate * 60);
  792. SERIAL_EOL;
  793. CONFIG_ECHO_START;
  794. if (!forReplay) {
  795. SERIAL_ECHOLNPGM("Auto-Retract: S=0 to disable, 1 to interpret extrude-only moves as retracts or recoveries");
  796. CONFIG_ECHO_START;
  797. }
  798. SERIAL_ECHOPAIR(" M209 S", (autoretract_enabled ? 1 : 0));
  799. SERIAL_EOL;
  800. #endif // FWRETRACT
  801. /**
  802. * Volumetric extrusion M200
  803. */
  804. if (!forReplay) {
  805. CONFIG_ECHO_START;
  806. SERIAL_ECHOPGM("Filament settings:");
  807. if (volumetric_enabled)
  808. SERIAL_EOL;
  809. else
  810. SERIAL_ECHOLNPGM(" Disabled");
  811. }
  812. CONFIG_ECHO_START;
  813. SERIAL_ECHOPAIR(" M200 D", filament_size[0]);
  814. SERIAL_EOL;
  815. #if EXTRUDERS > 1
  816. CONFIG_ECHO_START;
  817. SERIAL_ECHOPAIR(" M200 T1 D", filament_size[1]);
  818. SERIAL_EOL;
  819. #if EXTRUDERS > 2
  820. CONFIG_ECHO_START;
  821. SERIAL_ECHOPAIR(" M200 T2 D", filament_size[2]);
  822. SERIAL_EOL;
  823. #if EXTRUDERS > 3
  824. CONFIG_ECHO_START;
  825. SERIAL_ECHOPAIR(" M200 T3 D", filament_size[3]);
  826. SERIAL_EOL;
  827. #endif
  828. #endif
  829. #endif
  830. if (!volumetric_enabled) {
  831. CONFIG_ECHO_START;
  832. SERIAL_ECHOLNPGM(" M200 D0");
  833. }
  834. /**
  835. * Auto Bed Leveling
  836. */
  837. #if HAS_BED_PROBE
  838. if (!forReplay) {
  839. CONFIG_ECHO_START;
  840. SERIAL_ECHOLNPGM("Z-Probe Offset (mm):");
  841. }
  842. CONFIG_ECHO_START;
  843. SERIAL_ECHOPAIR(" M851 Z", zprobe_zoffset);
  844. SERIAL_EOL;
  845. #endif
  846. }
  847. #endif // !DISABLE_M503