My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

configuration_store.cpp 29KB

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