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 28KB

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