1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-07-03 09:40:19 +00:00

18 Commits
2.0.1 ... 2.0.2

Author SHA1 Message Date
4827688635 Version 2.0.2
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
2020-10-19 08:57:59 +02:00
b71bc81c0d Fixing rebase errors with littlefs/debug refactor
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
2020-10-18 11:06:38 +02:00
a6ddd48abb Fix all other occurences
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
2020-10-17 22:46:22 +02:00
8c0161b181 Fix prepare fs example
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
2020-10-16 14:47:32 +02:00
3cf1aa7f49 Fix littleFS does not exist on esp32
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
2020-10-16 14:47:29 +02:00
313a069d4c Change idcounter to start at 1, closes #95 2020-10-02 19:08:45 +02:00
34d974b03b Merge pull request #97 from ericBcreator/add_tab_callback_function
Add tab callback function
2020-10-02 19:04:26 +02:00
1de52c939f Add files via upload 2020-10-01 20:28:22 +02:00
950a1fb029 Add files via upload 2020-10-01 20:27:01 +02:00
5a167091cc Update controls.js 2020-10-01 18:57:24 +02:00
57a81dbee3 Update ESPUI.cpp 2020-10-01 18:51:54 +02:00
acaf6898fd Update controls.js 2020-10-01 18:49:18 +02:00
37bbb9208d Merge pull request #91 from enwi/master
Reduce HEAP usage
2020-10-01 18:37:45 +02:00
6b2ef81b12 Fix include of ESPUI header 2020-10-01 18:04:28 +02:00
1e5ee117c5 Use DEBUG_ESPUI to en/disable debug code from being compiled
Include clang-format file for formatting code and format code
2020-10-01 18:04:28 +02:00
db4164f621 Reduce heap usage by using F and PSTR 2020-10-01 18:04:28 +02:00
bfd645d7a1 Use const String& to reduce IROM usage 2020-10-01 18:04:28 +02:00
99cf344d93 Changes suggested in #93
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
2020-09-24 21:50:28 +02:00
12 changed files with 1278 additions and 1507 deletions

58
.clang-format Executable file
View 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

View File

@ -12,6 +12,7 @@
}
.card {
min-height: 100px;
margin-top: 2%;
border-radius: 6px;
box-shadow: 0 4px 4px rgba(204, 197, 185, 0.5);
@ -28,9 +29,7 @@
}
}
.card-slider {
padding-bottom: 10px;
}
.card-slider {}
.turquoise {
background: #1abc9c;
@ -80,7 +79,7 @@
text-align: center;
color: #ffffff;
font-weight: 700;
line-height: 1;
line-height: 1.3;
margin-bottom: 5px;
display: inline-block;
white-space: nowrap;

File diff suppressed because one or more lines are too long

7
data/js/controls.js vendored
View File

@ -557,7 +557,7 @@ function start() {
case UI_TAB:
$("#tabsnav").append(
"<li><a href='#tab" + data.id + "'>" + data.value + "</a></li>"
"<li><a onmouseup='tabclick(" + data.id + ")' href='#tab" + data.id + "'>" + data.value + "</a></li>"
);
$("#tabscontent").append("<div id='tab" + data.id + "'></div>");
@ -814,6 +814,11 @@ function textchange(number) {
websock.send("tvalue:" + val + ":" + number);
}
function tabclick(number) {
var val = $("#tab" + number).val();
websock.send("tabvalue:" + val + ":" + number);
}
function selectchange(number) {
var val = $("#select" + number).val();
websock.send("svalue:" + val + ":" + number);

File diff suppressed because one or more lines are too long

View File

@ -1,11 +1,11 @@
#include <ESPUI.h>
ESPUIClass ESPUI( Verbosity::VerboseJSON );
void setup(void) {
void setup(void)
{
Serial.begin(115200);
ESPUI.prepareFileSystem();
}
void loop() {
void loop()
{
}

View File

@ -23,7 +23,7 @@
"frameworks": "arduino"
}
],
"version": "2.0.1",
"version": "2.0.2",
"frameworks": "arduino",
"platforms": "*"
}

View File

@ -1,5 +1,5 @@
name=ESPUI
version=2.0.1
version=2.0.2
author=Lukas Bachschwell
maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
sentence=ESP32 and ESP8266 Web Interface Library

File diff suppressed because it is too large Load Diff

View File

@ -6,16 +6,15 @@
#include "Arduino.h"
#include "ArduinoJson.h"
#include "FS.h"
#include "stdlib_noniso.h"
#if defined(ESP32)
#include "LittleFS.h"
#include "WiFi.h"
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include "SPIFFS.h"
#include "WiFi.h"
#else
#include <ArduinoOTA.h>
@ -23,8 +22,8 @@
#include <ESP8266mDNS.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <LittleFS.h>
#include <Hash.h>
#include <LittleFS.h>
#include <SPIFFSEditor.h>
#define FILE_WRITE "w"
@ -35,50 +34,50 @@
enum ControlType : uint8_t
{
// fixed controls
Title = 0,
// fixed controls
Title = 0,
// updatable controls
Pad,
PadWithCenter,
Button,
Label,
Switcher,
Slider,
Number,
Text,
Graph,
GraphPoint,
Tab,
Select,
Option,
Min,
Max,
Step,
Gauge,
Accel,
// updatable controls
Pad,
PadWithCenter,
Button,
Label,
Switcher,
Slider,
Number,
Text,
Graph,
GraphPoint,
Tab,
Select,
Option,
Min,
Max,
Step,
Gauge,
Accel,
UpdateOffset = 100,
UpdatePad = 101,
UpdatePadWithCenter,
ButtonButton,
UpdateLabel,
UpdateSwitcher,
UpdateSlider,
UpdateNumber,
UpdateText,
ClearGraph,
UpdateTab,
UpdateSelection,
UpdateOption,
UpdateMin,
UpdateMax,
UpdateStep,
UpdateGauge,
UpdateAccel,
UpdateOffset = 100,
UpdatePad = 101,
UpdatePadWithCenter,
ButtonButton,
UpdateLabel,
UpdateSwitcher,
UpdateSlider,
UpdateNumber,
UpdateText,
ClearGraph,
UpdateTab,
UpdateSelection,
UpdateOption,
UpdateMin,
UpdateMax,
UpdateStep,
UpdateGauge,
UpdateAccel,
InitialGui = 200,
Reload = 201
InitialGui = 200,
Reload = 201
};
#define UI_INITIAL_GUI ControlType::InitialGui
@ -106,15 +105,15 @@ enum ControlType : uint8_t
// Colors
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_EMERALD ControlColor::Emerald
@ -129,30 +128,43 @@ enum ControlColor : uint8_t
class Control
{
public:
ControlType type;
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;
ControlType type;
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;
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,
uint16_t parentControl = Control::noParent)
: type(type), label(label), callback(callback), value(value), color(color), parentControl(parentControl), next(nullptr)
{
id = idCounter++;
}
Control(ControlType type, const char* label, void (*callback)(Control*, int), const String& value,
ControlColor color, uint16_t parentControl = Control::noParent)
: 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:
static uint16_t idCounter;
static uint16_t idCounter;
};
// Values
@ -180,93 +192,105 @@ private:
enum Verbosity : uint8_t
{
Quiet = 0,
Verbose,
VerboseJSON
Quiet = 0,
Verbose,
VerboseJSON
};
class ESPUIClass
{
public:
ESPUIClass()
{
verbosity = Verbosity::Quiet;
jsonUpdateDocumentSize = 2000;
jsonInitialDocumentSize = 8000;
sliderContinuous = false;
}
unsigned int jsonUpdateDocumentSize;
unsigned int jsonInitialDocumentSize;
bool sliderContinuous;
ESPUIClass()
{
verbosity = Verbosity::Quiet;
jsonUpdateDocumentSize = 2000;
jsonInitialDocumentSize = 8000;
sliderContinuous = false;
}
unsigned int jsonUpdateDocumentSize;
unsigned int jsonInitialDocumentSize;
bool sliderContinuous;
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 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 prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS
void list(); // Lists SPIFFS directory
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of
// stuff into SPIFFS
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);
bool removeControl(uint16_t id, bool force_reload_ui = false);
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);
// create Elements
uint16_t button(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create Event Button
uint16_t switcher(const char *label, void (*callback)(Control *, int), ControlColor color, 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
// create Elements
uint16_t button(const char* label, void (*callback)(Control*, int), ControlColor color,
const String& value = ""); // Create Event Button
uint16_t switcher(const char* label, void (*callback)(Control*, int), ControlColor color,
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,
int max = 100); // Create Slider Control
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
uint16_t text(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create a Text Input Control
uint16_t slider(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min = 0,
int max = 100); // Create Slider Control
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
uint16_t text(const char* label, void (*callback)(Control*, int), ControlColor color,
const String& value = ""); // Create a Text Input Control
// Output only
uint16_t label(const char *label, ControlColor color, String value = ""); // Create Label
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
// Output only
uint16_t label(const char* label, ControlColor color,
const String& value = ""); // Create Label
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
uint16_t accelerometer(const char *label, void (*callback)(Control *, int), ControlColor color);
// Input only
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
void updateControlValue(uint16_t id, String value, int clientId = -1);
void updateControlValue(Control *control, String value, int clientId = -1);
// Update Elements
void updateControlValue(uint16_t id, const 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(Control *control, int clientId = -1);
void updateControl(uint16_t id, 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 updateGauge(uint16_t id, int number, int clientId);
void print(uint16_t id, const String& value);
void updateLabel(uint16_t id, const 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, const 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 clearGraph(uint16_t id, int clientId = -1);
void addGraphPoint(uint16_t id, int 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 jsonReload();
void jsonDom(AsyncWebSocketClient *client = nullptr);
// Variables
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
Control* controls = nullptr;
void jsonReload();
void jsonDom(AsyncWebSocketClient* client = nullptr);
Verbosity verbosity;
Verbosity verbosity;
AsyncWebServer *server;
AsyncWebSocket *ws;
AsyncWebServer* server;
AsyncWebSocket* ws;
private:
const char *basicAuthUsername = nullptr;
const char *basicAuthPassword = nullptr;
bool basicAuth = true;
const char* basicAuthUsername = nullptr;
const char* basicAuthPassword = nullptr;
bool basicAuth = true;
};
extern ESPUIClass ESPUI;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long