works so far

This commit is contained in:
Wolfgang Hottgenroth
2017-06-13 13:26:29 +02:00
parent 7be8afa297
commit cb6acce7bb
10 changed files with 138 additions and 10 deletions

View File

@ -92,7 +92,7 @@ void enableAlarm(tAlarmType alarmType) {
}
if (buzzerHandle.inUse == 0) {
buzzerHandle.inUse = 1;
schAdd(buzz, &buzzerHandle, 0, 10000);
schAdd(buzz, &buzzerHandle, 0, 30000);
}
}
@ -100,4 +100,5 @@ void disableAlarm() {
schDel(blink, NULL);
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, RESET);
schDel(buzz, &buzzerHandle);
buzzerHandle.inUse = 0;
}

View File

@ -12,10 +12,12 @@
#include <PontCoopScheduler.h>
#include "oled.h"
#include "eeprom.h"
#include "thermometer.h"
const uint32_t STORAGE_MAGIC = 0xaffe000a;
const uint8_t COLD_COUNT_THRESHOLD = 40;
@ -23,12 +25,15 @@ const uint32_t STORAGE_MAGIC = 0xaffe000a;
volatile tDisplay display = {
.toggle = 0, .setModeTemperature = 0, .setModeTime = 0,
.timerState = IDLE,
.thermometerEngineState = TE_IDLE,
.toggleModeState = 1,
.targetTemperature = 80, .currentTemperature = 75,
.targetTime = 120, .currentTime = 0,
.overrunTime = 0
};
typedef struct {
uint32_t magic;
uint32_t savedTemperature;
@ -59,6 +64,7 @@ void updateDisplay(void *handle) {
}
LED_P8x16Str(0, 4, buf);
sprintf(buf, " %5ds", lDisplay->overrunTime);
// static uint32_t h = 0;
// static uint32_t c = 0;
@ -69,6 +75,45 @@ void updateDisplay(void *handle) {
LED_P8x16Str(0, 6, buf);
}
void thermometerEngine(void *handle) {
tDisplay *lDisplay = (tDisplay*) handle;
lDisplay->currentTemperature = thermometerGetValue();
switch (lDisplay->thermometerEngineState) {
case TE_IDLE:
if (lDisplay->currentTemperature > lDisplay->targetTemperature) {
lDisplay->thermometerEngineState = TE_HOT;
lDisplay->coldCount = 0;
}
break;
case TE_HOT:
if (lDisplay->currentTemperature <= lDisplay->targetTemperature) {
lDisplay->coldCount += 1;
}
if (lDisplay->coldCount >= COLD_COUNT_THRESHOLD) {
lDisplay->thermometerEngineState = TE_COLD;
}
break;
case TE_COLD:
enableAlarm(TEMPERATURE_ALARM);
lDisplay->thermometerEngineState = TE_UNCONFIRMED;
break;
case TE_UNCONFIRMED:
break;
case TE_CONFIRMED:
disableAlarm();
lDisplay->thermometerEngineState = TE_IDLE;
break;
default:
lDisplay->thermometerEngineState = TE_IDLE;
}
}
void thermometerEngineConfirmAlarm() {
if (display.thermometerEngineState == TE_UNCONFIRMED) {
display.thermometerEngineState = TE_CONFIRMED;
}
}
void hmiInit() {
eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage));
@ -86,7 +131,8 @@ void hmiInit() {
display.targetTime = storage.savedTime;
}
schAdd(updateDisplay, &display, 0, 250);
schAdd(thermometerEngine, &display, 0, 250);
schAdd(updateDisplay, &display, 10, 250);
}
void clearSetMode(void *handle) {
@ -172,6 +218,7 @@ void buttonShort() {
toggleSetMode();
} else if (display.timerState == IDLE) {
startTimer();
thermometerEngineConfirmAlarm();
} else if (display.timerState == RUNNING || display.timerState == OVERRUN) {
stopTimer();
disableAlarm();

View File

@ -13,11 +13,16 @@
#include "stm32f1xx_hal.h"
typedef enum { TE_IDLE, TE_HOT, TE_COLD, TE_UNCONFIRMED, TE_CONFIRMED } tThermometerEngineState;
typedef struct {
uint32_t toggle;
uint32_t setModeTemperature;
uint32_t setModeTime;
tTimerState timerState;
tThermometerEngineState thermometerEngineState;
uint8_t coldCount;
uint32_t toggleModeState;
uint32_t targetTemperature;
uint32_t currentTemperature;

View File

@ -16,14 +16,15 @@
#include <hmi.h>
#include <stdlib.h>
#include <PontCoopScheduler.h>
#include "stm32f1xx_hal.h"
#include "hmi.h"
#include "oled.h"
#include "timer.h"
#include "alarm.h"
#include "thermometer.h"
void my_setup_1() {
@ -48,6 +49,7 @@ void my_setup_2() {
timerInit();
oledInit();
alarmInit();
thermometerInit();
}