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:
Markus Hitter 2016-04-17 13:50:12 +02:00
parent 2291642456
commit 65857b17dc
2 changed files with 18 additions and 12 deletions

View File

@ -54,7 +54,6 @@ def generateTempTables(sensors, settings):
ofp.output("#define NUMTABLES %d" % len(tl))
ofp.output("#define NUMTEMPS %d" % N)
ofp.output("#define TEMPTABLE_FORMAT 1")
ofp.output("");
for i in range(len(tl)):

17
temp.c
View File

@ -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"),
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.
// y = ((x - x₀)y₁ + (x₁-x)y₀) / (x₁ - x₀)
// y = temp
@ -219,7 +227,8 @@ static uint16_t temp_table_lookup(uint16_t temp, uint8_t sensor) {
// (x₁ - x₀)
(pgm_read_word(&(temptable[table_num][j][0])) -
pgm_read_word(&(temptable[table_num][j - 1][0])));
#elif (TEMPTABLE_FORMAT == 1)
} else
if (sizeof(temptable[0][0]) == 3 * sizeof(uint16_t)) {
// Linear interpolation using pre-computed slope.
// y = y₁ - (x - x₁) * d₁
#define X1 pgm_read_word(&(temptable[table_num][j][0]))
@ -227,9 +236,7 @@ static uint16_t temp_table_lookup(uint16_t temp, uint8_t sensor) {
#define D1 pgm_read_word(&(temptable[table_num][j][2]))
temp = Y1 - ((((int32_t)temp - X1) * D1 + (1 << 7)) >> 8);
#else
#error "temptable format unrecognized"
#endif
}
if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR(" temp:%d.%d"), temp / 4, (temp % 4) * 25);