rotary and logic integrated, rotary not working good

This commit is contained in:
Wolfgang Hottgenroth
2017-05-31 17:45:45 +02:00
parent 209e1bd1c5
commit 56f96e5f26
17 changed files with 555 additions and 85 deletions

View File

@ -21,83 +21,10 @@
#include "stm32f1xx_hal.h"
#include "oled.h"
#include "timer.h"
#include "display.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:
;
}
}
extern tDisplay display;
void blink(void *handle) {
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
@ -105,11 +32,9 @@ void blink(void *handle) {
void my_setup_1() {
schInit();
schAdd(blink, NULL, 0, 100);
// schAdd(blink, NULL, 0, 100);
schAdd(updateDisplay, &display, 0, 250);
schAdd(secondTick, &display, 0, 1000);
display.timerState = STARTED;
}
void my_loop() {
@ -120,13 +45,13 @@ void HAL_SYSTICK_Callback() {
schUpdate();
}
void my_errorHandler() {
HAL_GPIO_WritePin(ERROR_GPIO_Port, ERROR_Pin, GPIO_PIN_SET);
}
void my_setup_2() {
LED_Init();
LED_P6x8Str(0,0,"welcome to");
}