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

EEPROMwrite.h 6.7KB

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