mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-22 04:00:55 +00:00
more reformating
This commit is contained in:
parent
218ebc67d9
commit
b66d41a98b
137
src/ESPUI.h
137
src/ESPUI.h
@ -11,10 +11,10 @@
|
||||
|
||||
#if defined(ESP32)
|
||||
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include "SPIFFS.h"
|
||||
#include "WiFi.h"
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
#else
|
||||
|
||||
@ -97,17 +97,7 @@ enum ControlType : uint8_t {
|
||||
#define CLEAR_GRAPH ControlType::ClearGraph
|
||||
|
||||
// Colors
|
||||
enum ControlColor : uint8_t {
|
||||
Turquoise,
|
||||
Emerald,
|
||||
Peterriver,
|
||||
Wetasphalt,
|
||||
Sunflower,
|
||||
Carrot,
|
||||
Alizarin,
|
||||
Dark,
|
||||
None = 0xFF
|
||||
};
|
||||
enum ControlColor : uint8_t { Turquoise, Emerald, Peterriver, Wetasphalt, Sunflower, Carrot, Alizarin, Dark, None = 0xFF };
|
||||
#define COLOR_TURQUOISE ControlColor::Turquoise
|
||||
#define COLOR_EMERALD ControlColor::Emerald
|
||||
#define COLOR_PETERRIVER ControlColor::Peterriver
|
||||
@ -119,42 +109,29 @@ enum ControlColor : uint8_t {
|
||||
#define COLOR_NONE ControlColor::None
|
||||
|
||||
class Control {
|
||||
public:
|
||||
public:
|
||||
ControlType type;
|
||||
uint16_t id; // just mirroring the id here for practical reasons
|
||||
const char* label;
|
||||
void (*callback)(Control*, int);
|
||||
uint16_t id; // just mirroring the id here for practical reasons
|
||||
const char *label;
|
||||
void (*callback)(Control *, int);
|
||||
String value;
|
||||
ControlColor color;
|
||||
uint16_t parentControl;
|
||||
Control* next;
|
||||
Control *next;
|
||||
|
||||
static constexpr uint16_t noParent = 0xffff;
|
||||
|
||||
Control(ControlType type, const char* label, void (*callback)(Control*, int),
|
||||
String value, ControlColor color,
|
||||
Control(ControlType type, const char *label, void (*callback)(Control *, int), String value, ControlColor color,
|
||||
uint16_t parentControl = Control::noParent)
|
||||
: type(type),
|
||||
label(label),
|
||||
callback(callback),
|
||||
value(value),
|
||||
color(color),
|
||||
parentControl(parentControl),
|
||||
next(nullptr) {
|
||||
: type(type), label(label), callback(callback), value(value), color(color), parentControl(parentControl), next(nullptr) {
|
||||
id = idCounter++;
|
||||
}
|
||||
|
||||
Control(const Control& control)
|
||||
: type(control.type),
|
||||
id(control.id),
|
||||
label(control.label),
|
||||
callback(control.callback),
|
||||
value(control.value),
|
||||
color(control.color),
|
||||
parentControl(control.parentControl),
|
||||
next(control.next) {}
|
||||
Control(const Control &control)
|
||||
: type(control.type), id(control.id), label(control.label), callback(control.callback), value(control.value), color(control.color),
|
||||
parentControl(control.parentControl), next(control.next) {}
|
||||
|
||||
private:
|
||||
private:
|
||||
static uint16_t idCounter;
|
||||
};
|
||||
|
||||
@ -184,93 +161,63 @@ class Control {
|
||||
enum Verbosity : uint8_t { Quiet = 0, Verbose, VerboseJSON };
|
||||
|
||||
class ESPUIClass {
|
||||
public:
|
||||
public:
|
||||
ESPUIClass() { verbosity = Verbosity::Quiet; }
|
||||
´ void setVerbosity(Verbosity verbosity);
|
||||
void begin(const char *_title, const char *username = nullptr, const char *password = nullptr); // Setup server and page in Memorymode
|
||||
void beginSPIFFS(const char *_title, const char *username = nullptr, const char *password = nullptr); // Setup server and page in SPIFFSmode
|
||||
|
||||
void setVerbosity(Verbosity verbosity);
|
||||
// Setup server and page in Memorymode
|
||||
void begin(const char* _title, const char* username = nullptr,
|
||||
const char* password = nullptr);
|
||||
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS
|
||||
void list(); // Lists SPIFFS directory
|
||||
|
||||
// Setup server and page in SPIFFSmode
|
||||
void beginSPIFFS(const char* _title, const char* username = nullptr,
|
||||
const char* password = nullptr);
|
||||
uint16_t addControl(ControlType type, const char *label, String value = String(""), ControlColor color = ControlColor::Turquoise,
|
||||
uint16_t parentControl = Control::noParent, void (*callback)(Control *, int) = nullptr);
|
||||
|
||||
void prepareFileSystem(); // Initially preps the filesystem and loads a lot
|
||||
// of stuff into SPIFFS
|
||||
void list();
|
||||
// Creating Elements
|
||||
|
||||
uint16_t addControl(ControlType type, const char* label,
|
||||
String value = String(""),
|
||||
ControlColor color = ControlColor::Turquoise,
|
||||
uint16_t parentControl = Control::noParent,
|
||||
void (*callback)(Control*, int) = nullptr);
|
||||
|
||||
int button(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color,
|
||||
String value = ""); // Create Event Button
|
||||
int switcher(const char* label, bool startState,
|
||||
void (*callback)(Control*, int),
|
||||
ControlColor color); // Create Toggle Button
|
||||
int pad(const char* label, bool centerButton, void (*callback)(Control*, int),
|
||||
ControlColor color); // Create Pad Control
|
||||
int slider(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color, String value); // Create Slider Control
|
||||
int number(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color, int number, int min,
|
||||
int max); // Create a Number Input Control
|
||||
int text(const char* label, void (*callback)(Control*, int),
|
||||
ControlColor color,
|
||||
String value = ""); // Create a Text Input Control
|
||||
int button(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create Event Button
|
||||
int switcher(const char *label, bool startState, void (*callback)(Control *, int), ControlColor color); // Create Toggle Button
|
||||
int pad(const char *label, bool centerButton, void (*callback)(Control *, int), ControlColor color); // Create Pad Control
|
||||
int slider(const char *label, void (*callback)(Control *, int), ControlColor color, String value); // Create Slider Control
|
||||
int number(const char *label, void (*callback)(Control *, int), ControlColor color, int number, int min, int max); // Create a Number Input Control
|
||||
int text(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create a Text Input Control
|
||||
|
||||
// Output only
|
||||
int label(const char* label, ControlColor color,
|
||||
String value = ""); // Create Label
|
||||
int graph(const char* label, ControlColor color); // Create Graph display
|
||||
int label(const char *label, ControlColor color, String value = ""); // Create Label
|
||||
int graph(const char *label, ControlColor color); // Create Graph display
|
||||
|
||||
// Update Elements
|
||||
|
||||
Control* getControl(uint16_t id);
|
||||
Control *getControl(uint16_t id);
|
||||
|
||||
// Update Elements
|
||||
void updateControl(uint16_t id, String value, int clientId = -1);
|
||||
void updateControl(Control* control, String value, int clientId = -1);
|
||||
void updateControl(Control *control, String value, int clientId = -1);
|
||||
|
||||
void updateControl(uint16_t id, int clientId = -1);
|
||||
void updateControl(Control* control, int clientId = -1);
|
||||
void updateControl(Control *control, int clientId = -1);
|
||||
|
||||
void print(uint16_t id, String value);
|
||||
|
||||
void updateLabel(uint16_t id, String value);
|
||||
|
||||
void updateSwitcher(uint16_t id, bool nValue, int clientId = -1);
|
||||
|
||||
void updateSlider(uint16_t id, int nValue, int clientId = -1);
|
||||
|
||||
void updateNumber(uint16_t id, int nValue, int clientId = -1);
|
||||
|
||||
void updateText(uint16_t id, String nValue, int clientId = -1);
|
||||
|
||||
void updateSelect(uint16_t id, String nValue, int clientId = -1);
|
||||
|
||||
void clearGraph(uint16_t id, int clientId = -1);
|
||||
|
||||
void addGraphPoint(uint16_t id, int nValue, int clientId = -1);
|
||||
|
||||
// Variables ---
|
||||
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
|
||||
Control* controls = nullptr;
|
||||
void jsonDom(AsyncWebSocketClient* client);
|
||||
// Variables
|
||||
const char *ui_title = "ESPUI"; // Store UI Title and Header Name
|
||||
Control *controls = nullptr;
|
||||
void jsonDom(AsyncWebSocketClient *client);
|
||||
|
||||
Verbosity verbosity;
|
||||
|
||||
private:
|
||||
const char* basicAuthUsername = nullptr;
|
||||
const char* basicAuthPassword = nullptr;
|
||||
private:
|
||||
const char *basicAuthUsername = nullptr;
|
||||
const char *basicAuthPassword = nullptr;
|
||||
bool basicAuth = true;
|
||||
AsyncWebServer* server;
|
||||
AsyncWebSocket* ws;
|
||||
AsyncWebServer *server;
|
||||
AsyncWebSocket *ws;
|
||||
};
|
||||
|
||||
extern ESPUIClass ESPUI;
|
||||
|
Loading…
Reference in New Issue
Block a user