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.

EEPROMwrite.h 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #ifndef EEPROM_H
  2. #define EEPROM_H
  3. #include "Marlin.h"
  4. #include "planner.h"
  5. #include "temperature.h"
  6. //#include <EEPROM.h>
  7. int plaPreheatHotendTemp;
  8. int plaPreheatHPBTemp;
  9. int plaPreheatFanSpeed;
  10. int absPreheatHotendTemp;
  11. int absPreheatHPBTemp;
  12. int absPreheatFanSpeed;
  13. template <class T> int EEPROM_writeAnything(int &ee, const T& value)
  14. {
  15. const byte* p = (const byte*)(const void*)&value;
  16. int i;
  17. for (i = 0; i < (int)sizeof(value); i++)
  18. eeprom_write_byte((unsigned char *)ee++, *p++);
  19. return i;
  20. }
  21. template <class T> int EEPROM_readAnything(int &ee, T& value)
  22. {
  23. byte* p = (byte*)(void*)&value;
  24. int i;
  25. for (i = 0; i < (int)sizeof(value); i++)
  26. *p++ = eeprom_read_byte((unsigned char *)ee++);
  27. return i;
  28. }
  29. //======================================================================================
  30. #define EEPROM_OFFSET 100
  31. // IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
  32. // in the functions below, also increment the version number. This makes sure that
  33. // the default values are used whenever there is a change to the data, to prevent
  34. // wrong data being written to the variables.
  35. // ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
  36. #define EEPROM_VERSION "V07"
  37. inline void EEPROM_StoreSettings()
  38. {
  39. #ifdef EEPROM_SETTINGS
  40. char ver[4]= "000";
  41. int i=EEPROM_OFFSET;
  42. EEPROM_writeAnything(i,ver); // invalidate data first
  43. EEPROM_writeAnything(i,axis_steps_per_unit);
  44. EEPROM_writeAnything(i,max_feedrate);
  45. EEPROM_writeAnything(i,max_acceleration_units_per_sq_second);
  46. EEPROM_writeAnything(i,acceleration);
  47. EEPROM_writeAnything(i,retract_acceleration);
  48. EEPROM_writeAnything(i,minimumfeedrate);
  49. EEPROM_writeAnything(i,mintravelfeedrate);
  50. EEPROM_writeAnything(i,minsegmenttime);
  51. EEPROM_writeAnything(i,max_xy_jerk);
  52. EEPROM_writeAnything(i,max_z_jerk);
  53. EEPROM_writeAnything(i,max_e_jerk);
  54. EEPROM_writeAnything(i,add_homeing);
  55. EEPROM_writeAnything(i,plaPreheatHotendTemp);
  56. EEPROM_writeAnything(i,plaPreheatHPBTemp);
  57. EEPROM_writeAnything(i,plaPreheatFanSpeed);
  58. EEPROM_writeAnything(i,absPreheatHotendTemp);
  59. EEPROM_writeAnything(i,absPreheatHPBTemp);
  60. EEPROM_writeAnything(i,absPreheatFanSpeed);
  61. #ifdef PIDTEMP
  62. EEPROM_writeAnything(i,Kp);
  63. EEPROM_writeAnything(i,Ki);
  64. EEPROM_writeAnything(i,Kd);
  65. #else
  66. EEPROM_writeAnything(i,3000);
  67. EEPROM_writeAnything(i,0);
  68. EEPROM_writeAnything(i,0);
  69. #endif
  70. char ver2[4]=EEPROM_VERSION;
  71. i=EEPROM_OFFSET;
  72. EEPROM_writeAnything(i,ver2); // validate data
  73. SERIAL_ECHO_START;
  74. SERIAL_ECHOLNPGM("Settings Stored");
  75. #endif //EEPROM_SETTINGS
  76. }
  77. inline void EEPROM_printSettings()
  78. { // if def=true, the default values will be used
  79. // #ifdef EEPROM_SETTINGS
  80. SERIAL_ECHO_START;
  81. SERIAL_ECHOLNPGM("Steps per unit:");
  82. SERIAL_ECHO_START;
  83. SERIAL_ECHOPAIR(" M92 X",axis_steps_per_unit[0]);
  84. SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[1]);
  85. SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[2]);
  86. SERIAL_ECHOPAIR(" E",axis_steps_per_unit[3]);
  87. SERIAL_ECHOLN("");
  88. SERIAL_ECHO_START;
  89. SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
  90. SERIAL_ECHO_START;
  91. SERIAL_ECHOPAIR(" M203 X",max_feedrate[0]);
  92. SERIAL_ECHOPAIR(" Y",max_feedrate[1] );
  93. SERIAL_ECHOPAIR(" Z", max_feedrate[2] );
  94. SERIAL_ECHOPAIR(" E", max_feedrate[3]);
  95. SERIAL_ECHOLN("");
  96. SERIAL_ECHO_START;
  97. SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
  98. SERIAL_ECHO_START;
  99. SERIAL_ECHOPAIR(" M201 X" ,max_acceleration_units_per_sq_second[0] );
  100. SERIAL_ECHOPAIR(" Y" , max_acceleration_units_per_sq_second[1] );
  101. SERIAL_ECHOPAIR(" Z" ,max_acceleration_units_per_sq_second[2] );
  102. SERIAL_ECHOPAIR(" E" ,max_acceleration_units_per_sq_second[3]);
  103. SERIAL_ECHOLN("");
  104. SERIAL_ECHO_START;
  105. SERIAL_ECHOLNPGM("Acceleration: S=acceleration, T=retract acceleration");
  106. SERIAL_ECHO_START;
  107. SERIAL_ECHOPAIR(" M204 S",acceleration );
  108. SERIAL_ECHOPAIR(" T" ,retract_acceleration);
  109. SERIAL_ECHOLN("");
  110. SERIAL_ECHO_START;
  111. 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)");
  112. SERIAL_ECHO_START;
  113. SERIAL_ECHOPAIR(" M205 S",minimumfeedrate );
  114. SERIAL_ECHOPAIR(" T" ,mintravelfeedrate );
  115. SERIAL_ECHOPAIR(" B" ,minsegmenttime );
  116. SERIAL_ECHOPAIR(" X" ,max_xy_jerk );
  117. SERIAL_ECHOPAIR(" Z" ,max_z_jerk);
  118. SERIAL_ECHOPAIR(" E" ,max_e_jerk);
  119. SERIAL_ECHOLN("");
  120. SERIAL_ECHO_START;
  121. SERIAL_ECHOLNPGM("Home offset (mm):");
  122. SERIAL_ECHO_START;
  123. SERIAL_ECHOPAIR(" M206 X",add_homeing[0] );
  124. SERIAL_ECHOPAIR(" Y" ,add_homeing[1] );
  125. SERIAL_ECHOPAIR(" Z" ,add_homeing[2] );
  126. SERIAL_ECHOLN("");
  127. #ifdef PIDTEMP
  128. SERIAL_ECHO_START;
  129. SERIAL_ECHOLNPGM("PID settings:");
  130. SERIAL_ECHO_START;
  131. SERIAL_ECHOPAIR(" M301 P",Kp);
  132. SERIAL_ECHOPAIR(" I" ,Ki/PID_dT);
  133. SERIAL_ECHOPAIR(" D" ,Kd*PID_dT);
  134. SERIAL_ECHOLN("");
  135. #endif
  136. // #endif
  137. }
  138. inline void EEPROM_RetrieveSettings(bool def=false)
  139. { // if def=true, the default values will be used
  140. #ifdef EEPROM_SETTINGS
  141. int i=EEPROM_OFFSET;
  142. char stored_ver[4];
  143. char ver[4]=EEPROM_VERSION;
  144. EEPROM_readAnything(i,stored_ver); //read stored version
  145. // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
  146. if ((!def)&&(strncmp(ver,stored_ver,3)==0))
  147. { // version number match
  148. EEPROM_readAnything(i,axis_steps_per_unit);
  149. EEPROM_readAnything(i,max_feedrate);
  150. EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
  151. EEPROM_readAnything(i,acceleration);
  152. EEPROM_readAnything(i,retract_acceleration);
  153. EEPROM_readAnything(i,minimumfeedrate);
  154. EEPROM_readAnything(i,mintravelfeedrate);
  155. EEPROM_readAnything(i,minsegmenttime);
  156. EEPROM_readAnything(i,max_xy_jerk);
  157. EEPROM_readAnything(i,max_z_jerk);
  158. EEPROM_readAnything(i,max_e_jerk);
  159. EEPROM_readAnything(i,add_homeing);
  160. EEPROM_readAnything(i,plaPreheatHotendTemp);
  161. EEPROM_readAnything(i,plaPreheatHPBTemp);
  162. EEPROM_readAnything(i,plaPreheatFanSpeed);
  163. EEPROM_readAnything(i,absPreheatHotendTemp);
  164. EEPROM_readAnything(i,absPreheatHPBTemp);
  165. EEPROM_readAnything(i,absPreheatFanSpeed);
  166. #ifndef PIDTEMP
  167. float Kp,Ki,Kd;
  168. #endif
  169. EEPROM_readAnything(i,Kp);
  170. EEPROM_readAnything(i,Ki);
  171. EEPROM_readAnything(i,Kd);
  172. SERIAL_ECHO_START;
  173. SERIAL_ECHOLNPGM("Stored settings retreived:");
  174. }
  175. else
  176. #endif
  177. {
  178. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  179. float tmp2[]=DEFAULT_MAX_FEEDRATE;
  180. long tmp3[]=DEFAULT_MAX_ACCELERATION;
  181. for (short i=0;i<4;i++)
  182. {
  183. axis_steps_per_unit[i]=tmp1[i];
  184. max_feedrate[i]=tmp2[i];
  185. max_acceleration_units_per_sq_second[i]=tmp3[i];
  186. }
  187. acceleration=DEFAULT_ACCELERATION;
  188. retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
  189. minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
  190. minsegmenttime=DEFAULT_MINSEGMENTTIME;
  191. mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE;
  192. max_xy_jerk=DEFAULT_XYJERK;
  193. max_z_jerk=DEFAULT_ZJERK;
  194. max_e_jerk=DEFAULT_EJERK;
  195. add_homeing[0] = add_homeing[1] = add_homeing[2] = 0;
  196. SERIAL_ECHO_START;
  197. SERIAL_ECHOLN("Using Default settings:");
  198. #ifdef ULTIPANEL
  199. plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
  200. plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
  201. plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
  202. absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
  203. absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
  204. absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
  205. #endif
  206. }
  207. #ifdef EEPROM_CHITCHAT
  208. EEPROM_printSettings();
  209. #endif
  210. }
  211. #endif