smart variable implementation

This commit is contained in:
Siwat Sirichai 2024-03-23 10:25:16 +07:00
parent aa28ec88fb
commit 7f55e3544d
3 changed files with 183 additions and 8 deletions

View file

@ -2,9 +2,9 @@
#include <FRAM.h>
#include <ESPMegaIoT.hpp>
#include <map>
/**
* @brief SmartVariable is a local variable that can be accessed remotely and have FRAM support
*
*/
class SmartVariable {
@ -18,14 +18,20 @@ public:
char* getValue();
void enableSetValue(const char* setValueTopic);
void publishValue();
void bindFRAM(uint32_t framAddress);
void bindFRAM(FRAM *fram, uint32_t framAddress);
void bindFRAM(FRAM *fram, uint32_t framAddress, bool loadValue);
void loadValue();
void saveValue();
void setValueAutoSave(bool autoSave);
uint16_t registerCallback(void (*callback)(char*));
void unregisterCallback(uint16_t handlerId);
int32_t getIntValue();
void setIntValue(int32_t value);
double getDoubleValue();
void setDoubleValue(double value);
protected:
ESPMegaIoT* iot;
bool iotEnabled;
const char* topic;
char* value;
size_t size;
@ -34,9 +40,10 @@ protected:
bool setValueEnabled;
const char* setValueTopic;
bool autoSave;
FRAM fram;
FRAM *fram;
uint32_t framAddress;
void handleMqttCallback(char* topic, char* payload);
void subscribeMqtt();
// Value Change Callback
uint16_t currentHandlerId;
std::map<uint16_t, void (*)(char*)> valueChangeCallbacks;