mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-22 04:00:55 +00:00
commit
37bbb9208d
58
.clang-format
Executable file
58
.clang-format
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
---
|
||||||
|
# Based on Webkit style
|
||||||
|
BasedOnStyle: Webkit
|
||||||
|
IndentWidth: 4
|
||||||
|
ColumnLimit: 120
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
Standard: Cpp11
|
||||||
|
# Pointers aligned to the left
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
PointerAlignment: Left
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: true
|
||||||
|
AfterEnum: true
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: true
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
AfterExternBlock: true
|
||||||
|
BeforeCatch: true
|
||||||
|
BeforeElse: true
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
FixNamespaceComments: true
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
IncludeCategories:
|
||||||
|
# C++ standard headers (no .h)
|
||||||
|
- Regex: '<[[:alnum:]_-]+>'
|
||||||
|
Priority: 1
|
||||||
|
# Extenal libraries (with .h)
|
||||||
|
- Regex: '<[[:alnum:]_./-]+>'
|
||||||
|
Priority: 2
|
||||||
|
# Headers from same folder
|
||||||
|
- Regex: '"[[:alnum:]_.-]+"'
|
||||||
|
Priority: 3
|
||||||
|
# Headers from other folders
|
||||||
|
- Regex: '"[[:alnum:]_/.-]+"'
|
||||||
|
Priority: 4
|
||||||
|
IndentCaseLabels: false
|
||||||
|
NamespaceIndentation: All
|
||||||
|
SortIncludes: true
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
UseTab: Never
|
396
src/ESPUI.cpp
396
src/ESPUI.cpp
File diff suppressed because it is too large
Load Diff
110
src/ESPUI.h
110
src/ESPUI.h
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
|
||||||
#include "LittleFS.h"
|
|
||||||
#include "WiFi.h"
|
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
|
#include "LittleFS.h"
|
||||||
|
#include "WiFi.h"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@ -23,8 +24,8 @@
|
|||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <LittleFS.h>
|
|
||||||
#include <Hash.h>
|
#include <Hash.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
#include <SPIFFSEditor.h>
|
#include <SPIFFSEditor.h>
|
||||||
|
|
||||||
#define FILE_WRITE "w"
|
#define FILE_WRITE "w"
|
||||||
@ -131,25 +132,38 @@ 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), String value, ControlColor color,
|
Control(ControlType type, const char* label, void (*callback)(Control*, int), const String& value,
|
||||||
uint16_t parentControl = Control::noParent)
|
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++;
|
id = idCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Control(const Control &control)
|
Control(const Control& control)
|
||||||
: type(control.type), id(control.id), label(control.label), callback(control.callback), value(control.value), color(control.color),
|
: type(control.type),
|
||||||
parentControl(control.parentControl), next(control.next) {}
|
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;
|
static uint16_t idCounter;
|
||||||
@ -200,72 +214,84 @@ public:
|
|||||||
bool sliderContinuous;
|
bool sliderContinuous;
|
||||||
|
|
||||||
void setVerbosity(Verbosity verbosity);
|
void setVerbosity(Verbosity verbosity);
|
||||||
void begin(const char *_title, const char *username = nullptr, const char *password = nullptr); // Setup server and page in Memorymode
|
void begin(const char* _title, const char* username = nullptr,
|
||||||
void beginSPIFFS(const char *_title, const char *username = nullptr, const char *password = nullptr); // Setup server and page in SPIFFSmode
|
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 prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS
|
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of
|
||||||
|
// stuff into SPIFFS
|
||||||
void list(); // Lists SPIFFS directory
|
void list(); // Lists SPIFFS directory
|
||||||
|
|
||||||
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);
|
uint16_t addControl(ControlType type, const char* label, const String& value = String(""),
|
||||||
|
ControlColor color = ControlColor::Turquoise, uint16_t parentControl = Control::noParent,
|
||||||
|
void (*callback)(Control*, int) = nullptr);
|
||||||
bool removeControl(uint16_t id, bool force_reload_ui = false);
|
bool removeControl(uint16_t id, bool force_reload_ui = false);
|
||||||
|
|
||||||
// create Elements
|
// create Elements
|
||||||
uint16_t button(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create Event Button
|
uint16_t button(const char* label, void (*callback)(Control*, int), ControlColor color,
|
||||||
uint16_t switcher(const char *label, void (*callback)(Control *, int), ControlColor color, bool startState = false); // Create Toggle Button
|
const String& value = ""); // Create Event Button
|
||||||
uint16_t pad(const char *label, void (*callback)(Control *, int), ControlColor color); // Create Pad Control
|
uint16_t switcher(const char* label, void (*callback)(Control*, int), ControlColor color,
|
||||||
uint16_t padWithCenter(const char *label, void (*callback)(Control *, int), ControlColor color); // Create Pad Control with Centerbutton
|
bool startState = false); // Create Toggle Button
|
||||||
|
uint16_t pad(const char* label, void (*callback)(Control*, int),
|
||||||
|
ControlColor color); // Create Pad Control
|
||||||
|
uint16_t padWithCenter(const char* label, void (*callback)(Control*, int),
|
||||||
|
ControlColor color); // Create Pad Control with Centerbutton
|
||||||
|
|
||||||
uint16_t slider(const char *label, void (*callback)(Control *, int), ControlColor color, int value, int min = 0,
|
uint16_t slider(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min = 0,
|
||||||
int max = 100); // Create Slider Control
|
int max = 100); // Create Slider Control
|
||||||
uint16_t number(const char *label, void (*callback)(Control *, int), ControlColor color, int value, int min = 0,
|
uint16_t number(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min = 0,
|
||||||
int max = 100); // Create a Number Input Control
|
int max = 100); // Create a Number Input Control
|
||||||
uint16_t text(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create a Text Input Control
|
uint16_t text(const char* label, void (*callback)(Control*, int), ControlColor color,
|
||||||
|
const String& value = ""); // Create a Text Input Control
|
||||||
|
|
||||||
// Output only
|
// Output only
|
||||||
uint16_t label(const char *label, ControlColor color, String value = ""); // Create Label
|
uint16_t label(const char* label, ControlColor color,
|
||||||
uint16_t graph(const char *label, ControlColor color); // Create Graph display
|
const String& value = ""); // Create Label
|
||||||
uint16_t gauge(const char *label, ControlColor color, int value, int min = 0, int max = 100); // Create Gauge display
|
uint16_t graph(const char* label, ControlColor color); // Create Graph display
|
||||||
|
uint16_t gauge(const char* label, ControlColor color, int value, int min = 0,
|
||||||
|
int max = 100); // Create Gauge display
|
||||||
|
|
||||||
// Input only
|
// Input only
|
||||||
uint16_t accelerometer(const char *label, void (*callback)(Control *, int), ControlColor color);
|
uint16_t accelerometer(const char* label, void (*callback)(Control*, int), ControlColor color);
|
||||||
|
|
||||||
// Update Elements
|
// Update Elements
|
||||||
|
|
||||||
Control *getControl(uint16_t id);
|
Control* getControl(uint16_t id);
|
||||||
|
|
||||||
// Update Elements
|
// Update Elements
|
||||||
void updateControlValue(uint16_t id, String value, int clientId = -1);
|
void updateControlValue(uint16_t id, const String& value, int clientId = -1);
|
||||||
void updateControlValue(Control *control, String value, int clientId = -1);
|
void updateControlValue(Control* control, const 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, const String& value);
|
||||||
void updateLabel(uint16_t id, String value);
|
void updateLabel(uint16_t id, const 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, const String& nValue, int clientId = -1);
|
||||||
void updateSelect(uint16_t id, String nValue, int clientId = -1);
|
void updateSelect(uint16_t id, const String& nValue, int clientId = -1);
|
||||||
void updateGauge(uint16_t id, int number, int clientId);
|
void updateGauge(uint16_t id, int number, int clientId);
|
||||||
|
|
||||||
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 jsonReload();
|
void jsonReload();
|
||||||
void jsonDom(AsyncWebSocketClient *client = nullptr);
|
void jsonDom(AsyncWebSocketClient* client = nullptr);
|
||||||
|
|
||||||
Verbosity verbosity;
|
Verbosity verbosity;
|
||||||
|
|
||||||
AsyncWebServer *server;
|
AsyncWebServer* server;
|
||||||
AsyncWebSocket *ws;
|
AsyncWebSocket* ws;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *basicAuthUsername = nullptr;
|
const char* basicAuthUsername = nullptr;
|
||||||
const char *basicAuthPassword = nullptr;
|
const char* basicAuthPassword = nullptr;
|
||||||
bool basicAuth = true;
|
bool basicAuth = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user