My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

configuration_store.cpp 29KB

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