1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-26 00:21:27 +00:00

more reformating

This commit is contained in:
Lukas Bachschwell 2019-03-24 18:18:08 +01:00
parent 218ebc67d9
commit b66d41a98b

View File

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