EEPROM_writeAnything(i,max_xy_jerk);\r
EEPROM_writeAnything(i,max_z_jerk);\r
#ifdef PIDTEMP\r
- EEPROM_writeAnything(i,Kp);\r
- EEPROM_writeAnything(i,Ki);\r
- EEPROM_writeAnything(i,Kd);\r
+ EEPROM_writeAnything(i,Heater::Kp);\r
+ EEPROM_writeAnything(i,Heater::Ki);\r
+ EEPROM_writeAnything(i,Heater::Kd);\r
#else\r
EEPROM_writeAnything(i,3000);\r
EEPROM_writeAnything(i,0);\r
EEPROM_readAnything(i,max_xy_jerk);\r
EEPROM_readAnything(i,max_z_jerk);\r
#ifndef PIDTEMP\r
- float Kp,Ki,Kd;\r
+ float Kp,Ki,Kd; //read and ignore..\r
#endif\r
- EEPROM_readAnything(i,Kp);\r
- EEPROM_readAnything(i,Ki);\r
- EEPROM_readAnything(i,Kd);\r
+ EEPROM_readAnything(i,Heater::Kp);\r
+ EEPROM_readAnything(i,Heater::Ki);\r
+ EEPROM_readAnything(i,Heater::Kd);\r
\r
ECHOLN("Stored settings retreived:");\r
}\r
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));\r
#ifdef PIDTEMP\r
ECHOLN("PID settings:");\r
- ECHOLN(" M301 P" << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3)); \r
+ ECHOLN(" M301 P" << _FLOAT(Heater::Kp,3) << " I" << _FLOAT(Heater::Ki,3) << " D" << _FLOAT(Heater::Kd,3)); \r
#endif\r
\r
} \r
#define ECHO(x) Serial << "echo: " << x;\r
#define ECHOLN(x) Serial << "echo: "<<x<<endl;\r
\r
+\r
void get_command();\r
void process_commands();\r
\r
#include "Simplelcd.h"\r
#endif\r
\r
+Heater htr;\r
char version_string[] = "1.0.0 Alpha 1";\r
\r
#ifdef SDSUPPORT\r
#endif //SDSUPPORT\r
plan_init(); // Initialize planner;\r
st_init(); // Initialize stepper;\r
- tp_init(); // Initialize temperature loop\r
+ //tp_init(); // Initialize temperature loop is now done by the constructor of the Heater class\r
//checkautostart();\r
}\r
\r
bufindr = (bufindr + 1)%BUFSIZE;\r
}\r
//check heater every n milliseconds\r
- manage_heater();\r
+ Heater::manage_heater();\r
manage_inactivity(1);\r
LCD_STATUS;\r
}\r
if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait\r
codenum += millis(); // keep track of when we started waiting\r
while(millis() < codenum ){\r
- manage_heater();\r
+ Heater::manage_heater();\r
}\r
break;\r
case 28: //G28 Home all Axis one at a time\r
}\r
break;\r
case 104: // M104\r
- if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());\r
-#ifdef PIDTEMP\r
- pid_setpoint = code_value();\r
-#endif //PIDTEM\r
+ if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());\r
#ifdef WATCHPERIOD\r
- if(target_raw[TEMPSENSOR_HOTEND] > current_raw[TEMPSENSOR_HOTEND]){\r
+ if(Heater::isHeating(TEMPSENSOR_HOTEND)){\r
watchmillis = max(1,millis());\r
watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];\r
}else{\r
#endif\r
break;\r
case 140: // M140 set bed temp\r
- if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analogBed(code_value());\r
+ if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());\r
break;\r
case 105: // M105\r
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)\r
- tt = analog2temp(current_raw[TEMPSENSOR_HOTEND]);\r
+ tt = Heater::celsius(TEMPSENSOR_HOTEND);\r
#endif\r
#if TEMP_1_PIN > -1\r
- bt = analog2tempBed(current_raw[TEMPSENSOR_BED]);\r
+ bt = Heater::celsius(TEMPSENSOR_BED);\r
#endif\r
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)\r
Serial.print("ok T:");\r
#ifdef PIDTEMP\r
Serial.print(" B:");\r
#if TEMP_1_PIN > -1\r
- Serial.println(bt); \r
+ Serial.println(bt); \r
#else\r
- Serial.println(HeaterPower); \r
+ Serial.println(Heater::HeaterPower); \r
#endif\r
#else\r
Serial.println();\r
#endif\r
- #else\r
+ #else<\r
Serial.println();\r
#endif\r
#else\r
//break;\r
case 109: {// M109 - Wait for extruder heater to reach target.\r
LCD_MESSAGE("Heating...");\r
- if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());\r
- #ifdef PIDTEMP\r
- pid_setpoint = code_value();\r
- #endif //PIDTEM\r
+ if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());\r
+ \r
#ifdef WATCHPERIOD\r
- if(target_raw[TEMPSENSOR_HOTEND]>current_raw[TEMPSENSOR_HOTEND]){\r
+ if(Heater::isHeating(TEMPSENSOR_HOTEND)){\r
watchmillis = max(1,millis());\r
- watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];\r
+ watch_raw[TEMPSENSOR_HOTEND] = Heater::current_raw[TEMPSENSOR_HOTEND];\r
} else {\r
watchmillis = 0;\r
}\r
codenum = millis(); \r
\r
/* See if we are heating up or cooling down */\r
- bool target_direction = (current_raw[0] < target_raw[0]); // true if heating, false if cooling\r
+ bool target_direction = Heater::isHeating(TEMPSENSOR_HOTEND); // true if heating, false if cooling\r
\r
#ifdef TEMP_RESIDENCY_TIME\r
long residencyStart;\r
residencyStart = -1;\r
/* continue to loop until we have reached the target temp \r
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */\r
- while((target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0])) ||\r
+ while((target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND)) ||\r
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {\r
#else\r
- while ( target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0]) ) {\r
+ while ( target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND) ) {\r
#endif //TEMP_RESIDENCY_TIME\r
if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down\r
Serial.print("T:");\r
- Serial.println( analog2temp(current_raw[TEMPSENSOR_HOTEND]) ); \r
+ Serial.println( Heater::celsius(TEMPSENSOR_HOTEND) ); \r
codenum = millis();\r
}\r
- manage_heater();\r
+ Heater::manage_heater();\r
LCD_STATUS;\r
#ifdef TEMP_RESIDENCY_TIME\r
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time\r
or when current temp falls outside the hysteresis after target temp was reached */\r
- if ((residencyStart == -1 && target_direction && current_raw[0] >= target_raw[0]) ||\r
- (residencyStart == -1 && !target_direction && current_raw[0] <= target_raw[0]) ||\r
- (residencyStart > -1 && labs(analog2temp(current_raw[0]) - analog2temp(target_raw[0])) > TEMP_HYSTERESIS) ) {\r
+ if ((residencyStart == -1 && target_direction && !Heater::isHeating(TEMPSENSOR_HOTEND)) ||\r
+ (residencyStart == -1 && !target_direction && !Heater::isCooling(TEMPSENSOR_HOTEND)) ||\r
+ (residencyStart > -1 && labs(Heater::celsius(TEMPSENSOR_HOTEND) - Heater::celsiusTarget(TEMPSENSOR_HOTEND)) > TEMP_HYSTERESIS) ) {\r
residencyStart = millis();\r
}\r
#endif //TEMP_RESIDENCY_TIME\r
break;\r
case 190: // M190 - Wait bed for heater to reach target.\r
#if TEMP_1_PIN > -1\r
- if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analog(code_value());\r
+ if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());\r
codenum = millis(); \r
- while(current_raw[TEMPSENSOR_BED] < target_raw[TEMPSENSOR_BED]) \r
- {\r
+ while(Heater::isHeating(TEMPSENSOR_BED)) \r
+ {\r
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.\r
{\r
- float tt=analog2temp(current_raw[TEMPSENSOR_HOTEND]);\r
+ float tt=Heater::celsius(TEMPSENSOR_HOTEND);\r
Serial.print("T:");\r
Serial.println( tt );\r
Serial.print("ok T:");\r
Serial.print( tt ); \r
Serial.print(" B:");\r
- Serial.println( analog2temp(current_raw[TEMPSENSOR_BED]) ); \r
+ Serial.println( Heater::celsius(TEMPSENSOR_BED) ); \r
codenum = millis(); \r
}\r
- manage_heater();\r
+ Heater::manage_heater();\r
}\r
#endif\r
break;\r
break;\r
#ifdef PIDTEMP\r
case 301: // M301\r
- if(code_seen('P')) Kp = code_value();\r
- if(code_seen('I')) Ki = code_value()*PID_dT;\r
- if(code_seen('D')) Kd = code_value()/PID_dT;\r
+ if(code_seen('P')) Heater::Kp = code_value();\r
+ if(code_seen('I')) Heater::Ki = code_value()*PID_dT;\r
+ if(code_seen('D')) Heater::Kd = code_value()/PID_dT;\r
+ #ifdef PID_ADD_EXTRUSION_RATE\r
+ if(code_seen('C')) Heater::Kc = code_value();\r
+ #endif\r
+\r
// ECHOLN("Kp "<<_FLOAT(Kp,2));\r
// ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));\r
// ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));\r
inline void kill()\r
{\r
#if TEMP_0_PIN > -1\r
- target_raw[0]=0;\r
+ Heater::setCelsius(TEMPSENSOR_HOTEND,0);\r
#if HEATER_0_PIN > -1 \r
WRITE(HEATER_0_PIN,LOW);\r
#endif\r
#endif\r
#if TEMP_1_PIN > -1\r
- target_raw[1]=0;\r
+ Heater::setCelsius(TEMPSENSOR_BED,0);\r
#if HEATER_1_PIN > -1 \r
WRITE(HEATER_1_PIN,LOW);\r
#endif\r
#endif\r
#if TEMP_2_PIN > -1\r
- target_raw[2]=0;\r
+ Heater::setCelsius(TEMPSENSOR_AUX,0);\r
#if HEATER_2_PIN > -1 \r
WRITE(HEATER_2_PIN,LOW);\r
#endif\r
// If the buffer is full: good! That means we are well ahead of the robot. \r
// Rest here until there is room in the buffer.\r
while(block_buffer_tail == next_buffer_head) { \r
- manage_heater(); \r
+ htr.manage_heater(); \r
manage_inactivity(1); \r
LCD_STATUS;\r
}\r
void st_synchronize()\r
{\r
while(plan_get_current_block()) {\r
- manage_heater();\r
+ htr.manage_heater();\r
manage_inactivity(1);\r
LCD_STATUS;\r
} \r
#include "streaming.h"\r
#include "temperature.h"\r
\r
-int target_bed_raw = 0;\r
-int current_bed_raw = 0;\r
\r
-int target_raw[3] = {0, 0, 0};\r
-int current_raw[3] = {0, 0, 0};\r
-unsigned char temp_meas_ready = false;\r
\r
-unsigned long previous_millis_heater, previous_millis_bed_heater;\r
\r
-#ifdef PIDTEMP\r
- double temp_iState = 0;\r
- double temp_dState = 0;\r
- double pTerm;\r
- double iTerm;\r
- double dTerm;\r
- //int output;\r
- double pid_error;\r
- double temp_iState_min;\r
- double temp_iState_max;\r
- double pid_setpoint = 0.0;\r
- double pid_input;\r
- double pid_output;\r
- bool pid_reset;\r
- float HeaterPower;\r
- \r
- float Kp=DEFAULT_Kp;\r
- float Ki=DEFAULT_Ki;\r
- float Kd=DEFAULT_Kd;\r
- float Kc=DEFAULT_Kc;\r
-#endif //PIDTEMP\r
-\r
-#ifdef MINTEMP\r
-int minttemp = temp2analog(MINTEMP);\r
-#endif //MINTEMP\r
-#ifdef MAXTEMP\r
-int maxttemp = temp2analog(MAXTEMP);\r
-#endif //MAXTEMP\r
-\r
-#ifdef BED_MINTEMP\r
-int bed_minttemp = temp2analog(BED_MINTEMP);\r
-#endif //BED_MINTEMP\r
-#ifdef BED_MAXTEMP\r
-int bed_maxttemp = temp2analog(BED_MAXTEMP);\r
-#endif //BED_MAXTEMP\r
\r
-void manage_heater()\r
+void static Heater::manage_heater()\r
{\r
#ifdef USE_WATCHDOG\r
wd_reset();\r
\r
float pid_input;\r
float pid_output;\r
- if(temp_meas_ready != true) //better readability\r
+ if(htr.temp_meas_ready != true) //better readability\r
return; \r
\r
CRITICAL_SECTION_START;\r
- temp_meas_ready = false;\r
+ htr.temp_meas_ready = false;\r
CRITICAL_SECTION_END;\r
\r
#ifdef PIDTEMP\r
// For a thermistor, it uses the RepRap thermistor temp table.\r
// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.\r
// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.\r
-float temp2analog(int celsius) {\r
+float const static temp2analog(const int celsius)\r
+{\r
#ifdef HEATER_USES_THERMISTOR_1\r
int raw = 0;\r
byte i;\r
// For a thermistor, it uses the RepRap thermistor temp table.\r
// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.\r
// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.\r
-float temp2analogBed(int celsius) {\r
+float const static temp2analogBed(const int celsius)\r
+{\r
#ifdef BED_USES_THERMISTOR\r
\r
int raw = 0;\r
\r
// Derived from RepRap FiveD extruder::getTemperature()\r
// For hot end temperature measurement.\r
-float analog2temp(int raw) {\r
+float const static Heater::analog2temp(const int raw) {\r
#ifdef HEATER_1_USES_THERMISTOR\r
int celsius = 0;\r
byte i; \r
\r
// Derived from RepRap FiveD extruder::getTemperature()\r
// For bed temperature measurement.\r
-float analog2tempBed(int raw) {\r
+float const static Heater::analog2tempBed(const int raw) {\r
#ifdef BED_USES_THERMISTOR\r
int celsius = 0;\r
byte i;\r
#endif\r
}\r
\r
-void tp_init()\r
+Heater::Heater()\r
{\r
+ for(short i=0;i<3;i++)\r
+ {\r
+ target_raw[i]=0;\r
+ current_raw[i] =0;\r
+ }\r
+ htr.temp_meas_ready = false;\r
+ #ifdef MINTEMP\r
+ minttemp = temp2analog(MINTEMP);\r
+ #endif //MINTEMP\r
+ #ifdef MAXTEMP\r
+ maxttemp = temp2analog(MAXTEMP);\r
+ #endif //MAXTEMP\r
+\r
+ #ifdef BED_MINTEMP\r
+ bed_minttemp = temp2analog(BED_MINTEMP);\r
+ #endif //BED_MINTEMP\r
+ #ifdef BED_MAXTEMP\r
+ bed_maxttemp = temp2analog(BED_MAXTEMP);\r
+ #endif //BED_MAXTEMP\r
+ \r
#if (HEATER_0_PIN > -1) \r
SET_OUTPUT(HEATER_0_PIN);\r
#endif \r
#ifdef PIDTEMP\r
temp_iState_min = 0.0;\r
temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;\r
+ temp_iState = 0;\r
+ temp_dState = 0;\r
+ Kp=DEFAULT_Kp;\r
+ Ki=DEFAULT_Ki;\r
+ Kd=DEFAULT_Kd;\r
+ Kc=DEFAULT_Kc;\r
+ pid_setpoint = 0.0;\r
+\r
#endif //PIDTEMP\r
\r
// Set analog inputs\r
if(temp_count >= 16) // 6 ms * 16 = 96ms.\r
{\r
#ifdef HEATER_1_USES_AD595\r
- current_raw[0] = raw_temp_0_value;\r
+ htr.current_raw[0] = raw_temp_0_value;\r
#else\r
- current_raw[0] = 16383 - raw_temp_0_value;\r
+ htr.current_raw[0] = 16383 - raw_temp_0_value;\r
#endif\r
\r
#ifdef HEATER_2_USES_AD595\r
- current_raw[2] = raw_temp_2_value;\r
+ htr.current_raw[2] = raw_temp_2_value;\r
#else\r
- current_raw[2] = 16383 - raw_temp_2_value;\r
+ htr.current_raw[2] = 16383 - raw_temp_2_value;\r
#endif\r
\r
#ifdef BED_USES_AD595\r
- current_raw[1] = raw_temp_1_value;\r
+ htr.current_raw[1] = raw_temp_1_value;\r
#else\r
- current_raw[1] = 16383 - raw_temp_1_value;\r
+ htr.current_raw[1] = 16383 - raw_temp_1_value;\r
#endif\r
\r
- temp_meas_ready = true;\r
+ htr.temp_meas_ready = true;\r
temp_count = 0;\r
raw_temp_0_value = 0;\r
raw_temp_1_value = 0;\r
raw_temp_2_value = 0;\r
#ifdef MAXTEMP\r
#if (HEATER_0_PIN > -1)\r
- if(current_raw[TEMPSENSOR_HOTEND] >= maxttemp) {\r
- target_raw[TEMPSENSOR_HOTEND] = 0;\r
+ if(htr.current_raw[TEMPSENSOR_HOTEND] >= htr.maxttemp) {\r
+ htr.target_raw[TEMPSENSOR_HOTEND] = 0;\r
analogWrite(HEATER_0_PIN, 0);\r
Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!");\r
}\r
#endif\r
#if (HEATER_2_PIN > -1)\r
- if(current_raw[TEMPSENSOR_AUX] >= maxttemp) {\r
- target_raw[TEMPSENSOR_AUX] = 0;\r
+ if(htr.current_raw[TEMPSENSOR_AUX] >= htr.maxttemp) {\r
+ htr.target_raw[TEMPSENSOR_AUX] = 0;\r
analogWrite(HEATER_2_PIN, 0);\r
Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");\r
}\r
#endif //MAXTEMP\r
#ifdef MINTEMP\r
#if (HEATER_0_PIN > -1)\r
- if(current_raw[TEMPSENSOR_HOTEND] <= minttemp) {\r
- target_raw[TEMPSENSOR_HOTEND] = 0;\r
+ if(htr.current_raw[TEMPSENSOR_HOTEND] <= htr.minttemp) {\r
+ htr.target_raw[TEMPSENSOR_HOTEND] = 0;\r
analogWrite(HEATER_0_PIN, 0);\r
Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!");\r
}\r
#endif\r
#if (HEATER_2_PIN > -1)\r
- if(current_raw[TEMPSENSOR_AUX] <= minttemp) {\r
- target_raw[TEMPSENSOR_AUX] = 0;\r
+ if(htr.current_raw[TEMPSENSOR_AUX] <= htr.minttemp) {\r
+ htr.target_raw[TEMPSENSOR_AUX] = 0;\r
analogWrite(HEATER_2_PIN, 0);\r
Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!");\r
}\r
#endif //MAXTEMP\r
#ifdef BED_MINTEMP\r
#if (HEATER_1_PIN > -1)\r
- if(current_raw[1] <= bed_minttemp) {\r
- target_raw[1] = 0;\r
+ if(htr.current_raw[1] <= htr.bed_minttemp) {\r
+ htr.target_raw[1] = 0;\r
WRITE(HEATER_1_PIN, 0);\r
Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!");\r
}\r
#endif\r
#ifdef BED_MAXTEMP\r
#if (HEATER_1_PIN > -1)\r
- if(current_raw[1] >= bed_maxttemp) {\r
- target_raw[1] = 0;\r
+ if(htr.current_raw[1] >= htr.bed_maxttemp) {\r
+ htr.target_raw[1] = 0;\r
WRITE(HEATER_1_PIN, 0);\r
Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!");\r
}\r
#endif\r
}\r
}\r
+\r
+//Heater htr;\r
+\r
#ifdef PID_ADD_EXTRUSION_RATE\r
#include "stepper.h"\r
#endif\r
-void tp_init();\r
-void manage_heater();\r
-//int temp2analogu(int celsius, const short table[][2], int numtemps);\r
-//float analog2tempu(int raw, const short table[][2], int numtemps);\r
-float temp2analog(int celsius);\r
-float temp2analogBed(int celsius);\r
-float analog2temp(int raw);\r
-float analog2tempBed(int raw);\r
+\r
+enum TempSensor {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};\r
+\r
+// ther must be only one instance of this class, and it is created in temperature.cpp by itself and is called "htr".\r
+// all the variables are static, so that of the compiler optimization is more easy.\r
+// I honestly hope that this increases readability and structure.\r
+// none of the variables or routines should be called from an secondary process/interrupt with the exceptino of current_raw[].\r
+\r
+class Heater\r
+{\r
+public:\r
+ Heater(); //treplaces tp_init();\r
+ ~Heater(); \r
+ \r
+ void static manage_heater(); /// it is critical that this is called continously. \r
+ \r
+ // conversion routines, const since they don't change any class variables.\r
+ float const static temp2analog(const int celsius);\r
+ float const static temp2analogBed(const int celsius);\r
+ float const static analog2temp(const int raw);\r
+ float const static analog2tempBed(const int raw);\r
+ \r
+ inline float const static celsius(const TempSensor s) \r
+ {\r
+ if(s==TEMPSENSOR_BED) \r
+ return analog2tempBed(Heater::current_raw[s]); \r
+ else \r
+ return analog2temp(Heater::current_raw[s]);\r
+ };\r
+ inline float const static celsiusTarget(const TempSensor s) \r
+ {\r
+ if(s==TEMPSENSOR_BED) \r
+ return analog2tempBed(Heater::target_raw[s]); \r
+ else \r
+ return analog2temp(Heater::target_raw[s]);\r
+ };\r
+ inline float static setCelsius(const TempSensor s, const int celsius) \r
+ {\r
+ #ifdef PIDTEMP\r
+ if(s==TEMPSENSOR_HOTEND)\r
+ Heater::pid_setpoint = celsius;\r
+ #endif //PIDTEM\r
+ if(s==TEMPSENSOR_BED) \r
+ Heater::target_raw[s] = temp2analog(celsius); \r
+ else \r
+ Heater::target_raw[s] = temp2analogBed(celsius); \r
+ };\r
+\r
+ inline bool const static isHeating(TempSensor s)\r
+ { return (Heater::target_raw[s]>Heater::current_raw[s]);};\r
+ inline bool const static isCooling(TempSensor s)\r
+ { return (Heater::target_raw[s]<Heater::current_raw[s]);};\r
+\r
+public:\r
+ #ifdef PIDTEMP\r
+ static float Kp;\r
+ static float Ki;\r
+ static float Kd;\r
+ static float Kc;\r
+ #endif\r
+ \r
+ static int target_raw[3];\r
+ static float pid_setpoint;\r
+ \r
+ volatile static int current_raw[3]; //this are written by an ISR, so volatile.\r
+ volatile static bool temp_meas_ready ; //also this is set by the ISR\r
+ \r
+ \r
+private:\r
+ \r
+ \r
+\r
+ static unsigned long previous_millis_heater, previous_millis_bed_heater;\r
+\r
+ #ifdef PIDTEMP\r
+ static float temp_iState;\r
+ static float temp_dState;\r
+ static float pTerm;\r
+ static float iTerm;\r
+ static float dTerm;\r
+ //int output;\r
+ static float pid_error;\r
+ static float temp_iState_min;\r
+ static float temp_iState_max;\r
+ static float pid_input;\r
+ static float pid_output;\r
+ \r
+ static bool pid_reset;\r
+ static float HeaterPower;\r
+ \r
+ #endif //PIDTEMP\r
+\r
+public: //but only accesed from the ISR hence not volatile\r
+ #ifdef MINTEMP\r
+ static int minttemp;\r
+ #endif //MINTEMP\r
+ #ifdef MAXTEMP\r
+ static int maxttemp;\r
+ #endif //MAXTEMP\r
+\r
+ #ifdef BED_MINTEMP\r
+ static int bed_minttemp ;\r
+ #endif //BED_MINTEMP\r
+ #ifdef BED_MAXTEMP\r
+ static int bed_maxttemp;\r
+ #endif //BED_MAXTEMP\r
+ \r
+};\r
+\r
+extern Heater htr; //this creates the single, global instance \r
\r
#ifdef HEATER_USES_THERMISTOR\r
#define HEATERSOURCE 1\r
#define BEDSOURCE 1\r
#endif\r
\r
-//#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS)\r
-//#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS\r
-\r
-\r
-extern float Kp;\r
-extern float Ki;\r
-extern float Kd;\r
-extern float Kc;\r
-\r
-enum {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};\r
-extern int target_raw[3];\r
-extern int current_raw[3];\r
-extern double pid_setpoint;\r
\r
#endif\r
#include "ultralcd.h"\r
-\r
+#include "temperature.h"\r
\r
#ifdef ULTRA_LCD\r
extern volatile int feedmultiply;\r
void MainMenu::showStatus()\r
{ \r
#if LCD_HEIGHT==4\r
- static int oldcurrentraw=-1;\r
- static int oldtargetraw=-1;\r
+ static int oldcurrent=-1;\r
+ static int oldtarget=-1;\r
//force_lcd_update=true;\r
if(force_lcd_update||feedmultiplychanged) //initial display of content\r
{\r
#endif\r
}\r
\r
-\r
- if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update)\r
+ int tt=Heater::celsius(TEMPSENSOR_HOTEND);\r
+ if((abs(tt-oldcurrent)>1)||force_lcd_update)\r
{\r
lcd.setCursor(1,0);\r
- lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));\r
- oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];\r
+ lcd.print(ftostr3(tt));\r
+ oldcurrent=tt;\r
}\r
- if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update)\r
+ int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND);\r
+ if((ttg!=oldtarget)||force_lcd_update)\r
{\r
lcd.setCursor(5,0);\r
- lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));\r
- oldtargetraw=target_raw[TEMPSENSOR_HOTEND];\r
+ lcd.print(ftostr3(ttg));\r
+ oldtarget=ttg;\r
}\r
#if defined BED_USES_THERMISTOR || defined BED_USES_AD595 \r
- static int oldcurrentbedraw=-1;\r
- static int oldtargetbedraw=-1; \r
- if((current_bed_raw!=oldcurrentbedraw)||force_lcd_update)\r
+ static int oldcurrentbed=-1;\r
+ static int oldtargetbed=-1;\r
+ int tb=Heater::celsius(TEMPSENSOR_BED);\r
+ if((tb!=oldcurrentbed)||force_lcd_update)\r
{\r
lcd.setCursor(1,0);\r
- lcd.print(ftostr3(analog2temp(current_bed_raw)));\r
- oldcurrentraw=current_raw[TEMPSENSOR_BED];\r
+ lcd.print(ftostr3(tb));\r
+ oldcurrentbed=tb;\r
}\r
- if((target_bed_raw!=oldtargebedtraw)||force_lcd_update)\r
+ int tg=Heater::celsiusTarget(TEMPSENSOR_BED);\r
+ if((tg!=oldtargebed)||force_lcd_update)\r
{\r
lcd.setCursor(5,0);\r
- lcd.print(ftostr3(analog2temp(target_bed_raw)));\r
- oldtargetraw=target_bed_raw;\r
+ lcd.print(Heater::celsiusTarget(TEMPSENSOR_BED));\r
+ oldtargebed=tg;\r
}\r
#endif\r
//starttime=2;\r
messagetext[0]='\0';\r
}\r
#else //smaller LCDS----------------------------------\r
- static int oldcurrentraw=-1;\r
- static int oldtargetraw=-1;\r
+ static int oldcurrent=-1;\r
+ static int oldtarget=-1;\r
if(force_lcd_update) //initial display of content\r
{\r
encoderpos=feedmultiply;\r
#endif\r
}\r
\r
-\r
- if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update)\r
+ int tt=Heater::celsius(TEMPSENSOR_HOTEND);\r
+ if((abs(tt-oldcurrent)>1)||force_lcd_update)\r
{\r
lcd.setCursor(1,0);\r
- lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));\r
- oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];\r
+ lcd.print(ftostr3(tt));\r
+ oldcurrent=tt;\r
}\r
- if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update)\r
+ int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND);\r
+ if((ttg!=oldtarget)||force_lcd_update)\r
{\r
lcd.setCursor(5,0);\r
- lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));\r
- oldtargetraw=target_raw[TEMPSENSOR_HOTEND];\r
+ lcd.print(ftostr3(ttg));\r
+ oldtarge=ttg;\r
}\r
\r
if(messagetext[0]!='\0')\r
if((activeline==line) && CLICKED)\r
{\r
BLOCK\r
- target_raw[TEMPSENSOR_HOTEND] = temp2analog(170);\r
+ Heater::setCelsius(TEMPSENSOR_HOTEND, 170);\r
beepshort();\r
}\r
}break;\r
if(force_lcd_update)\r
{\r
lcd.setCursor(0,line);lcd.print(" \002Nozzle:");\r
- lcd.setCursor(13,line);lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));\r
+ lcd.setCursor(13,line);lcd.print(ftostr3(Heater::celsiusTarget(TEMPSENSOR_HOTEND)));\r
}\r
\r
if((activeline==line) )\r
linechanging=!linechanging;\r
if(linechanging)\r
{\r
- encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND]);\r
+ encoderpos=(int)Heater::celsiusTarget(TEMPSENSOR_HOTEND);\r
}\r
else\r
{\r
- target_raw[TEMPSENSOR_HOTEND] = temp2analog(encoderpos);\r
+ Heater::setCelsius(TEMPSENSOR_HOTEND,encoderpos);\r
encoderpos=activeline*lcdslow;\r
beepshort();\r
}\r
if(force_lcd_update)\r
{\r
lcd.setCursor(0,line);lcd.print(" PID-P: ");\r
- lcd.setCursor(13,line);lcd.print(itostr4(Kp));\r
+ lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kp));\r
}\r
\r
if((activeline==line) )\r
linechanging=!linechanging;\r
if(linechanging)\r
{\r
- encoderpos=(int)Kp/5;\r
+ encoderpos=(int)Heater::Kp/5;\r
}\r
else\r
{\r
- Kp= encoderpos*5;\r
+ Heater::Kp= encoderpos*5;\r
encoderpos=activeline*lcdslow;\r
\r
}\r
if(force_lcd_update)\r
{\r
lcd.setCursor(0,line);lcd.print(" PID-I: ");\r
- lcd.setCursor(13,line);lcd.print(ftostr51(Ki));\r
+ lcd.setCursor(13,line);lcd.print(ftostr51(Heater::Ki));\r
}\r
\r
if((activeline==line) )\r
linechanging=!linechanging;\r
if(linechanging)\r
{\r
- encoderpos=(int)(Ki*10);\r
+ encoderpos=(int)(Heater::Ki*10);\r
}\r
else\r
{\r
- Ki= encoderpos/10.;\r
+ Heater::Ki= encoderpos/10.;\r
encoderpos=activeline*lcdslow;\r
\r
}\r
if(force_lcd_update)\r
{\r
lcd.setCursor(0,line);lcd.print(" PID-D: ");\r
- lcd.setCursor(13,line);lcd.print(itostr4(Kd));\r
+ lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kd));\r
}\r
\r
if((activeline==line) )\r
linechanging=!linechanging;\r
if(linechanging)\r
{\r
- encoderpos=(int)Kd/5;\r
+ encoderpos=(int)(Heater::Kd/5.);\r
}\r
else\r
{\r
- Kd= encoderpos*5;\r
+ Heater::Kd= encoderpos*5;\r
encoderpos=activeline*lcdslow;\r
\r
}\r
if(force_lcd_update)\r
{\r
lcd.setCursor(0,line);lcd.print(" PID-C: ");\r
- lcd.setCursor(13,line);lcd.print(itostr3(Kc));\r
+ lcd.setCursor(13,line);lcd.print(itostr3(Heater::Kc));\r
}\r
\r
if((activeline==line) )\r
linechanging=!linechanging;\r
if(linechanging)\r
{\r
- encoderpos=(int)Kc;\r
+ encoderpos=(int)Heater::Kc;\r
}\r
else\r
{\r
- Kc= encoderpos;\r
+ Heater::Kc= encoderpos;\r
encoderpos=activeline*lcdslow;\r
\r
}\r