diff --git a/lambda-test/Makefile b/lambda-test/Makefile index a533629..d5fcefd 100644 --- a/lambda-test/Makefile +++ b/lambda-test/Makefile @@ -28,7 +28,7 @@ PROGRAMMER_TYPE = avrisp # extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 +PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM3 ##########------------------------------------------------------########## ########## Makefile Magic! ########## diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index 7967d0e..70284cf 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -71,7 +71,7 @@ setupSleepMode(); // enable pull-up resistor so the measured voltage - // should be (close to?) AREF + // should be close to AREF PORTC |= (1 << PC1); // PORTC = 0xff; @@ -158,7 +158,7 @@ setupSleepMode(); // enable pull-up resistor so the measured voltage - // should be (close to?) AREF + // should be close to AREF PORTC |= ((1 << PC5) | (1 << PC0) | (1 << PC2)); _delay_ms(10); @@ -266,15 +266,25 @@ } bool testToInfoLean(void) { - const char* info = toInfo(1600); + const char* info = toInfo(1901); return ! strcmp(info, LEAN); } -bool testToInfoIdeal(void) { - const char* info = toInfo(1400); +bool testToInfoOkay(void) { + assertTrue(0 == strcmp(toInfo(1900), OKAY)); + assertTrue(0 == strcmp(toInfo(1700), OKAY)); + assertTrue(0 == strcmp(toInfo(1501), OKAY)); - return ! strcmp(info, IDEAL); + return true; +} + +bool testToInfoIdeal(void) { + assertTrue(0 == strcmp(toInfo(1500), IDEAL)); + assertTrue(0 == strcmp(toInfo(1400), IDEAL)); + assertTrue(0 == strcmp(toInfo(1300), IDEAL)); + + return true; } bool testToInfoRich(void) { @@ -310,6 +320,7 @@ {"sensors", "testLookupLinInterBelow", testLookupLinInterBelow}, {"sensors", "testLookupLinInterAbove", testLookupLinInterAbove}, {"sensors", "testToInfoLean", testToInfoLean}, + {"sensors", "testToInfoOkay", testToInfoOkay}, {"sensors", "testToInfoIdeal", testToInfoIdeal}, {"sensors", "testToInfoRich", testToInfoRich} }; diff --git a/lambda/sensors.c b/lambda/sensors.c index 66ab571..0b0696b 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -79,15 +79,6 @@ int32_t lambdaVoltage = divRoundNearest(getVoltage(PC2), 11); lambdaVoltageAvg = average((lambdaVoltage << 4), lambdaVoltageAvg, 4); - // TODO just for testing, remove at some point - char log[64]; - snprintf(log, sizeof(log), - "Ti %3d C %4ld - To %3d C %4ld - L %4ld\r\n", - toTempI(tempIVoltage), tempIVoltage, - toTempO(tempOVoltage), tempOVoltage, - lambdaVoltage); - // printString(log); - measurement meas; meas.tempIVoltage = divRoundNearest(tempIVoltageAvg, 16); meas.tempOVoltage = divRoundNearest(tempOVoltageAvg, 16); @@ -101,19 +92,20 @@ } void display(measurement meas) { - div_t lambdaT = div(meas.lambda, 1000); + uint8_t lambdax10 = divRoundNearest(meas.lambda, 100); + div_t lambdaT = div(lambdax10, 10); char log[64]; snprintf(log, sizeof(log), - "Ti %3d C %4d - To %3d C %4d - L %d.%03d %4d\r\n", + "Ti %3d C %4d - To %3d C %4d - L %4d %4d\r\n", meas.tempI, meas.tempIVoltage, meas.tempO, meas.tempOVoltage, - lambdaT.quot, abs(lambdaT.rem), meas.lambdaVoltage); + meas.lambda, meas.lambdaVoltage); printString(log); char line0[17]; char line1[17]; snprintf(line0, sizeof(line0), "Ti %3dC To %3dC ", meas.tempI, meas.tempO); - snprintf(line1, sizeof(line1), "L %d.%03d %s ", + snprintf(line1, sizeof(line1), "L %d.%01d %s ", lambdaT.quot, abs(lambdaT.rem), toInfo(meas.lambda)); lcd_setcursor(0, 1); lcd_string(line0); @@ -168,9 +160,11 @@ } const char* toInfo(int16_t lambda) { - if (lambda > 1500) { + if (lambda > 1900) { return LEAN; - } else if (lambda > 1300 && lambda <= 1500) { + } else if (lambda > 1500 && lambda <= 1900) { + return OKAY; + } else if (lambda >= 1300 && lambda <= 1500) { return IDEAL; } else { return RICH; diff --git a/lambda/sensors.h b/lambda/sensors.h index 6aed6e2..cd44d69 100644 --- a/lambda/sensors.h +++ b/lambda/sensors.h @@ -14,6 +14,7 @@ // TODO put in Makefile? #define LEAN "Mager" +#define OKAY "Okay " #define IDEAL "Ideal" #define RICH "Fett!"