MI32 GUI changes (#20115)

This commit is contained in:
Christian Baars 2023-11-27 19:08:44 +01:00 committed by GitHub
parent 62afe918f0
commit fb51d9df8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 11 deletions

View File

@ -226,6 +226,7 @@ struct {
void *beServerCB;
uint8_t *beAdvBuf;
uint8_t infoMsg = 0;
uint8_t role = 0;
} MI32;
struct mi_sensor_t{
@ -473,8 +474,14 @@ const char HTTP_MI32_SCRIPT_1[] PROGMEM =
;
const char HTTP_MI32_STYLE[] PROGMEM =
"<style onload=setTimeout(setUp,500)>.parent {display: flex;flex-wrap: wrap;justify-content: center;}svg{float:inline-end;}"
".box {flex: 0 1 335px;margin: 5px;padding: 5px;border-radius: 0.8rem;background-color: rgba(221, 221, 221, 0.2);}</style>";
"<style onload=setTimeout(setUp,500)>body{display:flex;flex-direction:column;}"
".parent{display:grid;grid-template-columns:repeat(auto-fill,350px);grid-template-rows:repeat(auto-fill,220px);"
"grid-auto-rows:220px;grid-auto-columns:350px;gap:1rem;justify-content:center;}"
"svg{float:inline-end;}"
".box{padding:10px;border-radius:0.8rem;background-color:rgba(221, 221, 221, 0.2);}"
"@media screen and (min-width: 720px){.wide{grid-column:span 2;grid-row:span 1;}.big {grid-column:span 2;grid-row:span 2;}}"
".tall {grid-column:span 1;grid-row:span 2;}"
"</style>";
const char HTTP_MI32_STYLE_SVG[] PROGMEM =
"<svg height='0'><defs><linearGradient id='grd%u' x1='0%%' y1='0%%' x2='0%%' y2='15%%'>"
@ -482,12 +489,15 @@ const char HTTP_MI32_STYLE_SVG[] PROGMEM =
"<stop offset='1' stop-color='rgba(%u, %u, %u, 0)'/></linearGradient></defs></svg>"
;
const char HTTP_MI32_PARENT_BLE_ROLE[] PROGMEM = "None|Observer|Peripheral|Central";
const char HTTP_MI32_PARENT_START[] PROGMEM =
"<div class='parent'>"
"<div class='box'><h2>MI32 Bridge</h2>"
"Observing <span id='numDev'>%u</span> devices<br>"
"Uptime: <span class='Ti'>%u</span> seconds<br>"
"Free Heap: %u kB"
"<div class='box tall'><h2>MI32 Bridge</h2>"
"Observing <span id='numDev'>%u</span> devices<br><br>"
"Uptime: <span class='Ti'>%u</span> seconds<br><br>"
"Free Heap: %u kB<br><br>"
"BLE Role: %s"
"</div>";
const char HTTP_MI32_WIDGET[] PROGMEM =

View File

@ -726,6 +726,9 @@ bool HttpCheckPriviledgedAccess(bool autorequestauth = true)
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_HTTP "Referer '%s' denied. Use 'SO128 1' for HTTP API commands. 'Webpassword' is recommended."), referer.c_str());
return false;
} else {
#if defined(USE_MI_ESP32) && !defined(USE_BLE_ESP32)
MI32suspendScanTask();
#endif // defined(USE_MI_ESP32) && !defined(USE_BLE_ESP32)
return true;
}
}
@ -997,6 +1000,9 @@ void WSContentEnd(void) {
WSContentFlush(); // Flush chunk buffer
_WSContentSend(""); // Signal end of chunked content
Webserver->client().stop();
#if defined(USE_MI_ESP32) && !defined(USE_BLE_ESP32)
MI32resumeScanTask();
#endif // defined(USE_MI_ESP32) && !defined(USE_BLE_ESP32)
}
void WSContentStop(void) {

View File

@ -1019,6 +1019,7 @@ void MI32resumeScanTask(void){
void MI32StartTask(uint32_t task){
if (MI32.mode.willConnect == 1) return; // we are in the middle of connecting to something ... do not interrupt this.
MI32.role = 0;
switch(task){
case MI32_TASK_SCAN:
if (MI32.mode.connected == 1) return;
@ -1045,6 +1046,7 @@ void MI32StartScanTask(){
if(MI32.ScanTask!=nullptr) vTaskDelete(MI32.ScanTask);
MI32.mode.runningScan = 1;
MI32.mode.deleteScanTask = 0;
MI32.role = 1;
xTaskCreatePinnedToCore(
MI32ScanTask, /* Function to implement the task */
"MI32ScanTask", /* Name of the task */
@ -1199,6 +1201,7 @@ bool MI32StartConnectionTask(){
MI32.mode.willConnect = 1;
MI32Scan->stop();
MI32suspendScanTask();
MI32.role = 2;
xTaskCreatePinnedToCore(
MI32ConnectionTask, /* Function to implement the task */
"MI32ConnectionTask", /* Name of the task */
@ -1387,6 +1390,7 @@ bool MI32StartServerTask(){
return false;
}
}
MI32.role = 3;
xTaskCreatePinnedToCore(
MI32ServerTask, /* Function to implement the task */
"MI32ServerTask", /* Name of the task */
@ -2125,7 +2129,11 @@ void MI32sendEnergyWidget(){
#ifdef USE_WEBCAM
void MI32sendCamWidget(){
if (Wc.CamServer && Wc.up) {
WSContentSend_P(PSTR("<img class='box' id='cam' src='http://%_I:81/stream'>"),
WSContentSend_P(PSTR("<div class='box"));
if(Settings->webcam_config.resolution>7){
WSContentSend_P(PSTR(" big"));
}
WSContentSend_P(PSTR("' id='cam' style='background-image:url(http://%_I:81/stream);background-repeat:no-repeat;background-size:cover;'></div>"),
(uint32_t)WiFi.localIP());
}
}
@ -2242,7 +2250,6 @@ void MI32sendWidget(uint32_t slot){
}
void MI32InitGUI(void){
MI32suspendScanTask();
MI32.widgetSlot=0;
WSContentStart_P("m32");
WSContentSend_P(HTTP_MI32_SCRIPT_1);
@ -2252,11 +2259,15 @@ void MI32InitGUI(void){
WSContentSend_P(HTTP_MI32_STYLE_SVG,2,151,190,216,151,190,216);
WSContentSend_P(HTTP_MI32_STYLE_SVG,3,242,240,176,242,240,176);
WSContentSend_P((HTTP_MI32_PARENT_START),MIBLEsensors.size(),UpTime(),ESP.getFreeHeap()/1024);
char _role[16];
GetTextIndexed(_role, sizeof(_role), MI32.role, HTTP_MI32_PARENT_BLE_ROLE);
WSContentSend_P((HTTP_MI32_PARENT_START),MIBLEsensors.size(),UpTime(),ESP.getFreeHeap()/1024,_role);
for(uint32_t _slot = 0;_slot<MIBLEsensors.size();_slot++){
uint32_t _slot;
for(_slot = 0;_slot<MIBLEsensors.size();_slot++){
MI32sendWidget(_slot);
}
#ifdef USE_MI_ESP32_ENERGY
MI32sendEnergyWidget();
#endif //USE_MI_ESP32_ENERGY
@ -2266,7 +2277,6 @@ void MI32InitGUI(void){
WSContentSend_P(PSTR("</div>"));
WSContentSpaceButton(BUTTON_MAIN);
WSContentStop();
MI32resumeScanTask();
}
void MI32HandleWebGUI(void){