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