My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ConfigurationStore.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. #ifdef DELTA
  34. #define EEPROM_VERSION "V11"
  35. #else
  36. #define EEPROM_VERSION "V10"
  37. #endif
  38. #ifdef EEPROM_SETTINGS
  39. void Config_StoreSettings()
  40. {
  41. char ver[4]= "000";
  42. int i=EEPROM_OFFSET;
  43. EEPROM_WRITE_VAR(i,ver); // invalidate data first
  44. EEPROM_WRITE_VAR(i,axis_steps_per_unit);
  45. EEPROM_WRITE_VAR(i,max_feedrate);
  46. EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second);
  47. EEPROM_WRITE_VAR(i,acceleration);
  48. EEPROM_WRITE_VAR(i,retract_acceleration);
  49. EEPROM_WRITE_VAR(i,minimumfeedrate);
  50. EEPROM_WRITE_VAR(i,mintravelfeedrate);
  51. EEPROM_WRITE_VAR(i,minsegmenttime);
  52. EEPROM_WRITE_VAR(i,max_xy_jerk);
  53. EEPROM_WRITE_VAR(i,max_z_jerk);
  54. EEPROM_WRITE_VAR(i,max_e_jerk);
  55. EEPROM_WRITE_VAR(i,add_homeing);
  56. #ifdef DELTA
  57. EEPROM_WRITE_VAR(i,endstop_adj);
  58. EEPROM_WRITE_VAR(i,delta_radius);
  59. EEPROM_WRITE_VAR(i,delta_diagonal_rod);
  60. EEPROM_WRITE_VAR(i,delta_segments_per_second);
  61. #endif
  62. #ifndef ULTIPANEL
  63. int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
  64. int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  65. #endif
  66. EEPROM_WRITE_VAR(i,plaPreheatHotendTemp);
  67. EEPROM_WRITE_VAR(i,plaPreheatHPBTemp);
  68. EEPROM_WRITE_VAR(i,plaPreheatFanSpeed);
  69. EEPROM_WRITE_VAR(i,absPreheatHotendTemp);
  70. EEPROM_WRITE_VAR(i,absPreheatHPBTemp);
  71. EEPROM_WRITE_VAR(i,absPreheatFanSpeed);
  72. EEPROM_WRITE_VAR(i,zprobe_zoffset);
  73. #ifdef PIDTEMP
  74. EEPROM_WRITE_VAR(i,Kp);
  75. EEPROM_WRITE_VAR(i,Ki);
  76. EEPROM_WRITE_VAR(i,Kd);
  77. #else
  78. float dummy = 3000.0f;
  79. EEPROM_WRITE_VAR(i,dummy);
  80. dummy = 0.0f;
  81. EEPROM_WRITE_VAR(i,dummy);
  82. EEPROM_WRITE_VAR(i,dummy);
  83. #endif
  84. #ifndef DOGLCD
  85. int lcd_contrast = 32;
  86. #endif
  87. EEPROM_WRITE_VAR(i,lcd_contrast);
  88. char ver2[4]=EEPROM_VERSION;
  89. i=EEPROM_OFFSET;
  90. EEPROM_WRITE_VAR(i,ver2); // validate data
  91. SERIAL_ECHO_START;
  92. SERIAL_ECHOLNPGM("Settings Stored");
  93. }
  94. #endif //EEPROM_SETTINGS
  95. #ifndef DISABLE_M503
  96. void Config_PrintSettings()
  97. { // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown
  98. SERIAL_ECHO_START;
  99. SERIAL_ECHOLNPGM("Steps per unit:");
  100. SERIAL_ECHO_START;
  101. SERIAL_ECHOPAIR(" M92 X",axis_steps_per_unit[0]);
  102. SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[1]);
  103. SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[2]);
  104. SERIAL_ECHOPAIR(" E",axis_steps_per_unit[3]);
  105. SERIAL_ECHOLN("");
  106. SERIAL_ECHO_START;
  107. SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
  108. SERIAL_ECHO_START;
  109. SERIAL_ECHOPAIR(" M203 X",max_feedrate[0]);
  110. SERIAL_ECHOPAIR(" Y",max_feedrate[1] );
  111. SERIAL_ECHOPAIR(" Z", max_feedrate[2] );
  112. SERIAL_ECHOPAIR(" E", max_feedrate[3]);
  113. SERIAL_ECHOLN("");
  114. SERIAL_ECHO_START;
  115. SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
  116. SERIAL_ECHO_START;
  117. SERIAL_ECHOPAIR(" M201 X" ,max_acceleration_units_per_sq_second[0] );
  118. SERIAL_ECHOPAIR(" Y" , max_acceleration_units_per_sq_second[1] );
  119. SERIAL_ECHOPAIR(" Z" ,max_acceleration_units_per_sq_second[2] );
  120. SERIAL_ECHOPAIR(" E" ,max_acceleration_units_per_sq_second[3]);
  121. SERIAL_ECHOLN("");
  122. SERIAL_ECHO_START;
  123. SERIAL_ECHOLNPGM("Acceleration: S=acceleration, T=retract acceleration");
  124. SERIAL_ECHO_START;
  125. SERIAL_ECHOPAIR(" M204 S",acceleration );
  126. SERIAL_ECHOPAIR(" T" ,retract_acceleration);
  127. SERIAL_ECHOLN("");
  128. SERIAL_ECHO_START;
  129. 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)");
  130. SERIAL_ECHO_START;
  131. SERIAL_ECHOPAIR(" M205 S",minimumfeedrate );
  132. SERIAL_ECHOPAIR(" T" ,mintravelfeedrate );
  133. SERIAL_ECHOPAIR(" B" ,minsegmenttime );
  134. SERIAL_ECHOPAIR(" X" ,max_xy_jerk );
  135. SERIAL_ECHOPAIR(" Z" ,max_z_jerk);
  136. SERIAL_ECHOPAIR(" E" ,max_e_jerk);
  137. SERIAL_ECHOLN("");
  138. SERIAL_ECHO_START;
  139. SERIAL_ECHOLNPGM("Home offset (mm):");
  140. SERIAL_ECHO_START;
  141. SERIAL_ECHOPAIR(" M206 X",add_homeing[0] );
  142. SERIAL_ECHOPAIR(" Y" ,add_homeing[1] );
  143. SERIAL_ECHOPAIR(" Z" ,add_homeing[2] );
  144. SERIAL_ECHOLN("");
  145. #ifdef DELTA
  146. SERIAL_ECHO_START;
  147. SERIAL_ECHOLNPGM("Endstop adjustement (mm):");
  148. SERIAL_ECHO_START;
  149. SERIAL_ECHOPAIR(" M666 X",endstop_adj[0] );
  150. SERIAL_ECHOPAIR(" Y" ,endstop_adj[1] );
  151. SERIAL_ECHOPAIR(" Z" ,endstop_adj[2] );
  152. SERIAL_ECHOLN("");
  153. SERIAL_ECHO_START;
  154. SERIAL_ECHOLNPGM("Delta settings: L=delta_diagonal_rod, R=delta_radius, S=delta_segments_per_second");
  155. SERIAL_ECHO_START;
  156. SERIAL_ECHOPAIR(" M665 L",delta_diagonal_rod );
  157. SERIAL_ECHOPAIR(" R" ,delta_radius );
  158. SERIAL_ECHOPAIR(" S" ,delta_segments_per_second );
  159. SERIAL_ECHOLN("");
  160. #endif
  161. #ifdef PIDTEMP
  162. SERIAL_ECHO_START;
  163. SERIAL_ECHOLNPGM("PID settings:");
  164. SERIAL_ECHO_START;
  165. SERIAL_ECHOPAIR(" M301 P",Kp);
  166. SERIAL_ECHOPAIR(" I" ,unscalePID_i(Ki));
  167. SERIAL_ECHOPAIR(" D" ,unscalePID_d(Kd));
  168. SERIAL_ECHOLN("");
  169. #endif
  170. }
  171. #endif
  172. #ifdef EEPROM_SETTINGS
  173. void Config_RetrieveSettings()
  174. {
  175. int i=EEPROM_OFFSET;
  176. char stored_ver[4];
  177. char ver[4]=EEPROM_VERSION;
  178. EEPROM_READ_VAR(i,stored_ver); //read stored version
  179. // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
  180. if (strncmp(ver,stored_ver,3) == 0)
  181. {
  182. // version number match
  183. EEPROM_READ_VAR(i,axis_steps_per_unit);
  184. EEPROM_READ_VAR(i,max_feedrate);
  185. EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second);
  186. // 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)
  187. reset_acceleration_rates();
  188. EEPROM_READ_VAR(i,acceleration);
  189. EEPROM_READ_VAR(i,retract_acceleration);
  190. EEPROM_READ_VAR(i,minimumfeedrate);
  191. EEPROM_READ_VAR(i,mintravelfeedrate);
  192. EEPROM_READ_VAR(i,minsegmenttime);
  193. EEPROM_READ_VAR(i,max_xy_jerk);
  194. EEPROM_READ_VAR(i,max_z_jerk);
  195. EEPROM_READ_VAR(i,max_e_jerk);
  196. EEPROM_READ_VAR(i,add_homeing);
  197. #ifdef DELTA
  198. EEPROM_READ_VAR(i,endstop_adj);
  199. EEPROM_READ_VAR(i,delta_radius);
  200. EEPROM_READ_VAR(i,delta_diagonal_rod);
  201. EEPROM_READ_VAR(i,delta_segments_per_second);
  202. #endif
  203. #ifndef ULTIPANEL
  204. int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed;
  205. int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed;
  206. #endif
  207. EEPROM_READ_VAR(i,plaPreheatHotendTemp);
  208. EEPROM_READ_VAR(i,plaPreheatHPBTemp);
  209. EEPROM_READ_VAR(i,plaPreheatFanSpeed);
  210. EEPROM_READ_VAR(i,absPreheatHotendTemp);
  211. EEPROM_READ_VAR(i,absPreheatHPBTemp);
  212. EEPROM_READ_VAR(i,absPreheatFanSpeed);
  213. EEPROM_READ_VAR(i,zprobe_zoffset);
  214. #ifndef PIDTEMP
  215. float Kp,Ki,Kd;
  216. #endif
  217. // do not need to scale PID values as the values in EEPROM are already scaled
  218. EEPROM_READ_VAR(i,Kp);
  219. EEPROM_READ_VAR(i,Ki);
  220. EEPROM_READ_VAR(i,Kd);
  221. #ifndef DOGLCD
  222. int lcd_contrast;
  223. #endif
  224. EEPROM_READ_VAR(i,lcd_contrast);
  225. // Call updatePID (similar to when we have processed M301)
  226. updatePID();
  227. SERIAL_ECHO_START;
  228. SERIAL_ECHOLNPGM("Stored settings retrieved");
  229. }
  230. else
  231. {
  232. Config_ResetDefault();
  233. }
  234. #ifdef EEPROM_CHITCHAT
  235. Config_PrintSettings();
  236. #endif
  237. }
  238. #endif
  239. void Config_ResetDefault()
  240. {
  241. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  242. float tmp2[]=DEFAULT_MAX_FEEDRATE;
  243. long tmp3[]=DEFAULT_MAX_ACCELERATION;
  244. for (short i=0;i<4;i++)
  245. {
  246. axis_steps_per_unit[i]=tmp1[i];
  247. max_feedrate[i]=tmp2[i];
  248. max_acceleration_units_per_sq_second[i]=tmp3[i];
  249. }
  250. // steps per sq second need to be updated to agree with the units per sq second
  251. reset_acceleration_rates();
  252. acceleration=DEFAULT_ACCELERATION;
  253. retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
  254. minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
  255. minsegmenttime=DEFAULT_MINSEGMENTTIME;
  256. mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE;
  257. max_xy_jerk=DEFAULT_XYJERK;
  258. max_z_jerk=DEFAULT_ZJERK;
  259. max_e_jerk=DEFAULT_EJERK;
  260. add_homeing[0] = add_homeing[1] = add_homeing[2] = 0;
  261. #ifdef DELTA
  262. endstop_adj[0] = endstop_adj[1] = endstop_adj[2] = 0;
  263. delta_radius= DELTA_RADIUS;
  264. delta_diagonal_rod= DELTA_DIAGONAL_ROD;
  265. delta_segments_per_second= DELTA_SEGMENTS_PER_SECOND;
  266. recalc_delta_settings(delta_radius, delta_diagonal_rod);
  267. #endif
  268. #ifdef ULTIPANEL
  269. plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
  270. plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
  271. plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
  272. absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
  273. absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
  274. absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  275. #endif
  276. #ifdef ENABLE_AUTO_BED_LEVELING
  277. zprobe_zoffset = -Z_PROBE_OFFSET_FROM_EXTRUDER;
  278. #endif
  279. #ifdef DOGLCD
  280. lcd_contrast = DEFAULT_LCD_CONTRAST;
  281. #endif
  282. #ifdef PIDTEMP
  283. Kp = DEFAULT_Kp;
  284. Ki = scalePID_i(DEFAULT_Ki);
  285. Kd = scalePID_d(DEFAULT_Kd);
  286. // call updatePID (similar to when we have processed M301)
  287. updatePID();
  288. #ifdef PID_ADD_EXTRUSION_RATE
  289. Kc = DEFAULT_Kc;
  290. #endif//PID_ADD_EXTRUSION_RATE
  291. #endif//PIDTEMP
  292. SERIAL_ECHO_START;
  293. SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
  294. }