Fix temp readings for multiple sensor types.

Signed-off-by: Greg Frost <gregfrost1@bigpond.com>
This commit is contained in:
unknown 2011-09-11 16:36:15 +09:30
parent 78be8881ce
commit 614b60b038
2 changed files with 50 additions and 48 deletions

View file

@ -11,31 +11,29 @@ void manage_inactivity(byte debug);
void setup_acceleration(); void setup_acceleration();
void manage_heater(); void manage_heater();
int temp2analogu(int celsius, const short table[][2], int numtemps, int source);
int analog2tempu(int raw, const short table[][2], int numtemps, int source); #if defined HEATER_USES_THERMISTOR
#ifdef HEATER_USES_THERMISTOR #define temp2analogh( c ) temp2analog_thermistor(c,temptable,NUMTEMPS)
#define HEATERSOURCE 1 #define analog2temp( c ) analog2temp_thermistor(c,temptable,NUMTEMPS)
#endif #elif defined HEATER_USES_AD595
#ifdef HEATER_USES_AD595 #define temp2analogh( c ) temp2analog_ad595(c)
#define HEATERSOURCE 2 #define analog2temp( c ) analog2temp_ad595(c)
#endif #elif defined HEATER_USES_MAX6675
#ifdef HEATER_USES_MAX6675 #define temp2analogh( c ) temp2analog_max6675(c)
#define HEATERSOURCE 3 #define analog2temp( c ) analog2temp_max6675(c)
#endif #endif
#ifdef BED_USES_THERMISTOR
#define BEDSOURCE 1 #if defined BED_USES_THERMISTOR
#endif #define temp2analogBed( c ) temp2analog_thermistor((c),bedtemptable,BNUMTEMPS)
#ifdef BED_USES_AD595 #define analog2tempBed( c ) analog2temp_thermistor((c),bedtemptable,BNUMTEMPS)
#define BEDSOURCE 2 #elif defined BED_USES_AD595
#endif #define temp2analogBed( c ) temp2analog_ad595(c)
#ifdef BED_USES_MAX6675 #define analog2tempBed( c ) analog2temp_ad595(c)
#define BEDSOURCE 3 #elif defined BED_USES_MAX6675
#define temp2analogBed( c ) temp2analog_max6675(c)
#define analog2tempBed( c ) analog2temp_max6675(c)
#endif #endif
#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS,HEATERSOURCE)
#define temp2analogBed( c ) temp2analogu((c),bedtemptable,BNUMTEMPS,BEDSOURCE)
#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS,HEATERSOURCE)
#define analog2tempBed( c ) analog2tempu((c),bedtemptable,BNUMTEMPS,BEDSOURCE)
#if X_ENABLE_PIN > -1 #if X_ENABLE_PIN > -1
#define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
#define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON) #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)

View file

@ -1539,10 +1539,8 @@ void manage_heater()
#endif #endif
} }
int temp2analogu(int celsius, const short table[][2], int numtemps, int source) {
#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
if(source==1){ int temp2analog_thermistor(int celsius, const short table[][2], int numtemps) {
int raw = 0; int raw = 0;
byte i; byte i;
@ -1564,19 +1562,22 @@ int temp2analogu(int celsius, const short table[][2], int numtemps, int source)
return 1023 - raw; return 1023 - raw;
} }
#elif defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
if(source==2)
return celsius * 1024 / (500);
#elif defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
if(source==3)
return celsius * 4;
#endif #endif
return -1;
}
int analog2tempu(int raw,const short table[][2], int numtemps, int source) { #if defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
int temp2analog_ad595(int celsius) {
return celsius * 1024 / (500);
}
#endif
#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
int temp2analog_max6675(int celsius) {
return celsius * 4;
}
#endif
#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
if(source==1){ int analog2temp_thermistor(int raw,const short table[][2], int numtemps) {
int celsius = 0; int celsius = 0;
byte i; byte i;
@ -1600,16 +1601,19 @@ int analog2tempu(int raw,const short table[][2], int numtemps, int source) {
return celsius; return celsius;
} }
#elif defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
if(source==2)
return raw * 500 / 1024;
#elif defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
if(source==3)
return raw / 4;
#endif #endif
return -1;
}
#if defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
int analog2temp_ad595(int raw) {
return raw * 500 / 1024;
}
#endif
#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
int analog2temp_max6675(int raw) {
return raw / 4;
}
#endif
inline void kill() inline void kill()
{ {