My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

configuration_store.cpp 26KB

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