My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EEPROMwrite.h 6.1KB

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