diff --git a/lambda-test/command-test.c b/lambda-test/command-test.c index 6187f5d..145bf32 100644 --- a/lambda-test/command-test.c +++ b/lambda-test/command-test.c @@ -18,8 +18,6 @@ /* Module command */ bool testIsSimulation(void) { - extern bool updatePending; - setupPorts(); setHeatingOn(false); @@ -33,28 +31,20 @@ assertTrue(getTime() == 0); // assertFalse(isHeatingOn()); - assertTrue(updatePending); - return true; } bool testIsLogging(void) { - extern bool updatePending; - assertFalse(isLogging()); runCommand("le"); assertTrue(isLogging()); runCommand("ld"); assertFalse(isLogging()); - assertTrue(updatePending); - return true; } bool testHeating(void) { - extern bool updatePending; - setupPorts(); setHeatingOn(false); @@ -64,23 +54,18 @@ runCommand("hd"); assertFalse(isHeatingOn()); - assertTrue(updatePending); - return true; } bool testCycleDisplay(void) { extern uint8_t position; - extern bool updatePending; cancelAlert(true); assertTrue(position == 0); - cycleDisplay(); + runCommand("cm"); assertTrue(position == 1); - assertTrue(updatePending); - return true; } diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index e47a3e6..b761b16 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -35,16 +35,16 @@ extern TestClass usartClass; beginSuite("lambda"); - runClass(adcClass); - runClass(alertClass); - runClass(commandClass); - runClass(displayClass); - runClass(integersClass); - runClass(interruptsClass); +// runClass(adcClass); +// runClass(alertClass); +// runClass(commandClass); +// runClass(displayClass); +// runClass(integersClass); +// runClass(interruptsClass); runClass(rulesClass); - runClass(sensorsClass); - runClass(stringsClass); - runClass(usartClass); +// runClass(sensorsClass); +// runClass(stringsClass); +// runClass(usartClass); endSuite(); while (1) { diff --git a/lambda-test/rules-test.c b/lambda-test/rules-test.c index 8d67a7c..c40f504 100644 --- a/lambda-test/rules-test.c +++ b/lambda-test/rules-test.c @@ -219,6 +219,45 @@ return true; } +bool testHeatingReady(void) { + + resetRules(); + Measurement meas = {0, 0, 0}; + dir = 1; + + + + cancelAlert(false); + + return true; +} + +bool testHeatingFault(void) { + + resetRules(); + Measurement meas = {0, 0, 0}; + dir = 1; + + + + cancelAlert(false); + + return true; +} + +bool testHeatingTimeout(void) { + + resetRules(); + Measurement meas = {0, 0, 0}; + dir = 1; + + + + cancelAlert(false); + + return true; +} + bool testReasonDirBurnUp(void) { resetRules(); @@ -334,6 +373,9 @@ static const char testAirgateClose_P[] PROGMEM = "testAirgateClose"; static const char testTooRich_P[] PROGMEM = "testTooRich"; static const char testFireOut_P[] PROGMEM = "testFireOut"; +static const char testHeatingReady_P[] PROGMEM = "testHeatingReady"; +static const char testHeatingFault_P[] PROGMEM = "testHeatingFault"; +static const char testHeatingTimeout_P[] PROGMEM = "testHeatingTimeout"; static const char testReasonDirBurnUp_P[] PROGMEM = "testReasonDirBurnUp"; static const char testReasonDirBurnDown_P[] PROGMEM = "testReasonDirBurnDown"; @@ -344,6 +386,9 @@ {class, testAirgateClose_P, testAirgateClose}, {class, testTooRich_P, testTooRich}, {class, testFireOut_P, testFireOut}, + {class, testHeatingReady_P, testHeatingReady}, + {class, testHeatingFault_P, testHeatingFault}, + {class, testHeatingTimeout_P, testHeatingTimeout}, {class, testReasonDirBurnUp_P, testReasonDirBurnUp}, {class, testReasonDirBurnDown_P, testReasonDirBurnDown} }; diff --git a/lambda-test/sensors-test.c b/lambda-test/sensors-test.c index bfb20f1..eb57a3e 100644 --- a/lambda-test/sensors-test.c +++ b/lambda-test/sensors-test.c @@ -50,8 +50,7 @@ assertTrue(meas.tempI >= 980 && meas.tempI <= 1000); assertTrue(meas.tempO == 400); assertTrue(meas.lambda >= 995 && meas.lambda <= 999); - // 5000 * (1000 / SHUNT_MILLIOHMS) = 45045 - assertTrue(meas.current >= 44500 && meas.current <= 45100); + assertTrue(meas.current >= 49500 && meas.current <= 50000); return true; } @@ -110,6 +109,12 @@ return temp == 50; } +bool testToCurrent(void) { + uint16_t current = toCurrent(150); + + return current == 1500 / SHUNT_MILLIOHMS * 100; +} + bool testLookupLinInterBelow(void) { int16_t value = lookupLinInter(0, testTable, 2); @@ -134,6 +139,24 @@ return value == 15; } +bool testLinADCLow(void) { + int32_t lin = linADC(1000); + + return lin == 1004; +} + +bool testLinADCMid(void) { + int32_t lin = linADC(2000); + + return lin == 2000; +} + +bool testLinADCHigh(void) { + int32_t lin = linADC(4000); + + return lin == 3992; +} + bool testToInfoLean(void) { char* info = toInfo(191); @@ -162,6 +185,29 @@ return ! strcmp(info, MSG_RICH); } +bool testSetHeatingOn(void) { + setHeatingOn(true); + assertTrue(isHeatingOn()); + assertTrue(HEATING_UP == getHeatingState()); + + setHeatingOn(false); + assertFalse(isHeatingOn()); + assertTrue(HEATING_OFF == getHeatingState()); + + return true; +} + +bool testSetHeatingState(void) { + setHeatingOn(false); + assertFalse(isHeatingOn()); + assertTrue(HEATING_OFF == getHeatingState()); + + setHeatingState(HEATING_FAULT); + assertTrue(HEATING_FAULT == getHeatingState()); + + return true; +} + /* Test "class" */ static const char class[] PROGMEM = "sensors"; @@ -174,14 +220,20 @@ static const char testToTempI_P[] PROGMEM = "testToTempI"; static const char testToTempOValue_P[] PROGMEM = "testToTempOValue"; static const char testToTempOInter_P[] PROGMEM = "testToTempOInter"; +static const char testToCurrent_P[] PROGMEM = "testToCurrent"; static const char testLookupLinInterValue_P[] PROGMEM = "testLookupLinInterValue"; static const char testLookupLinInterInter_P[] PROGMEM = "testLookupLinInterInter"; static const char testLookupLinInterBelow_P[] PROGMEM = "testLookupLinInterBelow"; static const char testLookupLinInterAbove_P[] PROGMEM = "testLookupLinInterAbove"; +static const char testLinADCLow_P[] PROGMEM = "testLinADCLow"; +static const char testLinADCMid_P[] PROGMEM = "testLinADCMid"; +static const char testLinADCHigh_P[] PROGMEM = "testLinADCHigh"; static const char testToInfoLean_P[] PROGMEM = "testToInfoLean"; static const char testToInfoOkay_P[] PROGMEM = "testToInfoOkay"; static const char testToInfoIdeal_P[] PROGMEM = "testToInfoIdeal"; static const char testToInfoRich_P[] PROGMEM = "testToInfoRich"; +static const char testSetHeatingOn_P[] PROGMEM = "testSetHeatingOn"; +static const char testSetHeatingState_P[] PROGMEM = "testSetHeatingState"; /* Tests */ static TestCase const tests[] = { @@ -193,14 +245,20 @@ {class, testToTempI_P, testToTempI}, {class, testToTempOValue_P, testToTempOValue}, {class, testToTempOInter_P, testToTempOInter}, + {class, testToCurrent_P, testToCurrent}, {class, testLookupLinInterValue_P, testLookupLinInterValue}, {class, testLookupLinInterInter_P, testLookupLinInterInter}, {class, testLookupLinInterBelow_P, testLookupLinInterBelow}, {class, testLookupLinInterAbove_P, testLookupLinInterAbove}, + {class, testLinADCLow_P, testLinADCLow}, + {class, testLinADCMid_P, testLinADCMid}, + {class, testLinADCHigh_P, testLinADCHigh}, {class, testToInfoLean_P, testToInfoLean}, {class, testToInfoOkay_P, testToInfoOkay}, {class, testToInfoIdeal_P, testToInfoIdeal}, {class, testToInfoRich_P, testToInfoRich}, + {class, testSetHeatingOn_P, testSetHeatingOn}, + {class, testSetHeatingState_P, testSetHeatingState} }; TestClass sensorsClass = {tests, sizeof(tests) / sizeof(tests[0])}; diff --git a/lambda/TODO b/lambda/TODO index 6ad4581..bfcc46b 100644 --- a/lambda/TODO +++ b/lambda/TODO @@ -11,4 +11,11 @@ - Look at oxygen sensor voltage with voltmeter/oscilloscope - is the voltage really so unstable? - Put button and beeper pins in pins.h (watch out with OCR1A) -- AVCC should be connected to VCC via an LC network \ No newline at end of file +- AVCC should be connected to VCC via an LC network + +* Release/put in Makefile? +- Makefile: LANG = 0 +- pins.h LCD pins +- interrupts.h: INTS_PER_SEC 61 +- sensors.h: SHUNT_MILLIOHMS 100 +- rules.c: heatingTimeout(): getTime() >= 10800 \ No newline at end of file diff --git a/lambda/command.c b/lambda/command.c index a862d0b..14b8216 100644 --- a/lambda/command.c +++ b/lambda/command.c @@ -34,7 +34,7 @@ } void runCommand(char* const data) { - size_t fieldCount = 8; + uint8_t fieldCount = 8; char* fields[fieldCount]; split(data, " ", fields, fieldCount); if (strcmp_P(fields[0], PSTR("se")) == 0) { diff --git a/lambda/display.c b/lambda/display.c index 2975e7d..3a03c21 100644 --- a/lambda/display.c +++ b/lambda/display.c @@ -79,8 +79,7 @@ div_t ampsT = div(ampsx100, 100); char line1[17]; - snprintf(line1, sizeof(line1), "%d.%02dA", - ampsT.quot, abs(ampsT.rem)); + snprintf(line1, sizeof(line1), "%d.%02dA", ampsT.quot, abs(ampsT.rem)); setText(MSG_HEATING_CURRENT, line1); } diff --git a/lambda/lambda.c b/lambda/lambda.c index 67d3356..ddcbefe 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -61,11 +61,11 @@ if (! isSimulation() && getInts() >= ints + INTS_PER_SEC) { ints = getInts(); meas = measure(); + updateMeas(meas); + reason(meas); if (isLogging()) { logMeas(meas); } - updateMeas(meas); - reason(meas); } if (! isSimulation()) { updateDisplayIfPending(); diff --git a/lambda/rules.c b/lambda/rules.c index 778b24a..9bad3f5 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -121,8 +121,8 @@ return; } if (meas.current > HEATING_SHORT_MA || meas.current < HEATING_DISCONN_MA || - (getTime() > 120 && meas.current > HEATING_READY_MA)) { - // short circuit or disconnected or did not warm up within 2 minutes + (getTime() >= 180 && meas.current > HEATING_READY_MA)) { + // short circuit or disconnected or did not warm up within 3 minutes setHeatingOn(false); setHeatingState(HEATING_FAULT); alert_P(BEEPS, LENGTH, TONE, PSTR(MSG_HEATING_FAULT_0), @@ -188,7 +188,7 @@ // try to figure out if the fire is building up or burning down by // comparing current measurements with ones that are 3 minutes old. - if (age >= 179) { + if (age >= 180) { dir = DIR_NONE; if ((meas.tempI - rulesMeasPrev.tempI) >= 10 && rulesMeasMax.tempI < 800 && meas.lambda >= 2000) { diff --git a/lambda/sensors.h b/lambda/sensors.h index c6d6056..145d352 100644 --- a/lambda/sensors.h +++ b/lambda/sensors.h @@ -14,7 +14,7 @@ #include /* 0.1 Ohm 10% measured 0.111 Ohm */ -#define SHUNT_MILLIOHMS 111 +#define SHUNT_MILLIOHMS 100 #define HEATING_READY_MA 1400 #define HEATING_SHORT_MA 7500 #define HEATING_DISCONN_MA 100