1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-07-04 21:30:19 +00:00

Made Type and ID private and added accessors for them.

This commit is contained in:
Martin
2024-07-18 11:42:37 -04:00
parent 610ed1275e
commit bddcde4e57
3 changed files with 485 additions and 48 deletions

62
src/ESPUIcontrolMgr.h Normal file
View File

@ -0,0 +1,62 @@
#pragma once
#include <Arduino.h>
#include <ESPUI.h>
#include <ESPUIControl.h>
// implemented as a singleton
class _ESPUIcontrolMgr
{
public:
_ESPUIcontrolMgr();
~_ESPUIcontrolMgr() {}
_ESPUIcontrolMgr (_ESPUIcontrolMgr const&) = delete;
void operator=(_ESPUIcontrolMgr const&) = delete;
Control::ControlId_t addControl(Control::Type type,
const char* label,
const String& value,
Control::Color color,
Control::ControlId_t parentControl,
bool visible,
std::function<void(Control*, int)> callback);
bool removeControl(Control::ControlId_t id);
void RemoveToBeDeletedControls();
Control* getControl(Control::ControlId_t id);
Control* getControlNoLock(Control::ControlId_t id);
Control::ControlId_t GetControlCount() {return controlCount;}
uint32_t prepareJSONChunk(uint16_t startindex,
JsonDocument & rootDoc,
bool InUpdateMode,
String FragmentRequestString,
uint32_t CurrentSyncID);
private:
class ControlObject_t : public Control
{
public:
ControlObject_t(Control::ControlId_t id,
Type type,
const char* label,
std::function<void(Control*, int)> callback,
const String& value,
Color color,
bool visible,
uint16_t parentControl);
ControlObject_t * next = nullptr;
}; // ControlObject_t
ControlObject_t * controls = nullptr;
Control::ControlId_t controlCount = 0;
Control::ControlId_t idCounter = 0;
ControlObject_t * getControlObjectNoLock(Control::ControlId_t id);
#ifdef ESP32
SemaphoreHandle_t ControlsSemaphore = NULL;
#endif // def ESP32
};
extern _ESPUIcontrolMgr ESPUIcontrolMgr;