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 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);
#ifdef HEATER_USES_THERMISTOR
#define HEATERSOURCE 1
#endif
#ifdef HEATER_USES_AD595
#define HEATERSOURCE 2
#endif
#ifdef HEATER_USES_MAX6675
#define HEATERSOURCE 3
#endif
#ifdef BED_USES_THERMISTOR
#define BEDSOURCE 1
#endif
#ifdef BED_USES_AD595
#define BEDSOURCE 2
#endif
#ifdef BED_USES_MAX6675
#define BEDSOURCE 3
#if defined HEATER_USES_THERMISTOR
#define temp2analogh( c ) temp2analog_thermistor(c,temptable,NUMTEMPS)
#define analog2temp( c ) analog2temp_thermistor(c,temptable,NUMTEMPS)
#elif defined HEATER_USES_AD595
#define temp2analogh( c ) temp2analog_ad595(c)
#define analog2temp( c ) analog2temp_ad595(c)
#elif defined HEATER_USES_MAX6675
#define temp2analogh( c ) temp2analog_max6675(c)
#define analog2temp( c ) analog2temp_max6675(c)
#endif
#if defined BED_USES_THERMISTOR
#define temp2analogBed( c ) temp2analog_thermistor((c),bedtemptable,BNUMTEMPS)
#define analog2tempBed( c ) analog2temp_thermistor((c),bedtemptable,BNUMTEMPS)
#elif defined BED_USES_AD595
#define temp2analogBed( c ) temp2analog_ad595(c)
#define analog2tempBed( c ) analog2temp_ad595(c)
#elif defined BED_USES_MAX6675
#define temp2analogBed( c ) temp2analog_max6675(c)
#define analog2tempBed( c ) analog2temp_max6675(c)
#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
#define enable_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
}
int temp2analogu(int celsius, const short table[][2], int numtemps, int source) {
#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
if(source==1){
#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
int temp2analog_thermistor(int celsius, const short table[][2], int numtemps) {
int raw = 0;
byte i;
@ -1563,20 +1561,23 @@ int temp2analogu(int celsius, const short table[][2], int numtemps, int source)
if (i == numtemps) raw = table[i-1][0];
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
return -1;
}
#endif
int analog2tempu(int raw,const short table[][2], int numtemps, int source) {
#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
if(source==1){
#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)
int analog2temp_thermistor(int raw,const short table[][2], int numtemps) {
int celsius = 0;
byte i;
@ -1599,17 +1600,20 @@ int analog2tempu(int raw,const short table[][2], int numtemps, int source) {
if (i == numtemps) celsius = table[i-1][1];
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
return -1;
}
#endif
#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()
{