temp.c: get rid of TEMPTABLE_FORMAT.
Detecting tables by data size works fine, the optimiser removes unneeded code successfully. Binary size stays the same.
This commit is contained in:
parent
2291642456
commit
65857b17dc
|
|
@ -54,7 +54,6 @@ def generateTempTables(sensors, settings):
|
||||||
|
|
||||||
ofp.output("#define NUMTABLES %d" % len(tl))
|
ofp.output("#define NUMTABLES %d" % len(tl))
|
||||||
ofp.output("#define NUMTEMPS %d" % N)
|
ofp.output("#define NUMTEMPS %d" % N)
|
||||||
ofp.output("#define TEMPTABLE_FORMAT 1")
|
|
||||||
ofp.output("");
|
ofp.output("");
|
||||||
|
|
||||||
for i in range(len(tl)):
|
for i in range(len(tl)):
|
||||||
|
|
|
||||||
29
temp.c
29
temp.c
|
|
@ -196,7 +196,15 @@ static uint16_t temp_table_lookup(uint16_t temp, uint8_t sensor) {
|
||||||
sersendf_P(PSTR("pin:%d Raw ADC:%d table entry: %d"),
|
sersendf_P(PSTR("pin:%d Raw ADC:%d table entry: %d"),
|
||||||
temp_sensors[sensor].temp_pin, temp, j);
|
temp_sensors[sensor].temp_pin, temp, j);
|
||||||
|
|
||||||
#if (TEMPTABLE_FORMAT == 0)
|
if (sizeof(temptable[0][0]) == 2 * sizeof(uint16_t)) {
|
||||||
|
/**
|
||||||
|
This code handles temptables with value pairs and is deprecated.
|
||||||
|
It's kept for compatibility with legacy, handcrafted tables, only.
|
||||||
|
|
||||||
|
The new code expects tables with triples, nevertheless it's smaller
|
||||||
|
and also faster. Configtool was already changed to create tables
|
||||||
|
with triples, only.
|
||||||
|
*/
|
||||||
// Wikipedia's example linear interpolation formula.
|
// Wikipedia's example linear interpolation formula.
|
||||||
// y = ((x - x₀)y₁ + (x₁-x)y₀) / (x₁ - x₀)
|
// y = ((x - x₀)y₁ + (x₁-x)y₀) / (x₁ - x₀)
|
||||||
// y = temp
|
// y = temp
|
||||||
|
|
@ -219,17 +227,16 @@ static uint16_t temp_table_lookup(uint16_t temp, uint8_t sensor) {
|
||||||
// (x₁ - x₀)
|
// (x₁ - x₀)
|
||||||
(pgm_read_word(&(temptable[table_num][j][0])) -
|
(pgm_read_word(&(temptable[table_num][j][0])) -
|
||||||
pgm_read_word(&(temptable[table_num][j - 1][0])));
|
pgm_read_word(&(temptable[table_num][j - 1][0])));
|
||||||
#elif (TEMPTABLE_FORMAT == 1)
|
} else
|
||||||
// Linear interpolation using pre-computed slope.
|
if (sizeof(temptable[0][0]) == 3 * sizeof(uint16_t)) {
|
||||||
// y = y₁ - (x - x₁) * d₁
|
// Linear interpolation using pre-computed slope.
|
||||||
#define X1 pgm_read_word(&(temptable[table_num][j][0]))
|
// y = y₁ - (x - x₁) * d₁
|
||||||
#define Y1 pgm_read_word(&(temptable[table_num][j][1]))
|
#define X1 pgm_read_word(&(temptable[table_num][j][0]))
|
||||||
#define D1 pgm_read_word(&(temptable[table_num][j][2]))
|
#define Y1 pgm_read_word(&(temptable[table_num][j][1]))
|
||||||
|
#define D1 pgm_read_word(&(temptable[table_num][j][2]))
|
||||||
|
|
||||||
temp = Y1 - ((((int32_t)temp - X1) * D1 + (1<<7)) >> 8);
|
temp = Y1 - ((((int32_t)temp - X1) * D1 + (1 << 7)) >> 8);
|
||||||
#else
|
}
|
||||||
#error "temptable format unrecognized"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (DEBUG_PID && (debug_flags & DEBUG_PID))
|
if (DEBUG_PID && (debug_flags & DEBUG_PID))
|
||||||
sersendf_P(PSTR(" temp:%d.%d"), temp / 4, (temp % 4) * 25);
|
sersendf_P(PSTR(" temp:%d.%d"), temp / 4, (temp % 4) * 25);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue