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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 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 "V04"
  31. void StoreSettings()
  32. {
  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_ECHOLN("Settings Stored");
  59. }
  60. void RetrieveSettings(bool def=false)
  61. { // 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. // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
  67. if ((!def)&&(strncmp(ver,stored_ver,3)==0))
  68. { // version number match
  69. EEPROM_readAnything(i,axis_steps_per_unit);
  70. EEPROM_readAnything(i,max_feedrate);
  71. EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
  72. EEPROM_readAnything(i,acceleration);
  73. EEPROM_readAnything(i,retract_acceleration);
  74. EEPROM_readAnything(i,minimumfeedrate);
  75. EEPROM_readAnything(i,mintravelfeedrate);
  76. EEPROM_readAnything(i,minsegmenttime);
  77. EEPROM_readAnything(i,max_xy_jerk);
  78. EEPROM_readAnything(i,max_z_jerk);
  79. #ifndef PIDTEMP
  80. float Kp,Ki,Kd;
  81. #endif
  82. EEPROM_readAnything(i,Kp);
  83. EEPROM_readAnything(i,Ki);
  84. EEPROM_readAnything(i,Kd);
  85. SERIAL_ECHOLN("Stored settings retreived:");
  86. }
  87. else
  88. {
  89. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  90. float tmp2[]=DEFAULT_MAX_FEEDRATE;
  91. long tmp3[]=DEFAULT_MAX_ACCELERATION;
  92. for (short i=0;i<4;i++)
  93. {
  94. axis_steps_per_unit[i]=tmp1[i];
  95. max_feedrate[i]=tmp2[i];
  96. max_acceleration_units_per_sq_second[i]=tmp3[i];
  97. }
  98. acceleration=DEFAULT_ACCELERATION;
  99. retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
  100. minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
  101. minsegmenttime=DEFAULT_MINSEGMENTTIME;
  102. mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE;
  103. max_xy_jerk=DEFAULT_XYJERK;
  104. max_z_jerk=DEFAULT_ZJERK;
  105. SERIAL_ECHOLN("Using Default settings:");
  106. }
  107. SERIAL_ECHOLN("Steps per unit:");
  108. SERIAL_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));
  109. SERIAL_ECHOLN("Maximum feedrates (mm/s):");
  110. SERIAL_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));
  111. SERIAL_ECHOLN("Maximum Acceleration (mm/s2):");
  112. SERIAL_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));
  113. SERIAL_ECHOLN("Acceleration: S=acceleration, T=retract acceleration");
  114. SERIAL_ECHOLN(" M204 S" <<_FLOAT(acceleration,2) << " T" << _FLOAT(retract_acceleration,2));
  115. SERIAL_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)");
  116. SERIAL_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));
  117. #ifdef PIDTEMP
  118. SERIAL_ECHOLN("PID settings:");
  119. SERIAL_ECHOLN(" M301 P" << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));
  120. #endif
  121. }
  122. #endif