FEATURE: simple pointer based config linking

This commit is contained in:
Robin Dietzel 2023-01-05 11:45:24 +01:00
parent 5c60217399
commit a5e601d180
7 changed files with 72 additions and 29 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 "27146c9" #define GIT_HASH "2e389ce"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -11,8 +11,7 @@
#include "Menu_Entry_Type_Numeric.h" #include "Menu_Entry_Type_Numeric.h"
#include "Menu_Entry_Type_Percent.h" #include "Menu_Entry_Type_Percent.h"
#include "Menu_Entry_Type_Time.h" #include "Menu_Entry_Type_Time.h"
#include "Config_Entry_Type.h" #include "Config_Store.h"
#define SLAVE_ADDRESS_LCD 0x4e #define SLAVE_ADDRESS_LCD 0x4e
@ -20,9 +19,10 @@ ADC_HandleTypeDef hadc1;
I2C_HandleTypeDef hi2c1; I2C_HandleTypeDef hi2c1;
RTC_HandleTypeDef hrtc; RTC_HandleTypeDef hrtc;
TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim2;
UART_HandleTypeDef huart1; UART_HandleTypeDef huart1;
void SystemClock_Config(void); void SystemClock_Config(void);
static void MX_GPIO_Init(void); static void MX_GPIO_Init(void);
@ -41,6 +41,8 @@ extern int16_t rot_counter;
extern bool rot_button; extern bool rot_button;
int main(void) { int main(void) {
floatpump::Config_Store *globalConfig = new floatpump::Config_Store();
// Step 1: Initialize HAL // Step 1: Initialize HAL
HAL_Init(); HAL_Init();
@ -85,11 +87,13 @@ int main(void) {
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);
Menu_Entry entry(&entry1bool, "test"); Menu_Entry entry(&entry1bool, "test");
Menu_Entry_Type_Percent entry1perc(15); Menu_Entry_Type_Percent entry1perc(15);
Menu_Entry entry2(&entry1perc, "Prozent"); Menu_Entry entry2(&entry1perc, "Prozent");
@ -121,6 +125,12 @@ int main(void) {
old_pos = rot_counter; old_pos = rot_counter;
} }
HAL_Delay(100); HAL_Delay(100);
if(globalConfig->testBool) {
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_RESET);
}
} }
} }

View File

@ -0,0 +1,24 @@
//
// Created by robtor on 05.01.23.
//
#ifndef FLOATPUMP_CONFIG_STORE_H
#define FLOATPUMP_CONFIG_STORE_H
#include <chrono>
namespace floatpump {
class Config_Store {
public:
void saveToFlash();
void resetDefaults();
void loadFromFlash();
bool testBool = false;
bool testPercent;
};
} // floatpump
#endif //FLOATPUMP_CONFIG_STORE_H

View File

@ -6,7 +6,6 @@
#define FLOATPUMP_MENU_ENTRY_H #define FLOATPUMP_MENU_ENTRY_H
#include <Menu_Entry_Type_Delegate.h> #include <Menu_Entry_Type_Delegate.h>
#include <Config_Entry_Delegate.h>
namespace floatpump { namespace floatpump {
@ -15,7 +14,6 @@ namespace floatpump {
class Menu_Entry { class Menu_Entry {
public: public:
menu::Menu_Entry_Type_Delegate *m_type; menu::Menu_Entry_Type_Delegate *m_type;
config::Config_Entry_Delegate *m_config;
Menu_Entry(Menu_Entry_Type_Delegate *type, std::string name) : m_type(type), m_name(name) {}; Menu_Entry(Menu_Entry_Type_Delegate *type, std::string name) : m_type(type), m_name(name) {};

View File

@ -6,22 +6,22 @@
#define FLOATPUMP_MENU_ENTRY_TYPE_CHECKABLE_H #define FLOATPUMP_MENU_ENTRY_TYPE_CHECKABLE_H
#include "Menu_Entry_Type_Delegate.h" #include "Menu_Entry_Type_Delegate.h"
#include "Config_Entry_Type.h"
namespace floatpump { namespace floatpump {
namespace menu { namespace menu {
class Menu_Entry_Type_Checkable : public Menu_Entry_Type_Delegate { class Menu_Entry_Type_Checkable : public Menu_Entry_Type_Delegate {
public: public:
Menu_Entry_Type_Checkable(bool mState) Menu_Entry_Type_Checkable(bool mState) {
: m_state(mState) {} m_state = new bool(mState);
}
std::string toString() override { std::string toString() override {
return std::string((m_state) ? "ON " : "OFF"); return std::string((*m_state) ? "ON " : "OFF");
} }
void u_press() override { void u_press() override {
m_state = !m_state; *m_state = !(*m_state);
} }
void u_increase(uint16_t steps) override { void u_increase(uint16_t steps) override {
@ -36,8 +36,12 @@ namespace floatpump {
return false; return false;
} }
void linkConfig(bool *link) {
m_state = link;
}
private: private:
bool m_state = false; bool *m_state;
}; };
} // floatpump } // floatpump

View File

@ -6,7 +6,6 @@
#define FLOATPUMP_MENU_ENTRY_DELEGATE_H #define FLOATPUMP_MENU_ENTRY_DELEGATE_H
#include <string> #include <string>
#include "Config_Entry_Delegate.h"
namespace floatpump { namespace floatpump {
namespace menu { namespace menu {

View File

@ -0,0 +1,8 @@
//
// Created by robtor on 05.01.23.
//
#include "Config_Store.h"
namespace floatpump {
} // floatpump