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

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