diff --git a/lambda/lambda.c b/lambda/lambda.c index e5f6c93..ecbf103 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -6,7 +6,6 @@ * * TODO comments, attribution * TODO DIDR? - * TODO How to round integer divisions half up? * TODO string.h? */ #include diff --git a/lambda/sensors.c b/lambda/sensors.c index 3a1cafc..db18e12 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -80,7 +80,7 @@ } int16_t toTempI(int16_t mV) { - int temp = mV / 5; + int temp = (mV + 3) / 5; return temp; } @@ -106,10 +106,10 @@ } } - int32_t diffVoltage = table[i + 1].mV - table[i].mV; - int32_t diffValue = table[i + 1].value - table[i].value; + int16_t diffVoltage = table[i + 1].mV - table[i].mV; + int16_t diffValue = table[i + 1].value - table[i].value; int16_t value = table[i].value + - (((mV - table[i].mV) * (diffValue << 10) / diffVoltage) >> 10); + ((int32_t)(mV - table[i].mV) * diffValue / diffVoltage); return value; }