FEATURE: more standardized config storage with additional subclass
This commit is contained in:
parent
a5e601d180
commit
13fdacfcec
@ -7,6 +7,6 @@
|
||||
|
||||
// Auto generated header file containing the last git revision
|
||||
|
||||
#define GIT_HASH "2e389ce"
|
||||
#define GIT_HASH "d25705d"
|
||||
|
||||
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H
|
@ -40,8 +40,10 @@ static void MX_USART1_UART_Init(void);
|
||||
extern int16_t rot_counter;
|
||||
extern bool rot_button;
|
||||
|
||||
using namespace floatpump;
|
||||
|
||||
int main(void) {
|
||||
floatpump::Config_Store *globalConfig = new floatpump::Config_Store();
|
||||
Config_Store globalConfig;
|
||||
|
||||
// Step 1: Initialize HAL
|
||||
HAL_Init();
|
||||
@ -79,17 +81,17 @@ int main(void) {
|
||||
|
||||
//Disable Interrupt for Debouncing timer during display initalisation (exact timings are necessary)
|
||||
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);
|
||||
|
||||
floatpump::InitSequence initializer(display);
|
||||
InitSequence initializer(display);
|
||||
initializer.runInitSequence();
|
||||
|
||||
|
||||
using namespace floatpump::menu;
|
||||
Menu mainmenu(display);
|
||||
Menu_Entry_Type_Checkable entry1bool(true);
|
||||
entry1bool.linkConfig(&globalConfig->testBool);
|
||||
entry1bool.linkConfig(globalConfig.testbool.getLink());
|
||||
Menu_Entry entry(&entry1bool, "test");
|
||||
|
||||
|
||||
@ -126,7 +128,7 @@ int main(void) {
|
||||
}
|
||||
HAL_Delay(100);
|
||||
|
||||
if(globalConfig->testBool) {
|
||||
if(globalConfig.testbool.getValue()) {
|
||||
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_SET);
|
||||
} else {
|
||||
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_RESET);
|
||||
|
@ -11,12 +11,33 @@ namespace floatpump {
|
||||
|
||||
class Config_Store {
|
||||
public:
|
||||
Config_Store();
|
||||
void saveToFlash();
|
||||
void resetDefaults();
|
||||
void loadFromFlash();
|
||||
|
||||
bool testBool = false;
|
||||
bool testPercent;
|
||||
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<bool> testbool = Config_Object<bool>(false);
|
||||
};
|
||||
|
||||
} // floatpump
|
||||
|
@ -5,4 +5,7 @@
|
||||
#include "Config_Store.h"
|
||||
|
||||
namespace floatpump {
|
||||
Config_Store::Config_Store() {
|
||||
|
||||
}
|
||||
} // floatpump
|
Loading…
Reference in New Issue
Block a user