2011-11-05 19:03:38 +00:00
|
|
|
#ifndef __EEPROMH
|
|
|
|
#define __EEPROMH
|
2011-11-06 18:23:08 +00:00
|
|
|
|
|
|
|
#include "Marlin.h"
|
2011-11-04 17:02:56 +00:00
|
|
|
#include "planner.h"
|
|
|
|
#include "temperature.h"
|
2011-11-05 19:03:38 +00:00
|
|
|
#include <EEPROM.h>
|
2011-11-04 17:02:56 +00:00
|
|
|
|
|
|
|
template <class T> int EEPROM_writeAnything(int &ee, const T& value)
|
|
|
|
{
|
2011-11-06 18:23:08 +00:00
|
|
|
const byte* p = (const byte*)(const void*)&value;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < (int)sizeof(value); i++)
|
|
|
|
EEPROM.write(ee++, *p++);
|
|
|
|
return i;
|
2011-11-04 17:02:56 +00:00
|
|
|
}
|
2011-11-06 18:23:08 +00:00
|
|
|
|
2011-11-04 17:02:56 +00:00
|
|
|
template <class T> int EEPROM_readAnything(int &ee, T& value)
|
|
|
|
{
|
2011-11-06 18:23:08 +00:00
|
|
|
byte* p = (byte*)(void*)&value;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < (int)sizeof(value); i++)
|
|
|
|
*p++ = EEPROM.read(ee++);
|
|
|
|
return i;
|
2011-11-04 17:02:56 +00:00
|
|
|
}
|
|
|
|
//======================================================================================
|
|
|
|
|
2011-11-07 21:33:13 +00:00
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
|
|
|
|
void serialprintPGM(const char *str)
|
|
|
|
{
|
|
|
|
char ch=pgm_read_byte(str);
|
|
|
|
while(ch)
|
|
|
|
{
|
|
|
|
Serial.print(ch);
|
|
|
|
ch=pgm_read_byte(++str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#define SerialprintPGM(x) serialprintPGM(PSTR(x))
|
|
|
|
|
2011-11-04 17:02:56 +00:00
|
|
|
#define EEPROM_OFFSET 100
|
|
|
|
|
2011-11-06 18:23:08 +00: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.
|
|
|
|
#define EEPROM_VERSION "V04"
|
|
|
|
|
|
|
|
void StoreSettings()
|
|
|
|
{
|
2011-11-04 17:02:56 +00: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);
|
|
|
|
#ifdef PIDTEMP
|
2011-11-06 18:23:08 +00: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 17:02:56 +00:00
|
|
|
char ver2[4]=EEPROM_VERSION;
|
|
|
|
i=EEPROM_OFFSET;
|
|
|
|
EEPROM_writeAnything(i,ver2); // validate data
|
2011-11-07 21:33:13 +00:00
|
|
|
SerialprintPGM("echo: Settings Stored\n");
|
2011-11-04 17:02:56 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:23:08 +00:00
|
|
|
void RetrieveSettings(bool def=false)
|
|
|
|
{ // if def=true, the default values will be used
|
2011-11-04 17:02:56 +00:00
|
|
|
int i=EEPROM_OFFSET;
|
|
|
|
char stored_ver[4];
|
|
|
|
char ver[4]=EEPROM_VERSION;
|
|
|
|
EEPROM_readAnything(i,stored_ver); //read stored version
|
2011-11-06 18:23:08 +00:00
|
|
|
// 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);
|
|
|
|
#ifndef PIDTEMP
|
2011-11-04 17:02:56 +00:00
|
|
|
float Kp,Ki,Kd;
|
2011-11-06 18:23:08 +00:00
|
|
|
#endif
|
|
|
|
EEPROM_readAnything(i,Kp);
|
|
|
|
EEPROM_readAnything(i,Ki);
|
|
|
|
EEPROM_readAnything(i,Kd);
|
2011-11-04 17:02:56 +00:00
|
|
|
|
2011-11-07 21:33:13 +00:00
|
|
|
SerialprintPGM("echo: Stored settings retreived:\n");
|
2011-11-04 17:02:56 +00:00
|
|
|
}
|
2011-11-06 18:23:08 +00:00
|
|
|
else
|
|
|
|
{
|
2011-11-04 17:02:56 +00:00
|
|
|
float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
|
|
|
|
float tmp2[]=DEFAULT_MAX_FEEDRATE;
|
|
|
|
long tmp3[]=DEFAULT_MAX_ACCELERATION;
|
2011-11-06 18:23:08 +00:00
|
|
|
for (short i=0;i<4;i++)
|
|
|
|
{
|
2011-11-04 17:02:56 +00:00
|
|
|
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;
|
2011-11-07 21:33:13 +00:00
|
|
|
SerialprintPGM("echo: Using Default settings:\n");
|
2011-11-04 17:02:56 +00:00
|
|
|
}
|
2011-11-07 21:33:13 +00:00
|
|
|
SerialprintPGM("echo: Steps per unit:\n M92 X");
|
|
|
|
Serial.print(axis_steps_per_unit[0]);
|
|
|
|
SerialprintPGM(" Y");
|
|
|
|
Serial.print(axis_steps_per_unit[1]);
|
|
|
|
SerialprintPGM(" Z");
|
|
|
|
Serial.print(axis_steps_per_unit[2]);
|
|
|
|
SerialprintPGM(" E");
|
|
|
|
Serial.print(axis_steps_per_unit[3]);
|
|
|
|
|
|
|
|
SerialprintPGM("\nMaximum feedrates (mm/s):\n M203 X" );
|
|
|
|
Serial.print(max_feedrate[0]/60);
|
|
|
|
SerialprintPGM(" Y" );
|
|
|
|
Serial.print(max_feedrate[1]/60 );
|
|
|
|
SerialprintPGM(" Z" );
|
|
|
|
Serial.print(max_feedrate[2]/60 );
|
|
|
|
SerialprintPGM(" E" );
|
|
|
|
Serial.print(max_feedrate[3]/60);
|
|
|
|
SerialprintPGM("\nMaximum Acceleration (mm/s2):\n M201 X" );
|
|
|
|
Serial.print(max_acceleration_units_per_sq_second[0] );
|
|
|
|
SerialprintPGM(" Y" );
|
|
|
|
Serial.print(max_acceleration_units_per_sq_second[1] );
|
|
|
|
SerialprintPGM(" Z" );
|
|
|
|
Serial.print(max_acceleration_units_per_sq_second[2] );
|
|
|
|
SerialprintPGM(" E" );
|
|
|
|
Serial.print(max_acceleration_units_per_sq_second[3]);
|
|
|
|
SerialprintPGM("\necho: Acceleration: S=acceleration, T=retract acceleration\n M204 S" );
|
|
|
|
Serial.print(acceleration );
|
|
|
|
SerialprintPGM(" T" );
|
|
|
|
Serial.print(retract_acceleration);
|
|
|
|
SerialprintPGM("\necho: 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)");
|
|
|
|
SerialprintPGM(" M205 S" );
|
|
|
|
Serial.print(minimumfeedrate/60 );
|
|
|
|
SerialprintPGM(" T" );
|
|
|
|
Serial.print(mintravelfeedrate/60 );
|
|
|
|
SerialprintPGM(" B" );
|
|
|
|
Serial.print(minsegmenttime );
|
|
|
|
SerialprintPGM(" X" );
|
|
|
|
Serial.print(max_xy_jerk/60 );
|
|
|
|
SerialprintPGM(" Z" );
|
|
|
|
Serial.print(max_z_jerk/60);
|
|
|
|
SerialprintPGM("\n" );
|
2011-11-06 18:23:08 +00:00
|
|
|
#ifdef PIDTEMP
|
2011-11-07 21:33:13 +00:00
|
|
|
SerialprintPGM("PID settings:");
|
|
|
|
SerialprintPGM(" M301 P" );
|
|
|
|
Serial.print(Kp );
|
|
|
|
SerialprintPGM(" I" );
|
|
|
|
Serial.print(Ki );
|
|
|
|
SerialprintPGM(" D" );
|
|
|
|
Serial.print(Kd);
|
2011-11-06 18:23:08 +00:00
|
|
|
#endif
|
2011-11-04 17:02:56 +00:00
|
|
|
}
|
|
|
|
|
2011-11-05 19:03:38 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-04 17:02:56 +00:00
|
|
|
|