mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-24 07:20:53 +00:00
Fix compile issues #243
Also fix pio example Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
parent
fd1cc14e87
commit
f8fbcf887a
@ -18,7 +18,7 @@ board_build.filesystem = littlefs
|
|||||||
lib_extra_dirs = ../../
|
lib_extra_dirs = ../../
|
||||||
lib_deps =
|
lib_deps =
|
||||||
bblanchon/ArduinoJson @ ^6.18.5
|
bblanchon/ArduinoJson @ ^6.18.5
|
||||||
https://github.com/esphome/ESPAsyncWebServer @ 3.0.0 ; Updated lib, seems to have recent patches.
|
https://github.com/bmedici/ESPAsyncWebServer ; Use a fork of the library that has a bugfix for the compile.... https://github.com/esphome/ESPAsyncWebServer/pull/17
|
||||||
|
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
ESP Async WebServer ; force the use of the esphome version
|
ESP Async WebServer ; force the use of the esphome version
|
||||||
@ -40,4 +40,4 @@ monitor_filters = esp32_exception_decoder
|
|||||||
board_build.flash_mode = dout
|
board_build.flash_mode = dout
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${env.lib_deps}
|
${env.lib_deps}
|
||||||
me-no-dev/AsyncTCP@1.1.1
|
me-no-dev/AsyncTCP
|
||||||
|
@ -19,12 +19,12 @@
|
|||||||
|
|
||||||
static String heapInfo(const __FlashStringHelper* mode)
|
static String heapInfo(const __FlashStringHelper* mode)
|
||||||
{
|
{
|
||||||
|
String result;
|
||||||
#if ESP8266
|
#if ESP8266
|
||||||
|
|
||||||
uint32_t hfree;
|
uint32_t hfree;
|
||||||
uint32_t hmax;
|
uint16_t hmax;
|
||||||
uint8_t hfrag;
|
uint8_t hfrag;
|
||||||
String result;
|
|
||||||
result.reserve(128);
|
result.reserve(128);
|
||||||
|
|
||||||
#ifdef UMM_HEAP_IRAM
|
#ifdef UMM_HEAP_IRAM
|
||||||
@ -65,9 +65,6 @@ static String heapInfo (const __FlashStringHelper* mode)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ################# LITTLEFS functions
|
// ################# LITTLEFS functions
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
void listDir(const char* dirname, uint8_t levels)
|
void listDir(const char* dirname, uint8_t levels)
|
||||||
@ -572,11 +569,11 @@ void ESPUIClass::prepareFileSystem(bool format)
|
|||||||
#else
|
#else
|
||||||
LittleFS.end();
|
LittleFS.end();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Websockets Communication
|
// Handle Websockets Communication
|
||||||
void ESPUIClass::onWsEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len)
|
void ESPUIClass::onWsEvent(
|
||||||
|
AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len)
|
||||||
{
|
{
|
||||||
// Serial.println(String("ESPUIClass::OnWsEvent: type: ") + String(type));
|
// Serial.println(String("ESPUIClass::OnWsEvent: type: ") + String(type));
|
||||||
RemoveToBeDeletedControls();
|
RemoveToBeDeletedControls();
|
||||||
@ -627,12 +624,14 @@ uint16_t ESPUIClass::addControl(ControlType type, const char* label, const Strin
|
|||||||
return addControl(type, label, value, color, Control::noParent);
|
return addControl(type, label, value, color, Control::noParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl)
|
uint16_t ESPUIClass::addControl(
|
||||||
|
ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl)
|
||||||
{
|
{
|
||||||
return addControl(type, label, value, color, parentControl, nullptr);
|
return addControl(type, label, value, color, parentControl, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, void (*callback)(Control*, int))
|
uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color,
|
||||||
|
uint16_t parentControl, void (*callback)(Control*, int))
|
||||||
{
|
{
|
||||||
uint16_t id = addControl(type, label, value, color, parentControl, nullptr, nullptr);
|
uint16_t id = addControl(type, label, value, color, parentControl, nullptr, nullptr);
|
||||||
// set the original style callback
|
// set the original style callback
|
||||||
@ -640,7 +639,8 @@ uint16_t ESPUIClass::addControl(ControlType type, const char* label, const Strin
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, void (*callback)(Control*, int, void *), void * UserData)
|
uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color,
|
||||||
|
uint16_t parentControl, void (*callback)(Control*, int, void*), void* UserData)
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
xSemaphoreTake(ControlsSemaphore, portMAX_DELAY);
|
xSemaphoreTake(ControlsSemaphore, portMAX_DELAY);
|
||||||
@ -752,16 +752,19 @@ uint16_t ESPUIClass::graph(const char* label, ControlColor color)
|
|||||||
return addControl(ControlType::Graph, label, "", color);
|
return addControl(ControlType::Graph, label, "", color);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min, int max)
|
uint16_t ESPUIClass::slider(
|
||||||
|
const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min, int max)
|
||||||
{
|
{
|
||||||
uint16_t id = slider(label, nullptr, color, value, min, max, nullptr);
|
uint16_t id = slider(label, nullptr, color, value, min, max, nullptr);
|
||||||
getControl(id)->callback = callback;
|
getControl(id)->callback = callback;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value, int min, int max, void* userData)
|
uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value,
|
||||||
|
int min, int max, void* userData)
|
||||||
{
|
{
|
||||||
uint16_t sliderId = addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback, userData);
|
uint16_t sliderId
|
||||||
|
= addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback, userData);
|
||||||
addControl(ControlType::Min, label, String(min), ControlColor::None, sliderId);
|
addControl(ControlType::Min, label, String(min), ControlColor::None, sliderId);
|
||||||
addControl(ControlType::Max, label, String(max), ControlColor::None, sliderId);
|
addControl(ControlType::Max, label, String(max), ControlColor::None, sliderId);
|
||||||
|
|
||||||
@ -773,7 +776,8 @@ uint16_t ESPUIClass::button(const char* label, void (*callback)(Control*, int),
|
|||||||
return addControl(ControlType::Button, label, value, color, Control::noParent, callback);
|
return addControl(ControlType::Button, label, value, color, Control::noParent, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::button(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
|
uint16_t ESPUIClass::button(
|
||||||
|
const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
|
||||||
{
|
{
|
||||||
return addControl(ControlType::Button, label, value, color, Control::noParent, callback, UserData);
|
return addControl(ControlType::Button, label, value, color, Control::noParent, callback, UserData);
|
||||||
}
|
}
|
||||||
@ -783,9 +787,11 @@ uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int)
|
|||||||
return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback);
|
return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int, void*), ControlColor color, bool startState, void* UserData)
|
uint16_t ESPUIClass::switcher(
|
||||||
|
const char* label, void (*callback)(Control*, int, void*), ControlColor color, bool startState, void* UserData)
|
||||||
{
|
{
|
||||||
return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback, UserData);
|
return addControl(
|
||||||
|
ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback, UserData);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int), ControlColor color)
|
uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int), ControlColor color)
|
||||||
@ -803,12 +809,14 @@ uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*,
|
|||||||
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback);
|
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
|
uint16_t ESPUIClass::padWithCenter(
|
||||||
|
const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
|
||||||
{
|
{
|
||||||
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback, UserData);
|
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback, UserData);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int), ControlColor color, int number, int min, int max)
|
uint16_t ESPUIClass::number(
|
||||||
|
const char* label, void (*callback)(Control*, int), ControlColor color, int number, int min, int max)
|
||||||
{
|
{
|
||||||
uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback);
|
uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback);
|
||||||
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
|
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
|
||||||
@ -816,9 +824,11 @@ uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int),
|
|||||||
return numberId;
|
return numberId;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int number, int min, int max, void* UserData)
|
uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int number,
|
||||||
|
int min, int max, void* UserData)
|
||||||
{
|
{
|
||||||
uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback, UserData);
|
uint16_t numberId
|
||||||
|
= addControl(ControlType::Number, label, String(number), color, Control::noParent, callback, UserData);
|
||||||
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
|
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
|
||||||
addControl(ControlType::Max, label, String(max), ControlColor::None, numberId);
|
addControl(ControlType::Max, label, String(max), ControlColor::None, numberId);
|
||||||
return numberId;
|
return numberId;
|
||||||
@ -832,7 +842,8 @@ uint16_t ESPUIClass::gauge(const char* label, ControlColor color, int number, in
|
|||||||
return numberId;
|
return numberId;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::separator(const char* label) {
|
uint16_t ESPUIClass::separator(const char* label)
|
||||||
|
{
|
||||||
return addControl(ControlType::Separator, label, "", ControlColor::Alizarin, Control::noParent, nullptr);
|
return addControl(ControlType::Separator, label, "", ControlColor::Alizarin, Control::noParent, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -841,7 +852,8 @@ uint16_t ESPUIClass::accelerometer(const char* label, void (*callback)(Control*,
|
|||||||
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback);
|
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::accelerometer(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
|
uint16_t ESPUIClass::accelerometer(
|
||||||
|
const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
|
||||||
{
|
{
|
||||||
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback, UserData);
|
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback, UserData);
|
||||||
}
|
}
|
||||||
@ -851,7 +863,8 @@ uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int), Co
|
|||||||
return addControl(ControlType::Text, label, value, color, Control::noParent, callback);
|
return addControl(ControlType::Text, label, value, color, Control::noParent, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
|
uint16_t ESPUIClass::text(
|
||||||
|
const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
|
||||||
{
|
{
|
||||||
return addControl(ControlType::Text, label, value, color, Control::noParent, callback, UserData);
|
return addControl(ControlType::Text, label, value, color, Control::noParent, callback, UserData);
|
||||||
}
|
}
|
||||||
@ -942,7 +955,8 @@ void ESPUIClass::setPanelWide(uint16_t id, bool wide)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::setEnabled(uint16_t id, bool enabled, int clientId) {
|
void ESPUIClass::setEnabled(uint16_t id, bool enabled, int clientId)
|
||||||
|
{
|
||||||
Control* control = getControl(id);
|
Control* control = getControl(id);
|
||||||
if (control)
|
if (control)
|
||||||
{
|
{
|
||||||
@ -952,7 +966,8 @@ void ESPUIClass::setEnabled(uint16_t id, bool enabled, int clientId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::setVertical(uint16_t id, bool vert) {
|
void ESPUIClass::setVertical(uint16_t id, bool vert)
|
||||||
|
{
|
||||||
Control* control = getControl(id);
|
Control* control = getControl(id);
|
||||||
if (control)
|
if (control)
|
||||||
{
|
{
|
||||||
@ -1028,7 +1043,8 @@ void ESPUIClass::updateControlLabel(Control* control, const char * value, int cl
|
|||||||
updateControl(control, clientId);
|
updateControl(control, clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::updateVisibility(uint16_t id, bool visibility, int clientId) {
|
void ESPUIClass::updateVisibility(uint16_t id, bool visibility, int clientId)
|
||||||
|
{
|
||||||
Control* control = getControl(id);
|
Control* control = getControl(id);
|
||||||
if (control)
|
if (control)
|
||||||
{
|
{
|
||||||
@ -1047,7 +1063,8 @@ void ESPUIClass::updateLabel(uint16_t id, const String& value)
|
|||||||
updateControlValue(id, value);
|
updateControlValue(id, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::updateButton(uint16_t id, const String& value) {
|
void ESPUIClass::updateButton(uint16_t id, const String& value)
|
||||||
|
{
|
||||||
updateControlValue(id, value);
|
updateControlValue(id, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1086,7 +1103,8 @@ void ESPUIClass::updateTime(uint16_t id, int clientId)
|
|||||||
updateControl(id, clientId);
|
updateControl(id, clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::clearGraph(uint16_t id, int clientId) {
|
void ESPUIClass::clearGraph(uint16_t id, int clientId)
|
||||||
|
{
|
||||||
do // once
|
do // once
|
||||||
{
|
{
|
||||||
Control* control = getControl(id);
|
Control* control = getControl(id);
|
||||||
@ -1273,10 +1291,8 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len)
|
ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data,
|
||||||
{
|
size_t len) { ESPUI.onWsEvent(server, client, type, arg, data, len); });
|
||||||
ESPUI.onWsEvent(server, client, type, arg, data, len);
|
|
||||||
});
|
|
||||||
server->addHandler(ws);
|
server->addHandler(ws);
|
||||||
|
|
||||||
if (basicAuth)
|
if (basicAuth)
|
||||||
@ -1316,7 +1332,6 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c
|
|||||||
}
|
}
|
||||||
|
|
||||||
request->send(200, "text/plain", heapInfo(F("In LITTLEFS mode")));
|
request->send(200, "text/plain", heapInfo(F("In LITTLEFS mode")));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server->onNotFound([this](AsyncWebServerRequest* request) {
|
server->onNotFound([this](AsyncWebServerRequest* request) {
|
||||||
@ -1359,10 +1374,8 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas
|
|||||||
server = new AsyncWebServer(port);
|
server = new AsyncWebServer(port);
|
||||||
ws = new AsyncWebSocket("/ws");
|
ws = new AsyncWebSocket("/ws");
|
||||||
|
|
||||||
ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len)
|
ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data,
|
||||||
{
|
size_t len) { ESPUI.onWsEvent(server, client, type, arg, data, len); });
|
||||||
ESPUI.onWsEvent(server, client, type, arg, data, len);
|
|
||||||
});
|
|
||||||
|
|
||||||
server->addHandler(ws);
|
server->addHandler(ws);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user