My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

EEPROMwrite.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef __EEPROMH
  2. #define __EEPROMH
  3. #include "planner.h"
  4. #include "temperature.h"
  5. #include <EEPROM.h>
  6. #include "Marlin.h"
  7. #include "streaming.h"
  8. //======================================================================================
  9. template <class T> int EEPROM_writeAnything(int &ee, const T& value)
  10. {
  11. const byte* p = (const byte*)(const void*)&value;
  12. int i;
  13. for (i = 0; i < (int)sizeof(value); i++)
  14. EEPROM.write(ee++, *p++);
  15. return i;
  16. }
  17. //======================================================================================
  18. template <class T> int EEPROM_readAnything(int &ee, T& value)
  19. {
  20. byte* p = (byte*)(void*)&value;
  21. int i;
  22. for (i = 0; i < (int)sizeof(value); i++)
  23. *p++ = EEPROM.read(ee++);
  24. return i;
  25. }
  26. //======================================================================================
  27. #define EEPROM_OFFSET 100
  28. #define EEPROM_VERSION "V04" // 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. void StoreSettings() {
  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. #ifdef PIDTEMP
  48. EEPROM_writeAnything(i,Kp);
  49. EEPROM_writeAnything(i,Ki);
  50. EEPROM_writeAnything(i,Kd);
  51. #else
  52. EEPROM_writeAnything(i,3000);
  53. EEPROM_writeAnything(i,0);
  54. EEPROM_writeAnything(i,0);
  55. #endif
  56. char ver2[4]=EEPROM_VERSION;
  57. i=EEPROM_OFFSET;
  58. EEPROM_writeAnything(i,ver2); // validate data
  59. ECHOLN("Settings Stored");
  60. }
  61. void RetrieveSettings(bool def=false){ // if def=true, the default values will be used
  62. int i=EEPROM_OFFSET;
  63. char stored_ver[4];
  64. char ver[4]=EEPROM_VERSION;
  65. EEPROM_readAnything(i,stored_ver); //read stored version
  66. // ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
  67. if ((!def)&&(strncmp(ver,stored_ver,3)==0)) { // version number match
  68. EEPROM_readAnything(i,axis_steps_per_unit);
  69. EEPROM_readAnything(i,max_feedrate);
  70. EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
  71. EEPROM_readAnything(i,acceleration);
  72. EEPROM_readAnything(i,retract_acceleration);
  73. EEPROM_readAnything(i,minimumfeedrate);
  74. EEPROM_readAnything(i,mintravelfeedrate);
  75. EEPROM_readAnything(i,minsegmenttime);
  76. EEPROM_readAnything(i,max_xy_jerk);
  77. EEPROM_readAnything(i,max_z_jerk);
  78. #ifndef PIDTEMP
  79. float Kp,Ki,Kd;
  80. #endif
  81. EEPROM_readAnything(i,Kp);
  82. EEPROM_readAnything(i,Ki);
  83. EEPROM_readAnything(i,Kd);
  84. ECHOLN("Stored settings retreived:");
  85. }
  86. else {
  87. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  88. float tmp2[]=DEFAULT_MAX_FEEDRATE;
  89. long tmp3[]=DEFAULT_MAX_ACCELERATION;
  90. for (int i=0;i<4;i++) {
  91. axis_steps_per_unit[i]=tmp1[i];
  92. max_feedrate[i]=tmp2[i];
  93. max_acceleration_units_per_sq_second[i]=tmp3[i];
  94. }
  95. acceleration=DEFAULT_ACCELERATION;
  96. retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
  97. minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
  98. minsegmenttime=DEFAULT_MINSEGMENTTIME;
  99. mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE;
  100. max_xy_jerk=DEFAULT_XYJERK;
  101. max_z_jerk=DEFAULT_ZJERK;
  102. ECHOLN("Using Default settings:");
  103. }
  104. ECHOLN("Steps per unit:");
  105. ECHOLN(" M92 X" <<_FLOAT(axis_steps_per_unit[0],3) << " Y" << _FLOAT(axis_steps_per_unit[1],3) << " Z" << _FLOAT(axis_steps_per_unit[2],3) << " E" << _FLOAT(axis_steps_per_unit[3],3));
  106. ECHOLN("Maximum feedrates (mm/s):");
  107. ECHOLN(" M203 X" <<_FLOAT(max_feedrate[0]/60,2)<<" Y" << _FLOAT(max_feedrate[1]/60,2) << " Z" << _FLOAT(max_feedrate[2]/60,2) << " E" << _FLOAT(max_feedrate[3]/60,2));
  108. ECHOLN("Maximum Acceleration (mm/s2):");
  109. ECHOLN(" M201 X" <<_FLOAT(max_acceleration_units_per_sq_second[0],0) << " Y" << _FLOAT(max_acceleration_units_per_sq_second[1],0) << " Z" << _FLOAT(max_acceleration_units_per_sq_second[2],0) << " E" << _FLOAT(max_acceleration_units_per_sq_second[3],0));
  110. ECHOLN("Acceleration: S=acceleration, T=retract acceleration");
  111. ECHOLN(" M204 S" <<_FLOAT(acceleration,2) << " T" << _FLOAT(retract_acceleration,2));
  112. ECHOLN("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)");
  113. ECHOLN(" M205 S" <<_FLOAT(minimumfeedrate/60,2) << " T" << _FLOAT(mintravelfeedrate/60,2) << " B" << _FLOAT(minsegmenttime,2) << " X" << _FLOAT(max_xy_jerk/60,2) << " Z" << _FLOAT(max_z_jerk/60,2));
  114. #ifdef PIDTEMP
  115. ECHOLN("PID settings:");
  116. ECHOLN(" M301 P" << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));
  117. #endif
  118. }
  119. #endif