From aa28ec88fba87b3c4e0b389b20bdff95f236b3bb Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 23 Mar 2024 02:09:50 +0700 Subject: [PATCH] smart variable header --- .../lib/ESPMegaPRO/SmartVariable.hpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/SmartVariable.hpp diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/SmartVariable.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/SmartVariable.hpp new file mode 100644 index 0000000..3af1eb8 --- /dev/null +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/SmartVariable.hpp @@ -0,0 +1,43 @@ +#pragma once +#include +#include +#include +/** + * @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 valueChangeCallbacks; +}; \ No newline at end of file