My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

EEPROMwrite.h 6.1KB

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