smart variable header

This commit is contained in:
Siwat Sirichai 2024-03-23 02:09:50 +07:00
parent c56a98f823
commit aa28ec88fb
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
#pragma once
#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 {
public:
SmartVariable();
~SmartVariable();
void begin(size_t size);
void enableIoT(ESPMegaIoT* iot, const char* topic);
void enableValueRequest(const char* valueRequestTopic);
void setValue(const char* value);
char* getValue();
void enableSetValue(const char* setValueTopic);
void publishValue();
void bindFRAM(uint32_t framAddress);
void loadValue();
void saveValue();
void setValueAutoSave(bool autoSave);
uint16_t registerCallback(void (*callback)(char*));
void unregisterCallback(uint16_t handlerId);
protected:
ESPMegaIoT* iot;
const char* topic;
char* value;
size_t size;
bool useValueRequest;
const char* valueRequestTopic;
bool setValueEnabled;
const char* setValueTopic;
bool autoSave;
FRAM fram;
uint32_t framAddress;
void handleMqttCallback(char* topic, char* payload);
// Value Change Callback
uint16_t currentHandlerId;
std::map<uint16_t, void (*)(char*)> valueChangeCallbacks;
};