mirror of
https://github.com/s00500/ESPUI.git
synced 2025-07-04 06:10:18 +00:00
Compare commits
25 Commits
2.0.1
...
fix_switch
Author | SHA1 | Date | |
---|---|---|---|
4142e37eae
|
|||
0587918621 | |||
48826caee6 | |||
9ab8a84ff0 | |||
d12da60df4 | |||
8cdedaf3cb | |||
02d981cc2b | |||
4827688635
|
|||
b71bc81c0d
|
|||
a6ddd48abb
|
|||
8c0161b181
|
|||
3cf1aa7f49
|
|||
313a069d4c | |||
34d974b03b | |||
1de52c939f | |||
950a1fb029 | |||
5a167091cc | |||
57a81dbee3 | |||
acaf6898fd | |||
37bbb9208d | |||
6b2ef81b12 | |||
1e5ee117c5 | |||
db4164f621 | |||
bfd645d7a1 | |||
99cf344d93
|
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
|
@ -104,7 +104,7 @@ function `ESPUI.prepareFileSystem()`
|
|||||||
Just open the example sketch **prepareFileSystem** and run it on the ESP, (give
|
Just open the example sketch **prepareFileSystem** and run it on the ESP, (give
|
||||||
it up to 30 seconds, you can see the status on the Serial Monitor), The library
|
it up to 30 seconds, you can see the status on the Serial Monitor), The library
|
||||||
will create all needed files. Congratulations, you are done, from now on you
|
will create all needed files. Congratulations, you are done, from now on you
|
||||||
just need to to this again when there is a library update, or when you want to
|
just need to do this again when there is a library update, or when you want to
|
||||||
use another chip :-) Now you can upload your normal sketch, when you do not call
|
use another chip :-) Now you can upload your normal sketch, when you do not call
|
||||||
the `ESPUI.prepareFileSystem()` function the compiler will strip out all the
|
the `ESPUI.prepareFileSystem()` function the compiler will strip out all the
|
||||||
unnecessary strings that are already saved in the chip's filesystem and you have
|
unnecessary strings that are already saved in the chip's filesystem and you have
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
|
min-height: 100px;
|
||||||
margin-top: 2%;
|
margin-top: 2%;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
box-shadow: 0 4px 4px rgba(204, 197, 185, 0.5);
|
box-shadow: 0 4px 4px rgba(204, 197, 185, 0.5);
|
||||||
@ -28,9 +29,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-slider {
|
.card-slider {}
|
||||||
padding-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.turquoise {
|
.turquoise {
|
||||||
background: #1abc9c;
|
background: #1abc9c;
|
||||||
@ -80,7 +79,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
line-height: 1;
|
line-height: 1.3;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
2
data/css/style.min.css
vendored
2
data/css/style.min.css
vendored
File diff suppressed because one or more lines are too long
21
data/js/controls.js
vendored
21
data/js/controls.js
vendored
@ -380,28 +380,28 @@ function start() {
|
|||||||
data.id +
|
data.id +
|
||||||
", false)' id='pf" +
|
", false)' id='pf" +
|
||||||
data.id +
|
data.id +
|
||||||
"'>▲</a></li>" +
|
"'>▲</a></li>" +
|
||||||
"<li><a onmousedown='padclick(RIGHT, " +
|
"<li><a onmousedown='padclick(RIGHT, " +
|
||||||
data.id +
|
data.id +
|
||||||
", true)' onmouseup='padclick(RIGHT, " +
|
", true)' onmouseup='padclick(RIGHT, " +
|
||||||
data.id +
|
data.id +
|
||||||
", false)' id='pr" +
|
", false)' id='pr" +
|
||||||
data.id +
|
data.id +
|
||||||
"'>▲</a></li>" +
|
"'>▲</a></li>" +
|
||||||
"<li><a onmousedown='padclick(LEFT, " +
|
"<li><a onmousedown='padclick(LEFT, " +
|
||||||
data.id +
|
data.id +
|
||||||
", true)' onmouseup='padclick(LEFT, " +
|
", true)' onmouseup='padclick(LEFT, " +
|
||||||
data.id +
|
data.id +
|
||||||
", false)' id='pl" +
|
", false)' id='pl" +
|
||||||
data.id +
|
data.id +
|
||||||
"'>▲</a></li>" +
|
"'>▲</a></li>" +
|
||||||
"<li><a onmousedown='padclick(DOWN, " +
|
"<li><a onmousedown='padclick(DOWN, " +
|
||||||
data.id +
|
data.id +
|
||||||
", true)' onmouseup='padclick(DOWN, " +
|
", true)' onmouseup='padclick(DOWN, " +
|
||||||
data.id +
|
data.id +
|
||||||
", false)' id='pb" +
|
", false)' id='pb" +
|
||||||
data.id +
|
data.id +
|
||||||
"'>▲</a></li>" +
|
"'>▲</a></li>" +
|
||||||
"</ul>" +
|
"</ul>" +
|
||||||
(data.type == UI_CPAD
|
(data.type == UI_CPAD
|
||||||
? "<a class='confirm' onmousedown='padclick(CENTER," +
|
? "<a class='confirm' onmousedown='padclick(CENTER," +
|
||||||
@ -557,7 +557,7 @@ function start() {
|
|||||||
|
|
||||||
case UI_TAB:
|
case UI_TAB:
|
||||||
$("#tabsnav").append(
|
$("#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>");
|
$("#tabscontent").append("<div id='tab" + data.id + "'></div>");
|
||||||
|
|
||||||
@ -799,9 +799,11 @@ function start() {
|
|||||||
websock.onmessage = handleEvent;
|
websock.onmessage = handleEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sliderCache = {};
|
||||||
function sliderchange(number) {
|
function sliderchange(number) {
|
||||||
var val = $("#sl" + number).val();
|
var val = $("#sl" + number).val();
|
||||||
websock.send("slvalue:" + val + ":" + number);
|
sliderCache[number] !== val && websock.send("slvalue:" + val + ":" + number);
|
||||||
|
sliderCache[number] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
function numberchange(number) {
|
function numberchange(number) {
|
||||||
@ -814,6 +816,11 @@ function textchange(number) {
|
|||||||
websock.send("tvalue:" + val + ":" + number);
|
websock.send("tvalue:" + val + ":" + number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tabclick(number) {
|
||||||
|
var val = $("#tab" + number).val();
|
||||||
|
websock.send("tabvalue:" + val + ":" + number);
|
||||||
|
}
|
||||||
|
|
||||||
function selectchange(number) {
|
function selectchange(number) {
|
||||||
var val = $("#select" + number).val();
|
var val = $("#select" + number).val();
|
||||||
websock.send("svalue:" + val + ":" + number);
|
websock.send("svalue:" + val + ":" + number);
|
||||||
@ -854,9 +861,11 @@ function switcher(number, state) {
|
|||||||
if ($("#s" + number).is(":checked")) {
|
if ($("#s" + number).is(":checked")) {
|
||||||
websock.send("sactive:" + number);
|
websock.send("sactive:" + number);
|
||||||
$("#sl" + number).addClass("checked");
|
$("#sl" + number).addClass("checked");
|
||||||
|
$("#sl" + number).prop("checked", true);
|
||||||
} else {
|
} else {
|
||||||
websock.send("sinactive:" + number);
|
websock.send("sinactive:" + number);
|
||||||
$("#sl" + number).removeClass("checked");
|
$("#sl" + number).removeClass("checked");
|
||||||
|
$("#sl" + number).prop("checked", false);
|
||||||
}
|
}
|
||||||
} else if (state == 1) {
|
} else if (state == 1) {
|
||||||
$("#sl" + number).addClass("checked");
|
$("#sl" + number).addClass("checked");
|
||||||
|
15
data/js/controls.min.js
vendored
15
data/js/controls.min.js
vendored
@ -80,28 +80,28 @@ data.id+
|
|||||||
data.id+
|
data.id+
|
||||||
", false)' id='pf"+
|
", false)' id='pf"+
|
||||||
data.id+
|
data.id+
|
||||||
"'>▲</a></li>"+
|
"'>▲</a></li>"+
|
||||||
"<li><a onmousedown='padclick(RIGHT, "+
|
"<li><a onmousedown='padclick(RIGHT, "+
|
||||||
data.id+
|
data.id+
|
||||||
", true)' onmouseup='padclick(RIGHT, "+
|
", true)' onmouseup='padclick(RIGHT, "+
|
||||||
data.id+
|
data.id+
|
||||||
", false)' id='pr"+
|
", false)' id='pr"+
|
||||||
data.id+
|
data.id+
|
||||||
"'>▲</a></li>"+
|
"'>▲</a></li>"+
|
||||||
"<li><a onmousedown='padclick(LEFT, "+
|
"<li><a onmousedown='padclick(LEFT, "+
|
||||||
data.id+
|
data.id+
|
||||||
", true)' onmouseup='padclick(LEFT, "+
|
", true)' onmouseup='padclick(LEFT, "+
|
||||||
data.id+
|
data.id+
|
||||||
", false)' id='pl"+
|
", false)' id='pl"+
|
||||||
data.id+
|
data.id+
|
||||||
"'>▲</a></li>"+
|
"'>▲</a></li>"+
|
||||||
"<li><a onmousedown='padclick(DOWN, "+
|
"<li><a onmousedown='padclick(DOWN, "+
|
||||||
data.id+
|
data.id+
|
||||||
", true)' onmouseup='padclick(DOWN, "+
|
", true)' onmouseup='padclick(DOWN, "+
|
||||||
data.id+
|
data.id+
|
||||||
", false)' id='pb"+
|
", false)' id='pb"+
|
||||||
data.id+
|
data.id+
|
||||||
"'>▲</a></li>"+
|
"'>▲</a></li>"+
|
||||||
"</ul>"+
|
"</ul>"+
|
||||||
(data.type==UI_CPAD?"<a class='confirm' onmousedown='padclick(CENTER,"+
|
(data.type==UI_CPAD?"<a class='confirm' onmousedown='padclick(CENTER,"+
|
||||||
data.id+
|
data.id+
|
||||||
@ -162,7 +162,7 @@ data.value+
|
|||||||
"' onchange='textchange("+
|
"' onchange='textchange("+
|
||||||
data.id+
|
data.id+
|
||||||
")' />"+
|
")' />"+
|
||||||
"</div>");break;case UI_TAB:$("#tabsnav").append("<li><a href='#tab"+data.id+"'>"+data.value+"</a></li>");$("#tabscontent").append("<div id='tab"+data.id+"'></div>");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");}
|
"</div>");break;case UI_TAB:$("#tabsnav").append("<li><a onmouseup='tabclick("+data.id+")' href='#tab"+data.id+"'>"+data.value+"</a></li>");$("#tabscontent").append("<div id='tab"+data.id+"'></div>");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");}
|
||||||
e.preventDefault();});break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
e.preventDefault();});break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
parent.append("<div id='id"+
|
parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
@ -239,11 +239,12 @@ data.id+
|
|||||||
"'></pre>"+
|
"'></pre>"+
|
||||||
"</div>");requestOrientationPermission();break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;}
|
"</div>");requestOrientationPermission();break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;}
|
||||||
if(data.type>=UPDATE_OFFSET&&data.type<UI_INITIAL_GUI){var element=$("#id"+data.id);if(data.type==UPDATE_SLIDER){element.removeClass("slider-turquoise slider-emerald slider-peterriver slider-wetasphalt slider-sunflower slider-carrot slider-alizarin");element.addClass("slider-"+colorClass(data.color));}else{element.removeClass("turquoise emerald peterriver wetasphalt sunflower carrot alizarin");element.addClass(colorClass(data.color));}}};websock.onmessage=handleEvent;}
|
if(data.type>=UPDATE_OFFSET&&data.type<UI_INITIAL_GUI){var element=$("#id"+data.id);if(data.type==UPDATE_SLIDER){element.removeClass("slider-turquoise slider-emerald slider-peterriver slider-wetasphalt slider-sunflower slider-carrot slider-alizarin");element.addClass("slider-"+colorClass(data.color));}else{element.removeClass("turquoise emerald peterriver wetasphalt sunflower carrot alizarin");element.addClass(colorClass(data.color));}}};websock.onmessage=handleEvent;}
|
||||||
function sliderchange(number){var val=$("#sl"+number).val();websock.send("slvalue:"+val+":"+number);}
|
var sliderCache={};function sliderchange(number){var val=$("#sl"+number).val();sliderCache[number]!==val&&websock.send("slvalue:"+val+":"+number);sliderCache[number]=val;}
|
||||||
function numberchange(number){var val=$("#num"+number).val();websock.send("nvalue:"+val+":"+number);}
|
function numberchange(number){var val=$("#num"+number).val();websock.send("nvalue:"+val+":"+number);}
|
||||||
function textchange(number){var val=$("#text"+number).val();websock.send("tvalue:"+val+":"+number);}
|
function textchange(number){var val=$("#text"+number).val();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);}
|
function selectchange(number){var val=$("#select"+number).val();websock.send("svalue:"+val+":"+number);}
|
||||||
function buttonclick(number,isdown){if(isdown)websock.send("bdown:"+number);else websock.send("bup:"+number);}
|
function buttonclick(number,isdown){if(isdown)websock.send("bdown:"+number);else websock.send("bup:"+number);}
|
||||||
function padclick(type,number,isdown){switch(type){case CENTER:if(isdown)websock.send("pcdown:"+number);else websock.send("pcup:"+number);break;case UP:if(isdown)websock.send("pfdown:"+number);else websock.send("pfup:"+number);break;case DOWN:if(isdown)websock.send("pbdown:"+number);else websock.send("pbup:"+number);break;case LEFT:if(isdown)websock.send("pldown:"+number);else websock.send("plup:"+number);break;case RIGHT:if(isdown)websock.send("prdown:"+number);else websock.send("prup:"+number);break;}}
|
function padclick(type,number,isdown){switch(type){case CENTER:if(isdown)websock.send("pcdown:"+number);else websock.send("pcup:"+number);break;case UP:if(isdown)websock.send("pfdown:"+number);else websock.send("pfup:"+number);break;case DOWN:if(isdown)websock.send("pbdown:"+number);else websock.send("pbup:"+number);break;case LEFT:if(isdown)websock.send("pldown:"+number);else websock.send("plup:"+number);break;case RIGHT:if(isdown)websock.send("prdown:"+number);else websock.send("prup:"+number);break;}}
|
||||||
function switcher(number,state){if(state==null){if($("#s"+number).is(":checked")){websock.send("sactive:"+number);$("#sl"+number).addClass("checked");}else{websock.send("sinactive:"+number);$("#sl"+number).removeClass("checked");}}else if(state==1){$("#sl"+number).addClass("checked");$("#sl"+number).prop("checked",true);}else if(state==0){$("#sl"+number).removeClass("checked");$("#sl"+number).prop("checked",false);}}
|
function switcher(number,state){if(state==null){if($("#s"+number).is(":checked")){websock.send("sactive:"+number);$("#sl"+number).addClass("checked");$("#sl"+number).prop("checked",true);}else{websock.send("sinactive:"+number);$("#sl"+number).removeClass("checked");$("#sl"+number).prop("checked",false);}}else if(state==1){$("#sl"+number).addClass("checked");$("#sl"+number).prop("checked",true);}else if(state==0){$("#sl"+number).removeClass("checked");$("#sl"+number).prop("checked",false);}}
|
||||||
var rangeSlider=function(isDiscrete){var slider=$(".range-slider"),range=$(".range-slider__range"),value=$(".range-slider__value");slider.each(function(){value.each(function(){var value=$(this).prev().attr("value");$(this).html(value);});if(!isDiscrete){range.on({input:function(){sliderchange($(this).attr("id").replace(/^\D+/g,""));},});}else{range.on({input:function(){$(this).next().html(this.value);},change:function(){sliderchange($(this).attr("id").replace(/^\D+/g,""));},});}});};
|
var rangeSlider=function(isDiscrete){var slider=$(".range-slider"),range=$(".range-slider__range"),value=$(".range-slider__value");slider.each(function(){value.each(function(){var value=$(this).prev().attr("value");$(this).html(value);});if(!isDiscrete){range.on({input:function(){sliderchange($(this).attr("id").replace(/^\D+/g,""));},});}else{range.on({input:function(){$(this).next().html(this.value);},change:function(){sliderchange($(this).attr("id").replace(/^\D+/g,""));},});}});};
|
@ -1,11 +1,11 @@
|
|||||||
#include <ESPUI.h>
|
#include <ESPUI.h>
|
||||||
|
|
||||||
ESPUIClass ESPUI( Verbosity::VerboseJSON );
|
void setup(void)
|
||||||
|
{
|
||||||
void setup(void) {
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
ESPUI.prepareFileSystem();
|
ESPUI.prepareFileSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
"frameworks": "arduino"
|
"frameworks": "arduino"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*"
|
"platforms": "*"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=ESPUI
|
name=ESPUI
|
||||||
version=2.0.1
|
version=2.0.2
|
||||||
author=Lukas Bachschwell
|
author=Lukas Bachschwell
|
||||||
maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
|
maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
|
||||||
sentence=ESP32 and ESP8266 Web Interface Library
|
sentence=ESP32 and ESP8266 Web Interface Library
|
||||||
|
1893
src/ESPUI.cpp
1893
src/ESPUI.cpp
File diff suppressed because it is too large
Load Diff
300
src/ESPUI.h
300
src/ESPUI.h
@ -6,16 +6,15 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "FS.h"
|
|
||||||
#include "stdlib_noniso.h"
|
#include "stdlib_noniso.h"
|
||||||
|
|
||||||
#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 "SPIFFS.h"
|
||||||
|
#include "WiFi.h"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@ -23,8 +22,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"
|
||||||
@ -35,50 +34,50 @@
|
|||||||
|
|
||||||
enum ControlType : uint8_t
|
enum ControlType : uint8_t
|
||||||
{
|
{
|
||||||
// fixed controls
|
// fixed controls
|
||||||
Title = 0,
|
Title = 0,
|
||||||
|
|
||||||
// updatable controls
|
// updatable controls
|
||||||
Pad,
|
Pad,
|
||||||
PadWithCenter,
|
PadWithCenter,
|
||||||
Button,
|
Button,
|
||||||
Label,
|
Label,
|
||||||
Switcher,
|
Switcher,
|
||||||
Slider,
|
Slider,
|
||||||
Number,
|
Number,
|
||||||
Text,
|
Text,
|
||||||
Graph,
|
Graph,
|
||||||
GraphPoint,
|
GraphPoint,
|
||||||
Tab,
|
Tab,
|
||||||
Select,
|
Select,
|
||||||
Option,
|
Option,
|
||||||
Min,
|
Min,
|
||||||
Max,
|
Max,
|
||||||
Step,
|
Step,
|
||||||
Gauge,
|
Gauge,
|
||||||
Accel,
|
Accel,
|
||||||
|
|
||||||
UpdateOffset = 100,
|
UpdateOffset = 100,
|
||||||
UpdatePad = 101,
|
UpdatePad = 101,
|
||||||
UpdatePadWithCenter,
|
UpdatePadWithCenter,
|
||||||
ButtonButton,
|
ButtonButton,
|
||||||
UpdateLabel,
|
UpdateLabel,
|
||||||
UpdateSwitcher,
|
UpdateSwitcher,
|
||||||
UpdateSlider,
|
UpdateSlider,
|
||||||
UpdateNumber,
|
UpdateNumber,
|
||||||
UpdateText,
|
UpdateText,
|
||||||
ClearGraph,
|
ClearGraph,
|
||||||
UpdateTab,
|
UpdateTab,
|
||||||
UpdateSelection,
|
UpdateSelection,
|
||||||
UpdateOption,
|
UpdateOption,
|
||||||
UpdateMin,
|
UpdateMin,
|
||||||
UpdateMax,
|
UpdateMax,
|
||||||
UpdateStep,
|
UpdateStep,
|
||||||
UpdateGauge,
|
UpdateGauge,
|
||||||
UpdateAccel,
|
UpdateAccel,
|
||||||
|
|
||||||
InitialGui = 200,
|
InitialGui = 200,
|
||||||
Reload = 201
|
Reload = 201
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UI_INITIAL_GUI ControlType::InitialGui
|
#define UI_INITIAL_GUI ControlType::InitialGui
|
||||||
@ -106,15 +105,15 @@ enum ControlType : uint8_t
|
|||||||
// Colors
|
// Colors
|
||||||
enum ControlColor : uint8_t
|
enum ControlColor : uint8_t
|
||||||
{
|
{
|
||||||
Turquoise,
|
Turquoise,
|
||||||
Emerald,
|
Emerald,
|
||||||
Peterriver,
|
Peterriver,
|
||||||
Wetasphalt,
|
Wetasphalt,
|
||||||
Sunflower,
|
Sunflower,
|
||||||
Carrot,
|
Carrot,
|
||||||
Alizarin,
|
Alizarin,
|
||||||
Dark,
|
Dark,
|
||||||
None = 0xFF
|
None = 0xFF
|
||||||
};
|
};
|
||||||
#define COLOR_TURQUOISE ControlColor::Turquoise
|
#define COLOR_TURQUOISE ControlColor::Turquoise
|
||||||
#define COLOR_EMERALD ControlColor::Emerald
|
#define COLOR_EMERALD ControlColor::Emerald
|
||||||
@ -129,30 +128,43 @@ enum ControlColor : uint8_t
|
|||||||
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), 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),
|
||||||
id = idCounter++;
|
callback(callback),
|
||||||
}
|
value(value),
|
||||||
|
color(color),
|
||||||
|
parentControl(parentControl),
|
||||||
|
next(nullptr)
|
||||||
|
{
|
||||||
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
@ -180,93 +192,105 @@ private:
|
|||||||
|
|
||||||
enum Verbosity : uint8_t
|
enum Verbosity : uint8_t
|
||||||
{
|
{
|
||||||
Quiet = 0,
|
Quiet = 0,
|
||||||
Verbose,
|
Verbose,
|
||||||
VerboseJSON
|
VerboseJSON
|
||||||
};
|
};
|
||||||
|
|
||||||
class ESPUIClass
|
class ESPUIClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ESPUIClass()
|
ESPUIClass()
|
||||||
{
|
{
|
||||||
verbosity = Verbosity::Quiet;
|
verbosity = Verbosity::Quiet;
|
||||||
jsonUpdateDocumentSize = 2000;
|
jsonUpdateDocumentSize = 2000;
|
||||||
jsonInitialDocumentSize = 8000;
|
jsonInitialDocumentSize = 8000;
|
||||||
sliderContinuous = false;
|
sliderContinuous = false;
|
||||||
}
|
}
|
||||||
unsigned int jsonUpdateDocumentSize;
|
unsigned int jsonUpdateDocumentSize;
|
||||||
unsigned int jsonInitialDocumentSize;
|
unsigned int jsonInitialDocumentSize;
|
||||||
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
|
||||||
void list(); // Lists SPIFFS directory
|
// 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);
|
uint16_t addControl(ControlType type, const char* label, const String& value = String(""),
|
||||||
bool removeControl(uint16_t id, bool force_reload_ui = false);
|
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
|
// 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ESPUIClass ESPUI;
|
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
Reference in New Issue
Block a user