diff --git a/lambda/command.c b/lambda/command.c index fcd9d56..205f33e 100644 --- a/lambda/command.c +++ b/lambda/command.c @@ -96,13 +96,17 @@ } beep(1, length, tone); } - else if (simulation) { + else if (strcmp_P(fields[4], PSTR("!")) == 0 && simulation) { + // add one second per measurement to the timebase, + // assuming one measurement was logged per second + addInts(INTS_PER_SEC); Measurement meas = readMeas(fields, fieldCount); if (getHeatingState() == HEATING_OFF || getHeatingState() == HEATING_READY) { updateMeas(meas); } reason(meas); + updateDisplayIfPending(); } } diff --git a/lambda/interrupts.c b/lambda/interrupts.c index 7e89b81..cb8b1fc 100644 --- a/lambda/interrupts.c +++ b/lambda/interrupts.c @@ -13,6 +13,7 @@ #include #include #include +#include "command.h" #include "interrupts.h" #include "sensors.h" #include "display.h" @@ -25,7 +26,9 @@ * Called about every 16.4 ms. */ ISR(TIMER0_OVF_vect) { - ints++; + if (! isSimulation()) { + ints++; + } oscillateBeep(); if (bit_is_clear(PINB, PB0) && ! buttonPressed) { buttonPressed = true; @@ -43,6 +46,12 @@ return atomicInts; } +void addInts(uint8_t const add) { + ATOMIC_BLOCK(ATOMIC_FORCEON) { + ints += add; + } +} + uint32_t getTime(void) { return getInts() / INTS_PER_SEC; } diff --git a/lambda/interrupts.h b/lambda/interrupts.h index 2a5c580..8b7c6cb 100644 --- a/lambda/interrupts.h +++ b/lambda/interrupts.h @@ -21,6 +21,12 @@ uint32_t getInts(void); /** + * Adds the given number of interrupts to the interrupt counter + * used as timebase. Useful only for simulation. + */ +void addInts(uint8_t add); + +/** * Returns the time in about seconds since last reset. */ uint32_t getTime(void); diff --git a/lambda/lambda.c b/lambda/lambda.c index ed8e528..31204eb 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -70,12 +70,14 @@ } reason(meas); } + if (! isSimulation()) { + updateDisplayIfPending(); + } if (isUSARTReceived()) { char data[64]; getUSARTData(data, sizeof(data)); runCommand(data); } - updateDisplayIfPending(); } // never reached diff --git a/lambda/sensors.c b/lambda/sensors.c index b084d6d..13768f3 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -195,7 +195,6 @@ } else { PORTB &= ~(1 << PB2); heatingState = HEATING_OFF; - // cancelAlert(true); } }