display state machine working
This commit is contained in:
@ -22,18 +22,94 @@
|
||||
|
||||
#include "oled.h"
|
||||
|
||||
typedef enum {
|
||||
IDLE = 0,
|
||||
STARTED = 1,
|
||||
RUNNING = 2,
|
||||
OVERRUN = 3
|
||||
} tTimerState;
|
||||
|
||||
typedef struct {
|
||||
uint8_t toggle;
|
||||
uint8_t setModeTemperature;
|
||||
uint8_t setModeTime;
|
||||
tTimerState timerState;
|
||||
uint32_t targetTemperature;
|
||||
uint32_t currentTemperature;
|
||||
uint32_t targetTime;
|
||||
uint32_t currentTime;
|
||||
uint32_t overrunTime;
|
||||
} tDisplay;
|
||||
|
||||
|
||||
tDisplay display = {
|
||||
.toggle = 0, .setModeTemperature = 0, .setModeTime = 0,
|
||||
.timerState = IDLE,
|
||||
.targetTemperature = 80, .currentTemperature = 75,
|
||||
.targetTime = 180, .currentTime = 175,
|
||||
.overrunTime = 0
|
||||
};
|
||||
|
||||
|
||||
void updateDisplay(void *handle) {
|
||||
tDisplay *lDisplay = (tDisplay*) handle;
|
||||
lDisplay->toggle ^= 0x01;
|
||||
char buf[32];
|
||||
|
||||
sprintf(buf, "ThermometerTeaTimer");
|
||||
LED_P6x8Str(0, 0, buf);
|
||||
|
||||
if (lDisplay->setModeTemperature && lDisplay->toggle) {
|
||||
sprintf(buf, " %3d'C", lDisplay->currentTemperature);
|
||||
} else {
|
||||
sprintf(buf, "%3d'C %3d'C", lDisplay->targetTemperature, lDisplay->currentTemperature);
|
||||
}
|
||||
LED_P8x16Str(0, 2, buf);
|
||||
|
||||
if (lDisplay->setModeTime && lDisplay->toggle) {
|
||||
sprintf(buf, " %3ds", lDisplay->currentTime);
|
||||
} else {
|
||||
sprintf(buf, "%3ds %3ds", lDisplay->targetTime, lDisplay->currentTime);
|
||||
}
|
||||
LED_P8x16Str(0, 4, buf);
|
||||
|
||||
sprintf(buf, " %5ds", lDisplay->overrunTime);
|
||||
LED_P8x16Str(0, 6, buf);
|
||||
}
|
||||
|
||||
void secondTick(void *handle) {
|
||||
tDisplay *lDisplay = (tDisplay*) handle;
|
||||
|
||||
switch (lDisplay->timerState) {
|
||||
case STARTED:
|
||||
lDisplay->currentTime = lDisplay->targetTime;
|
||||
lDisplay->timerState = RUNNING;
|
||||
break;
|
||||
case RUNNING:
|
||||
lDisplay->currentTime -= 1;
|
||||
if (lDisplay->currentTime == 0) {
|
||||
lDisplay->timerState = OVERRUN;
|
||||
}
|
||||
break;
|
||||
case OVERRUN:
|
||||
lDisplay->overrunTime += 1;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void blink(void *handle) {
|
||||
static uint32_t i = 0;
|
||||
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
||||
LED_PrintValueI(0, 1, i);
|
||||
i++;
|
||||
}
|
||||
|
||||
void my_setup_1() {
|
||||
schInit();
|
||||
schAdd(blink, NULL, 0, 100);
|
||||
schAdd(updateDisplay, &display, 0, 250);
|
||||
schAdd(secondTick, &display, 0, 1000);
|
||||
|
||||
display.timerState = STARTED;
|
||||
}
|
||||
|
||||
void my_loop() {
|
||||
|
Reference in New Issue
Block a user