FEATURE: more standardized config storage with additional subclass

This commit is contained in:
Robin Dietzel 2023-01-05 12:19:36 +01:00
parent a5e601d180
commit 13fdacfcec
4 changed files with 34 additions and 8 deletions

View File

@ -7,6 +7,6 @@
// Auto generated header file containing the last git revision // Auto generated header file containing the last git revision
#define GIT_HASH "2e389ce" #define GIT_HASH "d25705d"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -40,8 +40,10 @@ static void MX_USART1_UART_Init(void);
extern int16_t rot_counter; extern int16_t rot_counter;
extern bool rot_button; extern bool rot_button;
using namespace floatpump;
int main(void) { int main(void) {
floatpump::Config_Store *globalConfig = new floatpump::Config_Store(); Config_Store globalConfig;
// Step 1: Initialize HAL // Step 1: Initialize HAL
HAL_Init(); HAL_Init();
@ -79,17 +81,17 @@ int main(void) {
//Disable Interrupt for Debouncing timer during display initalisation (exact timings are necessary) //Disable Interrupt for Debouncing timer during display initalisation (exact timings are necessary)
HAL_NVIC_DisableIRQ(TIM2_IRQn); HAL_NVIC_DisableIRQ(TIM2_IRQn);
floatpump::LCD_I2C_Driver &display = floatpump::LCD_I2C_Driver::getInstance(hi2c1, SLAVE_ADDRESS_LCD); LCD_I2C_Driver &display = floatpump::LCD_I2C_Driver::getInstance(hi2c1, SLAVE_ADDRESS_LCD);
HAL_NVIC_EnableIRQ(TIM2_IRQn); HAL_NVIC_EnableIRQ(TIM2_IRQn);
floatpump::InitSequence initializer(display); InitSequence initializer(display);
initializer.runInitSequence(); initializer.runInitSequence();
using namespace floatpump::menu; using namespace floatpump::menu;
Menu mainmenu(display); Menu mainmenu(display);
Menu_Entry_Type_Checkable entry1bool(true); Menu_Entry_Type_Checkable entry1bool(true);
entry1bool.linkConfig(&globalConfig->testBool); entry1bool.linkConfig(globalConfig.testbool.getLink());
Menu_Entry entry(&entry1bool, "test"); Menu_Entry entry(&entry1bool, "test");
@ -126,7 +128,7 @@ int main(void) {
} }
HAL_Delay(100); HAL_Delay(100);
if(globalConfig->testBool) { if(globalConfig.testbool.getValue()) {
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_SET);
} else { } else {
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_RESET);

View File

@ -11,12 +11,33 @@ namespace floatpump {
class Config_Store { class Config_Store {
public: public:
Config_Store();
void saveToFlash(); void saveToFlash();
void resetDefaults(); void resetDefaults();
void loadFromFlash(); void loadFromFlash();
bool testBool = false; template <class T>
bool testPercent; 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<bool> testbool = Config_Object<bool>(false);
}; };
} // floatpump } // floatpump

View File

@ -5,4 +5,7 @@
#include "Config_Store.h" #include "Config_Store.h"
namespace floatpump { namespace floatpump {
Config_Store::Config_Store() {
}
} // floatpump } // floatpump