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.

ConfigurationStore.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. #include "Marlin.h"
  2. #include "planner.h"
  3. #include "temperature.h"
  4. #include "ultralcd.h"
  5. #include "ConfigurationStore.h"
  6. void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size)
  7. {
  8. do
  9. {
  10. eeprom_write_byte((unsigned char*)pos, *value);
  11. pos++;
  12. value++;
  13. }while(--size);
  14. }
  15. #define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value))
  16. void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size)
  17. {
  18. do
  19. {
  20. *value = eeprom_read_byte((unsigned char*)pos);
  21. pos++;
  22. value++;
  23. }while(--size);
  24. }
  25. #define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value))
  26. //======================================================================================
  27. #define EEPROM_OFFSET 100
  28. // IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
  29. // in the functions below, also increment the version number. This makes sure that
  30. // the default values are used whenever there is a change to the data, to prevent
  31. // wrong data being written to the variables.
  32. // ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
  33. #define EEPROM_VERSION "V10"
  34. #ifdef DELTA
  35. #undef EEPROM_VERSION
  36. #define EEPROM_VERSION "V11"
  37. #endif
  38. #ifdef SCARA
  39. #undef EEPROM_VERSION
  40. #define EEPROM_VERSION "V12"
  41. #endif
  42. #ifdef EEPROM_SETTINGS
  43. void Config_StoreSettings()
  44. {
  45. char ver[4]= "000";
  46. int i=EEPROM_OFFSET;
  47. EEPROM_WRITE_VAR(i,ver); // invalidate data first
  48. EEPROM_WRITE_VAR(i,axis_steps_per_unit);
  49. EEPROM_WRITE_VAR(i,max_feedrate);
  50. EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second);
  51. EEPROM_WRITE_VAR(i,acceleration);
  52. EEPROM_WRITE_VAR(i,retract_acceleration);
  53. EEPROM_WRITE_VAR(i,minimumfeedrate);
  54. EEPROM_WRITE_VAR(i,mintravelfeedrate);
  55. EEPROM_WRITE_VAR(i,minsegmenttime);
  56. EEPROM_WRITE_VAR(i,max_xy_jerk);
  57. EEPROM_WRITE_VAR(i,max_z_jerk);
  58. EEPROM_WRITE_VAR(i,max_e_jerk);
  59. EEPROM_WRITE_VAR(i,add_homing);
  60. #ifdef DELTA
  61. EEPROM_WRITE_VAR(i,endstop_adj);
  62. EEPROM_WRITE_VAR(i,delta_radius);
  63. EEPROM_WRITE_VAR(i,delta_diagonal_rod);
  64. EEPROM_WRITE_VAR(i,delta_segments_per_second);
  65. #endif
  66. #ifndef ULTIPANEL
  67. int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
  68. int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  69. #endif
  70. EEPROM_WRITE_VAR(i,plaPreheatHotendTemp);
  71. EEPROM_WRITE_VAR(i,plaPreheatHPBTemp);
  72. EEPROM_WRITE_VAR(i,plaPreheatFanSpeed);
  73. EEPROM_WRITE_VAR(i,absPreheatHotendTemp);
  74. EEPROM_WRITE_VAR(i,absPreheatHPBTemp);
  75. EEPROM_WRITE_VAR(i,absPreheatFanSpeed);
  76. EEPROM_WRITE_VAR(i,zprobe_zoffset);
  77. #ifdef PIDTEMP
  78. EEPROM_WRITE_VAR(i,Kp);
  79. EEPROM_WRITE_VAR(i,Ki);
  80. EEPROM_WRITE_VAR(i,Kd);
  81. #else
  82. float dummy = 3000.0f;
  83. EEPROM_WRITE_VAR(i,dummy);
  84. dummy = 0.0f;
  85. EEPROM_WRITE_VAR(i,dummy);
  86. EEPROM_WRITE_VAR(i,dummy);
  87. #endif
  88. #ifndef DOGLCD
  89. int lcd_contrast = 32;
  90. #endif
  91. EEPROM_WRITE_VAR(i,lcd_contrast);
  92. #ifdef SCARA
  93. EEPROM_WRITE_VAR(i,axis_scaling); // Add scaling for SCARA
  94. #endif
  95. char ver2[4]=EEPROM_VERSION;
  96. i=EEPROM_OFFSET;
  97. EEPROM_WRITE_VAR(i,ver2); // validate data
  98. SERIAL_ECHO_START;
  99. SERIAL_ECHOLNPGM("Settings Stored");
  100. }
  101. #endif //EEPROM_SETTINGS
  102. #ifndef DISABLE_M503
  103. void Config_PrintSettings()
  104. { // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown
  105. SERIAL_ECHO_START;
  106. SERIAL_ECHOLNPGM("Steps per unit:");
  107. SERIAL_ECHO_START;
  108. SERIAL_ECHOPAIR(" M92 X",axis_steps_per_unit[X_AXIS]);
  109. SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[Y_AXIS]);
  110. SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[Z_AXIS]);
  111. SERIAL_ECHOPAIR(" E",axis_steps_per_unit[E_AXIS]);
  112. SERIAL_ECHOLN("");
  113. SERIAL_ECHO_START;
  114. #ifdef SCARA
  115. SERIAL_ECHOLNPGM("Scaling factors:");
  116. SERIAL_ECHO_START;
  117. SERIAL_ECHOPAIR(" M365 X",axis_scaling[X_AXIS]);
  118. SERIAL_ECHOPAIR(" Y",axis_scaling[Y_AXIS]);
  119. SERIAL_ECHOPAIR(" Z",axis_scaling[Z_AXIS]);
  120. SERIAL_ECHOLN("");
  121. SERIAL_ECHO_START;
  122. #endif
  123. SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
  124. SERIAL_ECHO_START;
  125. SERIAL_ECHOPAIR(" M203 X", max_feedrate[X_AXIS]);
  126. SERIAL_ECHOPAIR(" Y", max_feedrate[Y_AXIS]);
  127. SERIAL_ECHOPAIR(" Z", max_feedrate[Z_AXIS]);
  128. SERIAL_ECHOPAIR(" E", max_feedrate[E_AXIS]);
  129. SERIAL_ECHOLN("");
  130. SERIAL_ECHO_START;
  131. SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
  132. SERIAL_ECHO_START;
  133. SERIAL_ECHOPAIR(" M201 X" ,max_acceleration_units_per_sq_second[X_AXIS] );
  134. SERIAL_ECHOPAIR(" Y" , max_acceleration_units_per_sq_second[Y_AXIS] );
  135. SERIAL_ECHOPAIR(" Z" ,max_acceleration_units_per_sq_second[Z_AXIS] );
  136. SERIAL_ECHOPAIR(" E" ,max_acceleration_units_per_sq_second[E_AXIS]);
  137. SERIAL_ECHOLN("");
  138. SERIAL_ECHO_START;
  139. SERIAL_ECHOLNPGM("Acceleration: S=acceleration, T=retract acceleration");
  140. SERIAL_ECHO_START;
  141. SERIAL_ECHOPAIR(" M204 S",acceleration );
  142. SERIAL_ECHOPAIR(" T" ,retract_acceleration);
  143. SERIAL_ECHOLN("");
  144. SERIAL_ECHO_START;
  145. 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)");
  146. SERIAL_ECHO_START;
  147. SERIAL_ECHOPAIR(" M205 S",minimumfeedrate );
  148. SERIAL_ECHOPAIR(" T" ,mintravelfeedrate );
  149. SERIAL_ECHOPAIR(" B" ,minsegmenttime );
  150. SERIAL_ECHOPAIR(" X" ,max_xy_jerk );
  151. SERIAL_ECHOPAIR(" Z" ,max_z_jerk);
  152. SERIAL_ECHOPAIR(" E" ,max_e_jerk);
  153. SERIAL_ECHOLN("");
  154. SERIAL_ECHO_START;
  155. SERIAL_ECHOLNPGM("Home offset (mm):");
  156. SERIAL_ECHO_START;
  157. SERIAL_ECHOPAIR(" M206 X",add_homing[X_AXIS] );
  158. SERIAL_ECHOPAIR(" Y" ,add_homing[Y_AXIS] );
  159. SERIAL_ECHOPAIR(" Z" ,add_homing[Z_AXIS] );
  160. SERIAL_ECHOLN("");
  161. #ifdef DELTA
  162. SERIAL_ECHO_START;
  163. SERIAL_ECHOLNPGM("Endstop adjustement (mm):");
  164. SERIAL_ECHO_START;
  165. SERIAL_ECHOPAIR(" M666 X",endstop_adj[X_AXIS] );
  166. SERIAL_ECHOPAIR(" Y" ,endstop_adj[Y_AXIS] );
  167. SERIAL_ECHOPAIR(" Z" ,endstop_adj[Z_AXIS] );
  168. SERIAL_ECHOLN("");
  169. SERIAL_ECHO_START;
  170. SERIAL_ECHOLNPGM("Delta settings: L=delta_diagonal_rod, R=delta_radius, S=delta_segments_per_second");
  171. SERIAL_ECHO_START;
  172. SERIAL_ECHOPAIR(" M665 L",delta_diagonal_rod );
  173. SERIAL_ECHOPAIR(" R" ,delta_radius );
  174. SERIAL_ECHOPAIR(" S" ,delta_segments_per_second );
  175. SERIAL_ECHOLN("");
  176. #endif
  177. #ifdef PIDTEMP
  178. SERIAL_ECHO_START;
  179. SERIAL_ECHOLNPGM("PID settings:");
  180. SERIAL_ECHO_START;
  181. SERIAL_ECHOPAIR(" M301 P",Kp);
  182. SERIAL_ECHOPAIR(" I" ,unscalePID_i(Ki));
  183. SERIAL_ECHOPAIR(" D" ,unscalePID_d(Kd));
  184. SERIAL_ECHOLN("");
  185. #endif
  186. #ifdef FWRETRACT
  187. SERIAL_ECHO_START;
  188. SERIAL_ECHOLNPGM("Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)");
  189. SERIAL_ECHO_START;
  190. SERIAL_ECHOPAIR(" M207 S",retract_length);
  191. SERIAL_ECHOPAIR(" F" ,retract_feedrate*60);
  192. SERIAL_ECHOPAIR(" Z" ,retract_zlift);
  193. SERIAL_ECHOLN("");
  194. SERIAL_ECHO_START;
  195. SERIAL_ECHOLNPGM("Recover: S=Extra length (mm) F:Speed (mm/m)");
  196. SERIAL_ECHO_START;
  197. SERIAL_ECHOPAIR(" M208 S",retract_recover_length);
  198. SERIAL_ECHOPAIR(" F" ,retract_recover_feedrate*60);
  199. SERIAL_ECHOLN("");
  200. #endif
  201. }
  202. #endif
  203. #ifdef EEPROM_SETTINGS
  204. void Config_RetrieveSettings()
  205. {
  206. int i=EEPROM_OFFSET;
  207. char stored_ver[4];
  208. char ver[4]=EEPROM_VERSION;
  209. EEPROM_READ_VAR(i,stored_ver); //read stored version
  210. // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
  211. if (strncmp(ver,stored_ver,3) == 0)
  212. {
  213. // version number match
  214. EEPROM_READ_VAR(i,axis_steps_per_unit);
  215. EEPROM_READ_VAR(i,max_feedrate);
  216. EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second);
  217. // 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)
  218. reset_acceleration_rates();
  219. EEPROM_READ_VAR(i,acceleration);
  220. EEPROM_READ_VAR(i,retract_acceleration);
  221. EEPROM_READ_VAR(i,minimumfeedrate);
  222. EEPROM_READ_VAR(i,mintravelfeedrate);
  223. EEPROM_READ_VAR(i,minsegmenttime);
  224. EEPROM_READ_VAR(i,max_xy_jerk);
  225. EEPROM_READ_VAR(i,max_z_jerk);
  226. EEPROM_READ_VAR(i,max_e_jerk);
  227. EEPROM_READ_VAR(i,add_homing);
  228. #ifdef DELTA
  229. EEPROM_READ_VAR(i,endstop_adj);
  230. EEPROM_READ_VAR(i,delta_radius);
  231. EEPROM_READ_VAR(i,delta_diagonal_rod);
  232. EEPROM_READ_VAR(i,delta_segments_per_second);
  233. #endif
  234. #ifndef ULTIPANEL
  235. int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed;
  236. int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed;
  237. #endif
  238. EEPROM_READ_VAR(i,plaPreheatHotendTemp);
  239. EEPROM_READ_VAR(i,plaPreheatHPBTemp);
  240. EEPROM_READ_VAR(i,plaPreheatFanSpeed);
  241. EEPROM_READ_VAR(i,absPreheatHotendTemp);
  242. EEPROM_READ_VAR(i,absPreheatHPBTemp);
  243. EEPROM_READ_VAR(i,absPreheatFanSpeed);
  244. EEPROM_READ_VAR(i,zprobe_zoffset);
  245. #ifndef PIDTEMP
  246. float Kp,Ki,Kd;
  247. #endif
  248. // do not need to scale PID values as the values in EEPROM are already scaled
  249. EEPROM_READ_VAR(i,Kp);
  250. EEPROM_READ_VAR(i,Ki);
  251. EEPROM_READ_VAR(i,Kd);
  252. #ifndef DOGLCD
  253. int lcd_contrast;
  254. #endif
  255. EEPROM_READ_VAR(i,lcd_contrast);
  256. #ifdef SCARA
  257. EEPROM_READ_VAR(i,axis_scaling);
  258. #endif
  259. // Call updatePID (similar to when we have processed M301)
  260. updatePID();
  261. SERIAL_ECHO_START;
  262. SERIAL_ECHOLNPGM("Stored settings retrieved");
  263. }
  264. else
  265. {
  266. Config_ResetDefault();
  267. }
  268. #ifdef EEPROM_CHITCHAT
  269. Config_PrintSettings();
  270. #endif
  271. }
  272. #endif
  273. void Config_ResetDefault()
  274. {
  275. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  276. float tmp2[]=DEFAULT_MAX_FEEDRATE;
  277. long tmp3[]=DEFAULT_MAX_ACCELERATION;
  278. for (short i=0;i<4;i++)
  279. {
  280. axis_steps_per_unit[i]=tmp1[i];
  281. max_feedrate[i]=tmp2[i];
  282. max_acceleration_units_per_sq_second[i]=tmp3[i];
  283. #ifdef SCARA
  284. axis_scaling[i]=1;
  285. #endif
  286. }
  287. // steps per sq second need to be updated to agree with the units per sq second
  288. reset_acceleration_rates();
  289. acceleration=DEFAULT_ACCELERATION;
  290. retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
  291. minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
  292. minsegmenttime=DEFAULT_MINSEGMENTTIME;
  293. mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE;
  294. max_xy_jerk=DEFAULT_XYJERK;
  295. max_z_jerk=DEFAULT_ZJERK;
  296. max_e_jerk=DEFAULT_EJERK;
  297. add_homing[X_AXIS] = add_homing[Y_AXIS] = add_homing[Z_AXIS] = 0;
  298. #ifdef DELTA
  299. endstop_adj[X_AXIS] = endstop_adj[Y_AXIS] = endstop_adj[Z_AXIS] = 0;
  300. delta_radius= DELTA_RADIUS;
  301. delta_diagonal_rod= DELTA_DIAGONAL_ROD;
  302. delta_segments_per_second= DELTA_SEGMENTS_PER_SECOND;
  303. recalc_delta_settings(delta_radius, delta_diagonal_rod);
  304. #endif
  305. #ifdef ULTIPANEL
  306. plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
  307. plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
  308. plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
  309. absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
  310. absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
  311. absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  312. #endif
  313. #ifdef ENABLE_AUTO_BED_LEVELING
  314. zprobe_zoffset = -Z_PROBE_OFFSET_FROM_EXTRUDER;
  315. #endif
  316. #ifdef DOGLCD
  317. lcd_contrast = DEFAULT_LCD_CONTRAST;
  318. #endif
  319. #ifdef PIDTEMP
  320. Kp = DEFAULT_Kp;
  321. Ki = scalePID_i(DEFAULT_Ki);
  322. Kd = scalePID_d(DEFAULT_Kd);
  323. // call updatePID (similar to when we have processed M301)
  324. updatePID();
  325. #ifdef PID_ADD_EXTRUSION_RATE
  326. Kc = DEFAULT_Kc;
  327. #endif//PID_ADD_EXTRUSION_RATE
  328. #endif//PIDTEMP
  329. SERIAL_ECHO_START;
  330. SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
  331. }