2012-06-02 20:44:17 +02:00
|
|
|
#ifndef EEPROM_H
|
|
|
|
#define EEPROM_H
|
2011-11-06 19:23:08 +01:00
|
|
|
|
|
|
|
#include "Marlin.h"
|
2011-11-04 18:02:56 +01:00
|
|
|
#include "planner.h"
|
|
|
|
#include "temperature.h"
|
2011-12-22 14:55:45 +01:00
|
|
|
//#include <EEPROM.h>
|
|
|
|
|
2011-11-04 18:02:56 +01:00
|
|
|
template <class T> int EEPROM_writeAnything(int &ee, const T& value)
|
|
|
|
{
|
2011-11-06 19:23:08 +01:00
|
|
|
const byte* p = (const byte*)(const void*)&value;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < (int)sizeof(value); i++)
|
2011-12-22 14:55:45 +01:00
|
|
|
eeprom_write_byte((unsigned char *)ee++, *p++);
|
2011-11-06 19:23:08 +01:00
|
|
|
return i;
|
2011-11-04 18:02:56 +01:00
|
|
|
}
|
2011-11-06 19:23:08 +01:00
|
|
|
|
2011-11-04 18:02:56 +01:00
|
|
|
template <class T> int EEPROM_readAnything(int &ee, T& value)
|
|
|
|
{
|
2011-11-06 19:23:08 +01:00
|
|
|
byte* p = (byte*)(void*)&value;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < (int)sizeof(value); i++)
|
2011-12-22 14:55:45 +01:00
|
|
|
*p++ = eeprom_read_byte((unsigned char *)ee++);
|
2011-11-06 19:23:08 +01:00
|
|
|
return i;
|
2011-11-04 18:02:56 +01:00
|
|
|
}
|
|
|
|
//======================================================================================
|
|
|
|
|
2011-11-09 20:27:15 +01:00
|
|
|
|
2011-11-07 22:33:13 +01:00
|
|
|
|
|
|
|
|
2011-11-04 18:02:56 +01:00
|
|
|
#define EEPROM_OFFSET 100
|
|
|
|
|
2011-11-06 19:23:08 +01:00
|
|
|
|
|
|
|
// IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
|
|
|
|
// in the functions below, also increment the version number. This makes sure that
|
|
|
|
// the default values are used whenever there is a change to the data, to prevent
|
|
|
|
// wrong data being written to the variables.
|
|
|
|
// ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
|
2012-08-22 00:46:10 +02:00
|
|
|
#define EEPROM_VERSION "V07"
|
2011-11-06 19:23:08 +01:00
|
|
|
|
2011-12-04 22:26:42 +01:00
|
|
|
inline void EEPROM_StoreSettings()
|
2011-11-06 19:23:08 +01:00
|
|
|
{
|
2011-11-09 20:27:15 +01:00
|
|
|
#ifdef EEPROM_SETTINGS
|
2011-11-04 18:02:56 +01:00
|
|
|
char ver[4]= "000";
|
|
|
|
int i=EEPROM_OFFSET;
|
|
|
|
EEPROM_writeAnything(i,ver); // invalidate data first
|
|
|
|
EEPROM_writeAnything(i,axis_steps_per_unit);
|
|
|
|
EEPROM_writeAnything(i,max_feedrate);
|
|
|
|
EEPROM_writeAnything(i,max_acceleration_units_per_sq_second);
|
|
|
|
EEPROM_writeAnything(i,acceleration);
|
|
|
|
EEPROM_writeAnything(i,retract_acceleration);
|
|
|
|
EEPROM_writeAnything(i,minimumfeedrate);
|
|
|
|
EEPROM_writeAnything(i,mintravelfeedrate);
|
|
|
|
EEPROM_writeAnything(i,minsegmenttime);
|
|
|
|
EEPROM_writeAnything(i,max_xy_jerk);
|
|
|
|
EEPROM_writeAnything(i,max_z_jerk);
|
2012-03-04 16:34:58 +01:00
|
|
|
EEPROM_writeAnything(i,max_e_jerk);
|
2012-08-01 22:18:08 +02:00
|
|
|
EEPROM_writeAnything(i,add_homeing);
|
2012-08-22 00:46:10 +02:00
|
|
|
EEPROM_writeAnything(i,plaPreheatHotendTemp);
|
|
|
|
EEPROM_writeAnything(i,plaPreheatHPBTemp);
|
|
|
|
EEPROM_writeAnything(i,plaPreheatFanSpeed);
|
|
|
|
EEPROM_writeAnything(i,absPreheatHotendTemp);
|
|
|
|
EEPROM_writeAnything(i,absPreheatHPBTemp);
|
|
|
|
EEPROM_writeAnything(i,absPreheatFanSpeed);
|
2011-11-04 18:02:56 +01:00
|
|
|
#ifdef PIDTEMP
|
2011-11-06 19:23:08 +01:00
|
|
|
EEPROM_writeAnything(i,Kp);
|
|
|
|
EEPROM_writeAnything(i,Ki);
|
|
|
|
EEPROM_writeAnything(i,Kd);
|
|
|
|
#else
|
|
|
|
EEPROM_writeAnything(i,3000);
|
|
|
|
EEPROM_writeAnything(i,0);
|
|
|
|
EEPROM_writeAnything(i,0);
|
|
|
|
#endif
|
2011-11-04 18:02:56 +01:00
|
|
|
char ver2[4]=EEPROM_VERSION;
|
|
|
|
i=EEPROM_OFFSET;
|
|
|
|
EEPROM_writeAnything(i,ver2); // validate data
|
2011-11-09 20:27:15 +01:00
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("Settings Stored");
|
|
|
|
#endif //EEPROM_SETTINGS
|
2011-11-04 18:02:56 +01:00
|
|
|
}
|
|
|
|
|
2011-12-04 22:26:42 +01:00
|
|
|
|
|
|
|
inline void EEPROM_printSettings()
|
|
|
|
{ // if def=true, the default values will be used
|
2012-08-11 15:49:40 +02:00
|
|
|
// #ifdef EEPROM_SETTINGS
|
2011-12-04 22:26:42 +01:00
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("Steps per unit:");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOPAIR(" M92 X",axis_steps_per_unit[0]);
|
|
|
|
SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[1]);
|
|
|
|
SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[2]);
|
|
|
|
SERIAL_ECHOPAIR(" E",axis_steps_per_unit[3]);
|
|
|
|
SERIAL_ECHOLN("");
|
|
|
|
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOPAIR(" M203 X",max_feedrate[0]);
|
|
|
|
SERIAL_ECHOPAIR(" Y",max_feedrate[1] );
|
|
|
|
SERIAL_ECHOPAIR(" Z", max_feedrate[2] );
|
|
|
|
SERIAL_ECHOPAIR(" E", max_feedrate[3]);
|
|
|
|
SERIAL_ECHOLN("");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOPAIR(" M201 X" ,max_acceleration_units_per_sq_second[0] );
|
|
|
|
SERIAL_ECHOPAIR(" Y" , max_acceleration_units_per_sq_second[1] );
|
|
|
|
SERIAL_ECHOPAIR(" Z" ,max_acceleration_units_per_sq_second[2] );
|
|
|
|
SERIAL_ECHOPAIR(" E" ,max_acceleration_units_per_sq_second[3]);
|
|
|
|
SERIAL_ECHOLN("");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("Acceleration: S=acceleration, T=retract acceleration");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOPAIR(" M204 S",acceleration );
|
|
|
|
SERIAL_ECHOPAIR(" T" ,retract_acceleration);
|
|
|
|
SERIAL_ECHOLN("");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
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)");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOPAIR(" M205 S",minimumfeedrate );
|
|
|
|
SERIAL_ECHOPAIR(" T" ,mintravelfeedrate );
|
|
|
|
SERIAL_ECHOPAIR(" B" ,minsegmenttime );
|
|
|
|
SERIAL_ECHOPAIR(" X" ,max_xy_jerk );
|
|
|
|
SERIAL_ECHOPAIR(" Z" ,max_z_jerk);
|
2012-03-04 16:34:58 +01:00
|
|
|
SERIAL_ECHOPAIR(" E" ,max_e_jerk);
|
2011-12-04 22:26:42 +01:00
|
|
|
SERIAL_ECHOLN("");
|
2012-08-01 22:18:08 +02:00
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("Home offset (mm):");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOPAIR(" M206 X",add_homeing[0] );
|
|
|
|
SERIAL_ECHOPAIR(" Y" ,add_homeing[1] );
|
|
|
|
SERIAL_ECHOPAIR(" Z" ,add_homeing[2] );
|
|
|
|
SERIAL_ECHOLN("");
|
2011-12-04 22:26:42 +01:00
|
|
|
#ifdef PIDTEMP
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("PID settings:");
|
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOPAIR(" M301 P",Kp);
|
|
|
|
SERIAL_ECHOPAIR(" I" ,Ki/PID_dT);
|
|
|
|
SERIAL_ECHOPAIR(" D" ,Kd*PID_dT);
|
|
|
|
SERIAL_ECHOLN("");
|
|
|
|
#endif
|
2012-08-11 15:49:40 +02:00
|
|
|
// #endif
|
2011-12-04 22:26:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void EEPROM_RetrieveSettings(bool def=false)
|
2011-11-06 19:23:08 +01:00
|
|
|
{ // if def=true, the default values will be used
|
2011-11-09 20:27:15 +01:00
|
|
|
#ifdef EEPROM_SETTINGS
|
|
|
|
int i=EEPROM_OFFSET;
|
|
|
|
char stored_ver[4];
|
|
|
|
char ver[4]=EEPROM_VERSION;
|
|
|
|
EEPROM_readAnything(i,stored_ver); //read stored version
|
|
|
|
// SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
|
|
|
|
if ((!def)&&(strncmp(ver,stored_ver,3)==0))
|
|
|
|
{ // version number match
|
|
|
|
EEPROM_readAnything(i,axis_steps_per_unit);
|
|
|
|
EEPROM_readAnything(i,max_feedrate);
|
|
|
|
EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
|
|
|
|
EEPROM_readAnything(i,acceleration);
|
|
|
|
EEPROM_readAnything(i,retract_acceleration);
|
|
|
|
EEPROM_readAnything(i,minimumfeedrate);
|
|
|
|
EEPROM_readAnything(i,mintravelfeedrate);
|
|
|
|
EEPROM_readAnything(i,minsegmenttime);
|
|
|
|
EEPROM_readAnything(i,max_xy_jerk);
|
|
|
|
EEPROM_readAnything(i,max_z_jerk);
|
2012-03-04 16:34:58 +01:00
|
|
|
EEPROM_readAnything(i,max_e_jerk);
|
2012-08-01 22:18:08 +02:00
|
|
|
EEPROM_readAnything(i,add_homeing);
|
2012-08-22 00:46:10 +02:00
|
|
|
EEPROM_readAnything(i,plaPreheatHotendTemp);
|
|
|
|
EEPROM_readAnything(i,plaPreheatHPBTemp);
|
|
|
|
EEPROM_readAnything(i,plaPreheatFanSpeed);
|
|
|
|
EEPROM_readAnything(i,absPreheatHotendTemp);
|
|
|
|
EEPROM_readAnything(i,absPreheatHPBTemp);
|
|
|
|
EEPROM_readAnything(i,absPreheatFanSpeed);
|
2011-11-09 20:27:15 +01:00
|
|
|
#ifndef PIDTEMP
|
|
|
|
float Kp,Ki,Kd;
|
|
|
|
#endif
|
|
|
|
EEPROM_readAnything(i,Kp);
|
|
|
|
EEPROM_readAnything(i,Ki);
|
|
|
|
EEPROM_readAnything(i,Kd);
|
2011-11-04 18:02:56 +01:00
|
|
|
|
2011-11-09 20:27:15 +01:00
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLNPGM("Stored settings retreived:");
|
|
|
|
}
|
|
|
|
else
|
2011-11-25 20:07:30 +01:00
|
|
|
#endif
|
2011-11-06 19:23:08 +01:00
|
|
|
{
|
2011-11-09 20:27:15 +01:00
|
|
|
float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
|
|
|
|
float tmp2[]=DEFAULT_MAX_FEEDRATE;
|
|
|
|
long tmp3[]=DEFAULT_MAX_ACCELERATION;
|
|
|
|
for (short i=0;i<4;i++)
|
|
|
|
{
|
|
|
|
axis_steps_per_unit[i]=tmp1[i];
|
|
|
|
max_feedrate[i]=tmp2[i];
|
|
|
|
max_acceleration_units_per_sq_second[i]=tmp3[i];
|
|
|
|
}
|
|
|
|
acceleration=DEFAULT_ACCELERATION;
|
|
|
|
retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
|
|
|
|
minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
|
|
|
|
minsegmenttime=DEFAULT_MINSEGMENTTIME;
|
|
|
|
mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE;
|
|
|
|
max_xy_jerk=DEFAULT_XYJERK;
|
|
|
|
max_z_jerk=DEFAULT_ZJERK;
|
2012-03-04 16:34:58 +01:00
|
|
|
max_e_jerk=DEFAULT_EJERK;
|
2012-08-01 22:18:08 +02:00
|
|
|
add_homeing[0] = add_homeing[1] = add_homeing[2] = 0;
|
2011-11-09 20:27:15 +01:00
|
|
|
SERIAL_ECHO_START;
|
|
|
|
SERIAL_ECHOLN("Using Default settings:");
|
2012-08-22 00:46:10 +02:00
|
|
|
#ifdef ULTIPANEL
|
|
|
|
plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
|
|
|
|
plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
|
|
|
|
plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
|
|
|
|
absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
|
|
|
|
absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
|
|
|
|
absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
|
2012-11-06 15:21:00 +01:00
|
|
|
#endif
|
|
|
|
#ifdef PIDTEMP
|
|
|
|
Kp = DEFAULT_Kp;
|
|
|
|
Ki = DEFAULT_Ki;
|
|
|
|
Kd = DEFAULT_Kp;
|
|
|
|
#ifdef PID_ADD_EXTRUSION_RATE
|
|
|
|
Kc = DEFAULT_Kc;
|
|
|
|
#endif
|
2012-08-22 00:46:10 +02:00
|
|
|
#endif
|
2011-11-04 18:02:56 +01:00
|
|
|
}
|
2011-11-09 20:27:15 +01:00
|
|
|
#ifdef EEPROM_CHITCHAT
|
2011-12-04 22:26:42 +01:00
|
|
|
EEPROM_printSettings();
|
2011-11-06 19:23:08 +01:00
|
|
|
#endif
|
2011-11-04 18:02:56 +01:00
|
|
|
}
|
|
|
|
|
2011-11-05 20:03:38 +01:00
|
|
|
#endif
|
|
|
|
|
2011-11-04 18:02:56 +01:00
|
|
|
|