From 8bcdb9f5f062fe68d90e31752453e1d662b3f0e2 Mon Sep 17 00:00:00 2001 From: Bernhard Kubicek Date: Sat, 5 Nov 2011 16:43:44 +0100 Subject: [PATCH] this is not working. Do you maybe know why? --- Marlin/EEPROMwrite.h | 16 ++--- Marlin/Marlin.h | 1 + Marlin/Marlin.pde | 80 ++++++++++++------------- Marlin/planner.cpp | 2 +- Marlin/stepper.cpp | 2 +- Marlin/temperature.cpp | 128 +++++++++++++++++++--------------------- Marlin/temperature.h | 131 ++++++++++++++++++++++++++++++++++------- Marlin/ultralcd.pde | 90 ++++++++++++++-------------- 8 files changed, 268 insertions(+), 182 deletions(-) diff --git a/Marlin/EEPROMwrite.h b/Marlin/EEPROMwrite.h index 2247e2f52d..4e5364d80b 100644 --- a/Marlin/EEPROMwrite.h +++ b/Marlin/EEPROMwrite.h @@ -48,9 +48,9 @@ void StoreSettings() { EEPROM_writeAnything(i,max_xy_jerk); EEPROM_writeAnything(i,max_z_jerk); #ifdef PIDTEMP - EEPROM_writeAnything(i,Kp); - EEPROM_writeAnything(i,Ki); - EEPROM_writeAnything(i,Kd); + EEPROM_writeAnything(i,Heater::Kp); + EEPROM_writeAnything(i,Heater::Ki); + EEPROM_writeAnything(i,Heater::Kd); #else EEPROM_writeAnything(i,3000); EEPROM_writeAnything(i,0); @@ -81,11 +81,11 @@ void RetrieveSettings(bool def=false){ // if def=true, the default values will EEPROM_readAnything(i,max_xy_jerk); EEPROM_readAnything(i,max_z_jerk); #ifndef PIDTEMP - float Kp,Ki,Kd; + float Kp,Ki,Kd; //read and ignore.. #endif - EEPROM_readAnything(i,Kp); - EEPROM_readAnything(i,Ki); - EEPROM_readAnything(i,Kd); + EEPROM_readAnything(i,Heater::Kp); + EEPROM_readAnything(i,Heater::Ki); + EEPROM_readAnything(i,Heater::Kd); ECHOLN("Stored settings retreived:"); } @@ -119,7 +119,7 @@ void RetrieveSettings(bool def=false){ // if def=true, the default values will 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)); #ifdef PIDTEMP ECHOLN("PID settings:"); - ECHOLN(" M301 P" << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3)); + ECHOLN(" M301 P" << _FLOAT(Heater::Kp,3) << " I" << _FLOAT(Heater::Ki,3) << " D" << _FLOAT(Heater::Kd,3)); #endif } diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index f85dad3576..4cd4c8d39b 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -10,6 +10,7 @@ #define ECHO(x) Serial << "echo: " << x; #define ECHOLN(x) Serial << "echo: "< current_raw[TEMPSENSOR_HOTEND]){ + if(Heater::isHeating(TEMPSENSOR_HOTEND)){ watchmillis = max(1,millis()); watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND]; }else{ @@ -815,14 +813,14 @@ inline void process_commands() #endif break; case 140: // M140 set bed temp - if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analogBed(code_value()); + if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value()); break; case 105: // M105 #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595) - tt = analog2temp(current_raw[TEMPSENSOR_HOTEND]); + tt = Heater::celsius(TEMPSENSOR_HOTEND); #endif #if TEMP_1_PIN > -1 - bt = analog2tempBed(current_raw[TEMPSENSOR_BED]); + bt = Heater::celsius(TEMPSENSOR_BED); #endif #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595) Serial.print("ok T:"); @@ -833,14 +831,14 @@ inline void process_commands() #ifdef PIDTEMP Serial.print(" B:"); #if TEMP_1_PIN > -1 - Serial.println(bt); + Serial.println(bt); #else - Serial.println(HeaterPower); + Serial.println(Heater::HeaterPower); #endif #else Serial.println(); #endif - #else + #else< Serial.println(); #endif #else @@ -850,14 +848,12 @@ inline void process_commands() //break; case 109: {// M109 - Wait for extruder heater to reach target. LCD_MESSAGE("Heating..."); - if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value()); - #ifdef PIDTEMP - pid_setpoint = code_value(); - #endif //PIDTEM + if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value()); + #ifdef WATCHPERIOD - if(target_raw[TEMPSENSOR_HOTEND]>current_raw[TEMPSENSOR_HOTEND]){ + if(Heater::isHeating(TEMPSENSOR_HOTEND)){ watchmillis = max(1,millis()); - watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND]; + watch_raw[TEMPSENSOR_HOTEND] = Heater::current_raw[TEMPSENSOR_HOTEND]; } else { watchmillis = 0; } @@ -865,31 +861,31 @@ inline void process_commands() codenum = millis(); /* See if we are heating up or cooling down */ - bool target_direction = (current_raw[0] < target_raw[0]); // true if heating, false if cooling + bool target_direction = Heater::isHeating(TEMPSENSOR_HOTEND); // true if heating, false if cooling #ifdef TEMP_RESIDENCY_TIME long residencyStart; residencyStart = -1; /* continue to loop until we have reached the target temp _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ - while((target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0])) || + while((target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND)) || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { #else - while ( target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0]) ) { + while ( target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND) ) { #endif //TEMP_RESIDENCY_TIME if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down Serial.print("T:"); - Serial.println( analog2temp(current_raw[TEMPSENSOR_HOTEND]) ); + Serial.println( Heater::celsius(TEMPSENSOR_HOTEND) ); codenum = millis(); } - manage_heater(); + Heater::manage_heater(); LCD_STATUS; #ifdef TEMP_RESIDENCY_TIME /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time or when current temp falls outside the hysteresis after target temp was reached */ - if ((residencyStart == -1 && target_direction && current_raw[0] >= target_raw[0]) || - (residencyStart == -1 && !target_direction && current_raw[0] <= target_raw[0]) || - (residencyStart > -1 && labs(analog2temp(current_raw[0]) - analog2temp(target_raw[0])) > TEMP_HYSTERESIS) ) { + if ((residencyStart == -1 && target_direction && !Heater::isHeating(TEMPSENSOR_HOTEND)) || + (residencyStart == -1 && !target_direction && !Heater::isCooling(TEMPSENSOR_HOTEND)) || + (residencyStart > -1 && labs(Heater::celsius(TEMPSENSOR_HOTEND) - Heater::celsiusTarget(TEMPSENSOR_HOTEND)) > TEMP_HYSTERESIS) ) { residencyStart = millis(); } #endif //TEMP_RESIDENCY_TIME @@ -899,22 +895,22 @@ inline void process_commands() break; case 190: // M190 - Wait bed for heater to reach target. #if TEMP_1_PIN > -1 - if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analog(code_value()); + if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value()); codenum = millis(); - while(current_raw[TEMPSENSOR_BED] < target_raw[TEMPSENSOR_BED]) - { + while(Heater::isHeating(TEMPSENSOR_BED)) + { if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. { - float tt=analog2temp(current_raw[TEMPSENSOR_HOTEND]); + float tt=Heater::celsius(TEMPSENSOR_HOTEND); Serial.print("T:"); Serial.println( tt ); Serial.print("ok T:"); Serial.print( tt ); Serial.print(" B:"); - Serial.println( analog2temp(current_raw[TEMPSENSOR_BED]) ); + Serial.println( Heater::celsius(TEMPSENSOR_BED) ); codenum = millis(); } - manage_heater(); + Heater::manage_heater(); } #endif break; @@ -1066,9 +1062,13 @@ inline void process_commands() break; #ifdef PIDTEMP case 301: // M301 - if(code_seen('P')) Kp = code_value(); - if(code_seen('I')) Ki = code_value()*PID_dT; - if(code_seen('D')) Kd = code_value()/PID_dT; + if(code_seen('P')) Heater::Kp = code_value(); + if(code_seen('I')) Heater::Ki = code_value()*PID_dT; + if(code_seen('D')) Heater::Kd = code_value()/PID_dT; + #ifdef PID_ADD_EXTRUSION_RATE + if(code_seen('C')) Heater::Kc = code_value(); + #endif + // ECHOLN("Kp "<<_FLOAT(Kp,2)); // ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2)); // ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2)); @@ -1194,19 +1194,19 @@ void wd_reset() { inline void kill() { #if TEMP_0_PIN > -1 - target_raw[0]=0; + Heater::setCelsius(TEMPSENSOR_HOTEND,0); #if HEATER_0_PIN > -1 WRITE(HEATER_0_PIN,LOW); #endif #endif #if TEMP_1_PIN > -1 - target_raw[1]=0; + Heater::setCelsius(TEMPSENSOR_BED,0); #if HEATER_1_PIN > -1 WRITE(HEATER_1_PIN,LOW); #endif #endif #if TEMP_2_PIN > -1 - target_raw[2]=0; + Heater::setCelsius(TEMPSENSOR_AUX,0); #if HEATER_2_PIN > -1 WRITE(HEATER_2_PIN,LOW); #endif diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 14f0bb1043..cfeb6b2234 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -388,7 +388,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) { // If the buffer is full: good! That means we are well ahead of the robot. // Rest here until there is room in the buffer. while(block_buffer_tail == next_buffer_head) { - manage_heater(); + htr.manage_heater(); manage_inactivity(1); LCD_STATUS; } diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index f4bd1289e0..01ff430f35 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -585,7 +585,7 @@ void st_init() void st_synchronize() { while(plan_get_current_block()) { - manage_heater(); + htr.manage_heater(); manage_inactivity(1); LCD_STATUS; } diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index ebc772e1d8..9be4bdc2f7 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -37,52 +37,11 @@ #include "streaming.h" #include "temperature.h" -int target_bed_raw = 0; -int current_bed_raw = 0; -int target_raw[3] = {0, 0, 0}; -int current_raw[3] = {0, 0, 0}; -unsigned char temp_meas_ready = false; -unsigned long previous_millis_heater, previous_millis_bed_heater; -#ifdef PIDTEMP - double temp_iState = 0; - double temp_dState = 0; - double pTerm; - double iTerm; - double dTerm; - //int output; - double pid_error; - double temp_iState_min; - double temp_iState_max; - double pid_setpoint = 0.0; - double pid_input; - double pid_output; - bool pid_reset; - float HeaterPower; - - float Kp=DEFAULT_Kp; - float Ki=DEFAULT_Ki; - float Kd=DEFAULT_Kd; - float Kc=DEFAULT_Kc; -#endif //PIDTEMP -#ifdef MINTEMP -int minttemp = temp2analog(MINTEMP); -#endif //MINTEMP -#ifdef MAXTEMP -int maxttemp = temp2analog(MAXTEMP); -#endif //MAXTEMP - -#ifdef BED_MINTEMP -int bed_minttemp = temp2analog(BED_MINTEMP); -#endif //BED_MINTEMP -#ifdef BED_MAXTEMP -int bed_maxttemp = temp2analog(BED_MAXTEMP); -#endif //BED_MAXTEMP - -void manage_heater() +void static Heater::manage_heater() { #ifdef USE_WATCHDOG wd_reset(); @@ -90,11 +49,11 @@ void manage_heater() float pid_input; float pid_output; - if(temp_meas_ready != true) //better readability + if(htr.temp_meas_ready != true) //better readability return; CRITICAL_SECTION_START; - temp_meas_ready = false; + htr.temp_meas_ready = false; CRITICAL_SECTION_END; #ifdef PIDTEMP @@ -176,7 +135,8 @@ CRITICAL_SECTION_END; // For a thermistor, it uses the RepRap thermistor temp table. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware. -float temp2analog(int celsius) { +float const static temp2analog(const int celsius) +{ #ifdef HEATER_USES_THERMISTOR_1 int raw = 0; byte i; @@ -207,7 +167,8 @@ float temp2analog(int celsius) { // For a thermistor, it uses the RepRap thermistor temp table. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware. -float temp2analogBed(int celsius) { +float const static temp2analogBed(const int celsius) +{ #ifdef BED_USES_THERMISTOR int raw = 0; @@ -237,7 +198,7 @@ float temp2analogBed(int celsius) { // Derived from RepRap FiveD extruder::getTemperature() // For hot end temperature measurement. -float analog2temp(int raw) { +float const static Heater::analog2temp(const int raw) { #ifdef HEATER_1_USES_THERMISTOR int celsius = 0; byte i; @@ -266,7 +227,7 @@ float analog2temp(int raw) { // Derived from RepRap FiveD extruder::getTemperature() // For bed temperature measurement. -float analog2tempBed(int raw) { +float const static Heater::analog2tempBed(const int raw) { #ifdef BED_USES_THERMISTOR int celsius = 0; byte i; @@ -296,8 +257,28 @@ float analog2tempBed(int raw) { #endif } -void tp_init() +Heater::Heater() { + for(short i=0;i<3;i++) + { + target_raw[i]=0; + current_raw[i] =0; + } + htr.temp_meas_ready = false; + #ifdef MINTEMP + minttemp = temp2analog(MINTEMP); + #endif //MINTEMP + #ifdef MAXTEMP + maxttemp = temp2analog(MAXTEMP); + #endif //MAXTEMP + + #ifdef BED_MINTEMP + bed_minttemp = temp2analog(BED_MINTEMP); + #endif //BED_MINTEMP + #ifdef BED_MAXTEMP + bed_maxttemp = temp2analog(BED_MAXTEMP); + #endif //BED_MAXTEMP + #if (HEATER_0_PIN > -1) SET_OUTPUT(HEATER_0_PIN); #endif @@ -311,6 +292,14 @@ void tp_init() #ifdef PIDTEMP temp_iState_min = 0.0; temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki; + temp_iState = 0; + temp_dState = 0; + Kp=DEFAULT_Kp; + Ki=DEFAULT_Ki; + Kd=DEFAULT_Kd; + Kc=DEFAULT_Kc; + pid_setpoint = 0.0; + #endif //PIDTEMP // Set analog inputs @@ -407,39 +396,39 @@ ISR(TIMER0_COMPB_vect) if(temp_count >= 16) // 6 ms * 16 = 96ms. { #ifdef HEATER_1_USES_AD595 - current_raw[0] = raw_temp_0_value; + htr.current_raw[0] = raw_temp_0_value; #else - current_raw[0] = 16383 - raw_temp_0_value; + htr.current_raw[0] = 16383 - raw_temp_0_value; #endif #ifdef HEATER_2_USES_AD595 - current_raw[2] = raw_temp_2_value; + htr.current_raw[2] = raw_temp_2_value; #else - current_raw[2] = 16383 - raw_temp_2_value; + htr.current_raw[2] = 16383 - raw_temp_2_value; #endif #ifdef BED_USES_AD595 - current_raw[1] = raw_temp_1_value; + htr.current_raw[1] = raw_temp_1_value; #else - current_raw[1] = 16383 - raw_temp_1_value; + htr.current_raw[1] = 16383 - raw_temp_1_value; #endif - temp_meas_ready = true; + htr.temp_meas_ready = true; temp_count = 0; raw_temp_0_value = 0; raw_temp_1_value = 0; raw_temp_2_value = 0; #ifdef MAXTEMP #if (HEATER_0_PIN > -1) - if(current_raw[TEMPSENSOR_HOTEND] >= maxttemp) { - target_raw[TEMPSENSOR_HOTEND] = 0; + if(htr.current_raw[TEMPSENSOR_HOTEND] >= htr.maxttemp) { + htr.target_raw[TEMPSENSOR_HOTEND] = 0; analogWrite(HEATER_0_PIN, 0); Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!"); } #endif #if (HEATER_2_PIN > -1) - if(current_raw[TEMPSENSOR_AUX] >= maxttemp) { - target_raw[TEMPSENSOR_AUX] = 0; + if(htr.current_raw[TEMPSENSOR_AUX] >= htr.maxttemp) { + htr.target_raw[TEMPSENSOR_AUX] = 0; analogWrite(HEATER_2_PIN, 0); Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!"); } @@ -447,15 +436,15 @@ ISR(TIMER0_COMPB_vect) #endif //MAXTEMP #ifdef MINTEMP #if (HEATER_0_PIN > -1) - if(current_raw[TEMPSENSOR_HOTEND] <= minttemp) { - target_raw[TEMPSENSOR_HOTEND] = 0; + if(htr.current_raw[TEMPSENSOR_HOTEND] <= htr.minttemp) { + htr.target_raw[TEMPSENSOR_HOTEND] = 0; analogWrite(HEATER_0_PIN, 0); Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!"); } #endif #if (HEATER_2_PIN > -1) - if(current_raw[TEMPSENSOR_AUX] <= minttemp) { - target_raw[TEMPSENSOR_AUX] = 0; + if(htr.current_raw[TEMPSENSOR_AUX] <= htr.minttemp) { + htr.target_raw[TEMPSENSOR_AUX] = 0; analogWrite(HEATER_2_PIN, 0); Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!"); } @@ -463,8 +452,8 @@ ISR(TIMER0_COMPB_vect) #endif //MAXTEMP #ifdef BED_MINTEMP #if (HEATER_1_PIN > -1) - if(current_raw[1] <= bed_minttemp) { - target_raw[1] = 0; + if(htr.current_raw[1] <= htr.bed_minttemp) { + htr.target_raw[1] = 0; WRITE(HEATER_1_PIN, 0); Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!"); } @@ -472,8 +461,8 @@ ISR(TIMER0_COMPB_vect) #endif #ifdef BED_MAXTEMP #if (HEATER_1_PIN > -1) - if(current_raw[1] >= bed_maxttemp) { - target_raw[1] = 0; + if(htr.current_raw[1] >= htr.bed_maxttemp) { + htr.target_raw[1] = 0; WRITE(HEATER_1_PIN, 0); Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!"); } @@ -481,3 +470,6 @@ ISR(TIMER0_COMPB_vect) #endif } } + +//Heater htr; + diff --git a/Marlin/temperature.h b/Marlin/temperature.h index e2e6c459c6..a93d46ba4b 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -25,14 +25,116 @@ #ifdef PID_ADD_EXTRUSION_RATE #include "stepper.h" #endif -void tp_init(); -void manage_heater(); -//int temp2analogu(int celsius, const short table[][2], int numtemps); -//float analog2tempu(int raw, const short table[][2], int numtemps); -float temp2analog(int celsius); -float temp2analogBed(int celsius); -float analog2temp(int raw); -float analog2tempBed(int raw); + +enum TempSensor {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2}; + +// ther must be only one instance of this class, and it is created in temperature.cpp by itself and is called "htr". +// all the variables are static, so that of the compiler optimization is more easy. +// I honestly hope that this increases readability and structure. +// none of the variables or routines should be called from an secondary process/interrupt with the exceptino of current_raw[]. + +class Heater +{ +public: + Heater(); //treplaces tp_init(); + ~Heater(); + + void static manage_heater(); /// it is critical that this is called continously. + + // conversion routines, const since they don't change any class variables. + float const static temp2analog(const int celsius); + float const static temp2analogBed(const int celsius); + float const static analog2temp(const int raw); + float const static analog2tempBed(const int raw); + + inline float const static celsius(const TempSensor s) + { + if(s==TEMPSENSOR_BED) + return analog2tempBed(Heater::current_raw[s]); + else + return analog2temp(Heater::current_raw[s]); + }; + inline float const static celsiusTarget(const TempSensor s) + { + if(s==TEMPSENSOR_BED) + return analog2tempBed(Heater::target_raw[s]); + else + return analog2temp(Heater::target_raw[s]); + }; + inline float static setCelsius(const TempSensor s, const int celsius) + { + #ifdef PIDTEMP + if(s==TEMPSENSOR_HOTEND) + Heater::pid_setpoint = celsius; + #endif //PIDTEM + if(s==TEMPSENSOR_BED) + Heater::target_raw[s] = temp2analog(celsius); + else + Heater::target_raw[s] = temp2analogBed(celsius); + }; + + inline bool const static isHeating(TempSensor s) + { return (Heater::target_raw[s]>Heater::current_raw[s]);}; + inline bool const static isCooling(TempSensor s) + { return (Heater::target_raw[s]3)||force_lcd_update) + int tt=Heater::celsius(TEMPSENSOR_HOTEND); + if((abs(tt-oldcurrent)>1)||force_lcd_update) { lcd.setCursor(1,0); - lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND]))); - oldcurrentraw=current_raw[TEMPSENSOR_HOTEND]; + lcd.print(ftostr3(tt)); + oldcurrent=tt; } - if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update) + int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND); + if((ttg!=oldtarget)||force_lcd_update) { lcd.setCursor(5,0); - lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND]))); - oldtargetraw=target_raw[TEMPSENSOR_HOTEND]; + lcd.print(ftostr3(ttg)); + oldtarget=ttg; } #if defined BED_USES_THERMISTOR || defined BED_USES_AD595 - static int oldcurrentbedraw=-1; - static int oldtargetbedraw=-1; - if((current_bed_raw!=oldcurrentbedraw)||force_lcd_update) + static int oldcurrentbed=-1; + static int oldtargetbed=-1; + int tb=Heater::celsius(TEMPSENSOR_BED); + if((tb!=oldcurrentbed)||force_lcd_update) { lcd.setCursor(1,0); - lcd.print(ftostr3(analog2temp(current_bed_raw))); - oldcurrentraw=current_raw[TEMPSENSOR_BED]; + lcd.print(ftostr3(tb)); + oldcurrentbed=tb; } - if((target_bed_raw!=oldtargebedtraw)||force_lcd_update) + int tg=Heater::celsiusTarget(TEMPSENSOR_BED); + if((tg!=oldtargebed)||force_lcd_update) { lcd.setCursor(5,0); - lcd.print(ftostr3(analog2temp(target_bed_raw))); - oldtargetraw=target_bed_raw; + lcd.print(Heater::celsiusTarget(TEMPSENSOR_BED)); + oldtargebed=tg; } #endif //starttime=2; @@ -327,8 +330,8 @@ void MainMenu::showStatus() messagetext[0]='\0'; } #else //smaller LCDS---------------------------------- - static int oldcurrentraw=-1; - static int oldtargetraw=-1; + static int oldcurrent=-1; + static int oldtarget=-1; if(force_lcd_update) //initial display of content { encoderpos=feedmultiply; @@ -338,18 +341,19 @@ void MainMenu::showStatus() #endif } - - if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update) + int tt=Heater::celsius(TEMPSENSOR_HOTEND); + if((abs(tt-oldcurrent)>1)||force_lcd_update) { lcd.setCursor(1,0); - lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND]))); - oldcurrentraw=current_raw[TEMPSENSOR_HOTEND]; + lcd.print(ftostr3(tt)); + oldcurrent=tt; } - if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update) + int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND); + if((ttg!=oldtarget)||force_lcd_update) { lcd.setCursor(5,0); - lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND]))); - oldtargetraw=target_raw[TEMPSENSOR_HOTEND]; + lcd.print(ftostr3(ttg)); + oldtarge=ttg; } if(messagetext[0]!='\0') @@ -426,7 +430,7 @@ void MainMenu::showPrepare() if((activeline==line) && CLICKED) { BLOCK - target_raw[TEMPSENSOR_HOTEND] = temp2analog(170); + Heater::setCelsius(TEMPSENSOR_HOTEND, 170); beepshort(); } }break; @@ -531,7 +535,7 @@ void MainMenu::showControl() if(force_lcd_update) { lcd.setCursor(0,line);lcd.print(" \002Nozzle:"); - lcd.setCursor(13,line);lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND]))); + lcd.setCursor(13,line);lcd.print(ftostr3(Heater::celsiusTarget(TEMPSENSOR_HOTEND))); } if((activeline==line) ) @@ -541,11 +545,11 @@ void MainMenu::showControl() linechanging=!linechanging; if(linechanging) { - encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND]); + encoderpos=(int)Heater::celsiusTarget(TEMPSENSOR_HOTEND); } else { - target_raw[TEMPSENSOR_HOTEND] = temp2analog(encoderpos); + Heater::setCelsius(TEMPSENSOR_HOTEND,encoderpos); encoderpos=activeline*lcdslow; beepshort(); } @@ -669,7 +673,7 @@ void MainMenu::showControl() if(force_lcd_update) { lcd.setCursor(0,line);lcd.print(" PID-P: "); - lcd.setCursor(13,line);lcd.print(itostr4(Kp)); + lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kp)); } if((activeline==line) ) @@ -679,11 +683,11 @@ void MainMenu::showControl() linechanging=!linechanging; if(linechanging) { - encoderpos=(int)Kp/5; + encoderpos=(int)Heater::Kp/5; } else { - Kp= encoderpos*5; + Heater::Kp= encoderpos*5; encoderpos=activeline*lcdslow; } @@ -703,7 +707,7 @@ void MainMenu::showControl() if(force_lcd_update) { lcd.setCursor(0,line);lcd.print(" PID-I: "); - lcd.setCursor(13,line);lcd.print(ftostr51(Ki)); + lcd.setCursor(13,line);lcd.print(ftostr51(Heater::Ki)); } if((activeline==line) ) @@ -713,11 +717,11 @@ void MainMenu::showControl() linechanging=!linechanging; if(linechanging) { - encoderpos=(int)(Ki*10); + encoderpos=(int)(Heater::Ki*10); } else { - Ki= encoderpos/10.; + Heater::Ki= encoderpos/10.; encoderpos=activeline*lcdslow; } @@ -737,7 +741,7 @@ void MainMenu::showControl() if(force_lcd_update) { lcd.setCursor(0,line);lcd.print(" PID-D: "); - lcd.setCursor(13,line);lcd.print(itostr4(Kd)); + lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kd)); } if((activeline==line) ) @@ -747,11 +751,11 @@ void MainMenu::showControl() linechanging=!linechanging; if(linechanging) { - encoderpos=(int)Kd/5; + encoderpos=(int)(Heater::Kd/5.); } else { - Kd= encoderpos*5; + Heater::Kd= encoderpos*5; encoderpos=activeline*lcdslow; } @@ -774,7 +778,7 @@ void MainMenu::showControl() if(force_lcd_update) { lcd.setCursor(0,line);lcd.print(" PID-C: "); - lcd.setCursor(13,line);lcd.print(itostr3(Kc)); + lcd.setCursor(13,line);lcd.print(itostr3(Heater::Kc)); } if((activeline==line) ) @@ -784,11 +788,11 @@ void MainMenu::showControl() linechanging=!linechanging; if(linechanging) { - encoderpos=(int)Kc; + encoderpos=(int)Heater::Kc; } else { - Kc= encoderpos; + Heater::Kc= encoderpos; encoderpos=activeline*lcdslow; }