80 lines
2.4 KiB
C++
80 lines
2.4 KiB
C++
//
|
|
// Created by robtor on 05.01.23.
|
|
//
|
|
|
|
#ifndef FLOATPUMP_CONFIG_STORE_H
|
|
#define FLOATPUMP_CONFIG_STORE_H
|
|
|
|
#include <chrono>
|
|
#include "stm32f4xx_hal.h"
|
|
|
|
namespace floatpump {
|
|
|
|
class Config_Store {
|
|
public:
|
|
Config_Store();
|
|
|
|
static uint32_t Flash_Write (uint32_t StartPageAddress, uint32_t Data, uint16_t n_words) {
|
|
static FLASH_EraseInitTypeDef EraseInitStruct;
|
|
uint32_t PAGEError;
|
|
int sofar=0;
|
|
|
|
HAL_FLASH_Unlock();
|
|
FLASH_Erase_Sector(FLASH_SECTOR_7, VOLTAGE_RANGE_1);
|
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, StartPageAddress, Data);
|
|
HAL_FLASH_Lock();
|
|
return 0;
|
|
}
|
|
|
|
void saveToFlash() {
|
|
Flash_Write(0x08060000, this->RefillBelow.getValue(), 0);
|
|
};
|
|
|
|
void resetDefaults();
|
|
|
|
void loadFromFlash() {
|
|
this->RefillBelow.setValue(*(uint32_t *)0x08060000);
|
|
};
|
|
|
|
template<class T>
|
|
class Config_Object {
|
|
public:
|
|
Config_Object(T initialValue) : m_data(initialValue) {};
|
|
|
|
T getValue() {
|
|
return m_data;
|
|
}
|
|
|
|
void setValue(T newValue) {
|
|
m_data = newValue;
|
|
}
|
|
|
|
T *getLink() {
|
|
return &m_data;
|
|
}
|
|
|
|
private:
|
|
T m_data;
|
|
};
|
|
|
|
Config_Object<uint16_t> TankCalibLow = Config_Object<uint16_t>(0);
|
|
Config_Object<uint16_t> TankCalibHigh = Config_Object<uint16_t>(65535);
|
|
Config_Object<uint8_t> TankMinLevel = Config_Object<uint8_t>(20);
|
|
Config_Object<uint8_t> TankHysteresis = Config_Object<uint8_t>(5);
|
|
Config_Object<uint32_t> TankCooldown = Config_Object<uint32_t>(5);
|
|
Config_Object<uint32_t> TankZeroLevelCM = Config_Object<uint32_t>(0);
|
|
Config_Object<uint32_t> TankFullLevelCM = Config_Object<uint32_t>(200);
|
|
Config_Object<bool> TankPumpInvert = Config_Object<bool>(false);
|
|
|
|
Config_Object<bool> RefillEnable = Config_Object<bool>(false);
|
|
Config_Object<bool> RefillBlockInvert = Config_Object<bool>(false);
|
|
Config_Object<bool> RefillBlockEnable = Config_Object<bool>(true);
|
|
Config_Object<uint8_t> RefillBelow = Config_Object<uint8_t>(false);
|
|
Config_Object<uint8_t> RefillHysteresis = Config_Object<uint8_t>(false);
|
|
Config_Object<uint32_t> RefillCooldown = Config_Object<uint32_t>(60);
|
|
};
|
|
|
|
} // floatpump
|
|
|
|
#endif //FLOATPUMP_CONFIG_STORE_H
|