/* temperature.h - temperature controller Part of Marlin Copyright (c) 2011 Erik van der Zalm Grbl is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Grbl is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Grbl. If not, see . */ #ifndef temperature_h #define temperature_h #include "Marlin.h" #ifdef PID_ADD_EXTRUSION_RATE #include "stepper.h" #endif 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]