refactured temperature.cpp so that there are now abstract functions to access temperatures.

This commit is contained in:
Bernhard Kubicek
2011-11-06 14:03:41 +01:00
parent 0b82465168
commit 2afb7bd4cf
5 changed files with 237 additions and 179 deletions

View File

@ -22,18 +22,97 @@
#define temperature_h
#include "Marlin.h"
#include "fastio.h"
#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);
void tp_init(); //initialise the heating
void manage_heater(); //it is critical that this is called periodically.
enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
//low leven conversion routines
// do not use this routines and variables outsie of temperature.cpp
int temp2analog(int celsius);
int temp2analogBed(int celsius);
float analog2temp(int raw);
float analog2tempBed(int raw);
extern int target_raw[3];
extern int current_raw[3];
extern float Kp,Ki,Kd,Kc;
#ifdef PIDTEMP
float pid_setpoint = 0.0;
#endif
#ifdef WATCHPERIOD
extern int watch_raw[3] ;
extern unsigned long watchmillis;
#endif
//high level conversion routines, for use outside of temperature.cpp
//inline so that there is no performance decrease.
//deg=degreeCelsius
inline float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);};
inline float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);};
inline float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);};
inline float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);};
inline float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};
inline float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};
inline void setTargetHotend0(float celsius)
{
target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
#ifdef PIDTEMP
pid_setpoint = celsius;
#endif //PIDTEMP
};
inline void setTargetHotend1(float celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};
inline void setTargetBed(float celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};
inline bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
inline bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
inline bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];};
inline bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];};
inline bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];};
inline bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];};
inline void disable_heater()
{
#if TEMP_0_PIN > -1
target_raw[0]=0;
#if HEATER_0_PIN > -1
WRITE(HEATER_0_PIN,LOW);
#endif
#endif
#if TEMP_1_PIN > -1
target_raw[1]=0;
#if HEATER_1_PIN > -1
WRITE(HEATER_1_PIN,LOW);
#endif
#endif
#if TEMP_2_PIN > -1
target_raw[2]=0;
#if HEATER_2_PIN > -1
WRITE(HEATER_2_PIN,LOW);
#endif
#endif
}
void setWatch() {
if(isHeatingHotend0())
{
watchmillis = max(1,millis());
watch_raw[TEMPSENSOR_HOTEND_0] = current_raw[TEMPSENSOR_HOTEND_0];
}
else
{
watchmillis = 0;
}
}
#ifdef HEATER_0_USES_THERMISTOR
#define HEATERSOURCE 1
#endif
@ -41,18 +120,9 @@ float analog2tempBed(int raw);
#define BEDSOURCE 1
#endif
//#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS)
//#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS
extern float Kp;
extern float Ki;
extern float Kd;
extern float Kc;
enum {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
extern int target_raw[3];
extern int current_raw[3];
extern double pid_setpoint;
#endif
#endif