2017-05-26 18:45:18 +02:00
|
|
|
/*
|
|
|
|
* main2.c
|
|
|
|
*
|
|
|
|
* Created on: Oct 21, 2016
|
|
|
|
* Author: wn
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1. insert #include "main2.h" at USER CODE Includes of main.c
|
|
|
|
* 2. insert my_setup_1(); at USER CODE 1 in main.c
|
|
|
|
* 3. insert my_setup_2(); at USER CODE 2 in main.c
|
|
|
|
* 4. insert my_loop(); at USER CODE 3 in main.c
|
|
|
|
* 5. insert my_errorHandler(); at USER CODE BEGIN Error_Handler in main.c
|
|
|
|
* All this is done by the script insertMyCode.sh in tools
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <PontCoopScheduler.h>
|
|
|
|
#include "stm32f1xx_hal.h"
|
|
|
|
|
2017-05-29 11:50:59 +02:00
|
|
|
#include "oled.h"
|
|
|
|
|
2017-05-29 13:49:52 +02:00
|
|
|
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);
|
|
|
|
}
|
2017-05-26 18:45:18 +02:00
|
|
|
|
2017-05-29 13:49:52 +02:00
|
|
|
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:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 18:45:18 +02:00
|
|
|
|
|
|
|
void blink(void *handle) {
|
|
|
|
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void my_setup_1() {
|
|
|
|
schInit();
|
|
|
|
schAdd(blink, NULL, 0, 100);
|
2017-05-29 13:49:52 +02:00
|
|
|
schAdd(updateDisplay, &display, 0, 250);
|
|
|
|
schAdd(secondTick, &display, 0, 1000);
|
|
|
|
|
|
|
|
display.timerState = STARTED;
|
2017-05-26 18:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void my_loop() {
|
|
|
|
schExec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_SYSTICK_Callback() {
|
|
|
|
schUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void my_errorHandler() {
|
2017-05-26 18:57:42 +02:00
|
|
|
HAL_GPIO_WritePin(ERROR_GPIO_Port, ERROR_Pin, GPIO_PIN_SET);
|
2017-05-26 18:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void my_setup_2() {
|
2017-05-29 11:50:59 +02:00
|
|
|
LED_Init();
|
|
|
|
LED_P6x8Str(0,0,"welcome to");
|
|
|
|
|
2017-05-26 18:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|