operating time and eeprom handling
This commit is contained in:
parent
00a40d91ad
commit
ace2804b44
@ -8,7 +8,7 @@
|
||||
#include "eeprom.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "hmi.h"
|
||||
|
||||
#define HIGH GPIO_PIN_SET
|
||||
#define LOW GPIO_PIN_RESET
|
||||
@ -24,12 +24,20 @@ const uint8_t EEPROM_RDSR = 0x05;
|
||||
const uint8_t EEPROM_WRSR = 0x01;
|
||||
|
||||
|
||||
const uint32_t STORAGE_MAGIC = 0xaffe000b;
|
||||
|
||||
|
||||
|
||||
tStorage storage;
|
||||
extern tDisplay display;
|
||||
|
||||
|
||||
static void __EEPROM_CS(GPIO_PinState v) {
|
||||
HAL_GPIO_WritePin(EEPROM_CS_GPIO_Port, EEPROM_CS_Pin, v);
|
||||
}
|
||||
|
||||
|
||||
uint8_t eepromReadStatus() {
|
||||
static uint8_t eepromReadStatus() {
|
||||
struct {
|
||||
uint8_t rdsr;
|
||||
uint8_t data;
|
||||
@ -44,7 +52,7 @@ uint8_t eepromReadStatus() {
|
||||
return rxMsg.data;
|
||||
}
|
||||
|
||||
void eepromWren() {
|
||||
static void eepromWren() {
|
||||
struct {
|
||||
uint8_t wren;
|
||||
} txMsg = {
|
||||
@ -55,7 +63,8 @@ void eepromWren() {
|
||||
HAL_SPI_Transmit(&hspi1, &txMsg, 1, HAL_MAX_DELAY);
|
||||
__EEPROM_CS(HIGH);
|
||||
}
|
||||
void eepromWrdi() {
|
||||
|
||||
static void eepromWrdi() {
|
||||
struct {
|
||||
uint8_t wrdi;
|
||||
} txMsg = {
|
||||
@ -103,3 +112,23 @@ void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len) {
|
||||
|
||||
memcpy(buf, rxMsg.data, len);
|
||||
}
|
||||
|
||||
uint8_t eepromReadStorage() {
|
||||
eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
if (storage.magic == STORAGE_MAGIC) {
|
||||
display.targetTemperature = storage.savedTemperature;
|
||||
display.targetTime = storage.savedTime;
|
||||
display.operatingTime = storage.operatingTime;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void eepromWriteStorage() {
|
||||
storage.magic = STORAGE_MAGIC;
|
||||
storage.savedTemperature = display.targetTemperature;
|
||||
storage.savedTime = display.targetTime;
|
||||
storage.operatingTime = display.operatingTime;
|
||||
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
}
|
||||
|
@ -13,10 +13,19 @@
|
||||
|
||||
#define STORAGE_ADDRESS 0x20
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t savedTemperature;
|
||||
uint32_t savedTime;
|
||||
uint32_t operatingTime;
|
||||
} tStorage;
|
||||
|
||||
|
||||
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||
uint8_t eepromReadStatus();
|
||||
void eepromWren();
|
||||
void eepromWrdi();
|
||||
|
||||
void eepromWriteStorage();
|
||||
uint8_t eepromReadStorage();
|
||||
|
||||
#endif /* EEPROM_H_ */
|
||||
|
48
my_src/hmi.c
48
my_src/hmi.c
@ -16,7 +16,6 @@
|
||||
|
||||
|
||||
|
||||
const uint32_t STORAGE_MAGIC = 0xaffe000a;
|
||||
const uint8_t COLD_COUNT_THRESHOLD = 40;
|
||||
|
||||
const char THERMOMETER_STATE_MARKS[TE_LAST] = {'I', 'H', 'C', 'C', 'C', 'B'};
|
||||
@ -30,40 +29,31 @@ volatile tDisplay display = {
|
||||
.setState = TS_IDLE,
|
||||
.targetTemperature = 80, .currentTemperature = 75,
|
||||
.targetTime = 120, .currentTime = 0,
|
||||
.overrunTime = 0
|
||||
.overrunTime = 0,
|
||||
.operatingTime = 0
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t savedTemperature;
|
||||
uint32_t savedTime;
|
||||
} tStorage;
|
||||
|
||||
tStorage storage;
|
||||
|
||||
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);
|
||||
LED_P8x16Str(0, 0, 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);
|
||||
LED_P8x16Str(0, 2, buf);
|
||||
|
||||
|
||||
sprintf(buf, "%c %5ds", THERMOMETER_STATE_MARKS[lDisplay->thermometerEngineState], lDisplay->overrunTime);
|
||||
@ -73,6 +63,9 @@ void updateDisplay(void *handle) {
|
||||
// sprintf(buf, "%d %d %d", c, i, i-h);
|
||||
// h = i;
|
||||
// c++;
|
||||
LED_P8x16Str(0, 4, buf);
|
||||
|
||||
sprintf(buf, "%d", lDisplay->operatingTime);
|
||||
LED_P8x16Str(0, 6, buf);
|
||||
}
|
||||
|
||||
@ -125,19 +118,8 @@ static void thermometerEngineUnblock() {
|
||||
}
|
||||
|
||||
void hmiInit() {
|
||||
eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
if (storage.magic == STORAGE_MAGIC) {
|
||||
display.targetTemperature = storage.savedTemperature;
|
||||
display.targetTime = storage.savedTime;
|
||||
} else {
|
||||
storage.magic = STORAGE_MAGIC;
|
||||
storage.savedTemperature = 80;
|
||||
storage.savedTime = 90;
|
||||
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
|
||||
// eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
display.targetTemperature = storage.savedTemperature;
|
||||
display.targetTime = storage.savedTime;
|
||||
if (! eepromReadStorage()) {
|
||||
eepromWriteStorage();
|
||||
}
|
||||
|
||||
schAdd(thermometerEngine, &display, 0, 250);
|
||||
@ -189,16 +171,14 @@ void displayIncValue() {
|
||||
reEnableSetModeTimer();
|
||||
if (display.targetTemperature < 100) {
|
||||
display.targetTemperature++;
|
||||
storage.savedTemperature = display.targetTemperature;
|
||||
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
eepromWriteStorage();
|
||||
}
|
||||
}
|
||||
if (display.setModeTime == 1) {
|
||||
reEnableSetModeTimer();
|
||||
if (display.targetTime < 999) {
|
||||
display.targetTime += 10;
|
||||
storage.savedTime = display.targetTime;
|
||||
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
eepromWriteStorage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,16 +188,14 @@ void displayDecValue() {
|
||||
reEnableSetModeTimer();
|
||||
if (display.targetTemperature > 0) {
|
||||
display.targetTemperature--;
|
||||
storage.savedTemperature = display.targetTemperature;
|
||||
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
eepromWriteStorage();
|
||||
}
|
||||
}
|
||||
if (display.setModeTime == 1) {
|
||||
reEnableSetModeTimer();
|
||||
if (display.targetTime >= 10) {
|
||||
display.targetTime -= 10;
|
||||
storage.savedTime = display.targetTime;
|
||||
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||
eepromWriteStorage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ typedef struct {
|
||||
uint32_t targetTime;
|
||||
uint32_t currentTime;
|
||||
uint32_t overrunTime;
|
||||
uint32_t operatingTime;
|
||||
} tDisplay;
|
||||
|
||||
void hmiInit(void);
|
||||
|
@ -9,9 +9,10 @@
|
||||
#include "timer.h"
|
||||
#include "alarm.h"
|
||||
#include <PontCoopScheduler.h>
|
||||
#include "eeprom.h"
|
||||
|
||||
|
||||
|
||||
const uint8_t OPTIME_UPDATE_CYCLE = 10;
|
||||
extern tDisplay display;
|
||||
|
||||
void startTimer() {
|
||||
@ -25,6 +26,11 @@ void stopTimer() {
|
||||
void secondTick(void *handle) {
|
||||
tDisplay *lDisplay = (tDisplay*) handle;
|
||||
|
||||
lDisplay->operatingTime += 1;
|
||||
if (lDisplay->operatingTime % OPTIME_UPDATE_CYCLE == 0) {
|
||||
eepromWriteStorage();
|
||||
}
|
||||
|
||||
switch (lDisplay->timerState) {
|
||||
case TT_STARTED:
|
||||
lDisplay->currentTime = lDisplay->targetTime;
|
||||
|
Loading…
x
Reference in New Issue
Block a user