some buttons are now websocket-handled
This commit is contained in:
		| @@ -225,8 +225,8 @@ | |||||||
|         </div> |         </div> | ||||||
|         <div class="form-group row"> |         <div class="form-group row"> | ||||||
|           <div class="col text-center"> |           <div class="col text-center"> | ||||||
|             <button id="btn-ws-start" class="btn btn-outline-primary">Start</button> |             <button id="btn-debugstart" class="btn-wsevent btn btn-outline-primary ml-2">Start</button> | ||||||
|             <button id="btn-ws-stop" class="btn btn-outline-primary ml-2">Stop</button> |             <button id="btn-debugstop" class="btn-wsevent btn btn-outline-primary ml-2">Stop</button> | ||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
|         </p> |         </p> | ||||||
| @@ -235,13 +235,11 @@ | |||||||
|         <hr /> |         <hr /> | ||||||
|         <p> |         <p> | ||||||
|         <h4>Gerät neustarten</h4> |         <h4>Gerät neustarten</h4> | ||||||
|         <form action="post.htm" method="POST" class="form-horizontal"> |  | ||||||
|           <div class="form-group row"> |           <div class="form-group row"> | ||||||
|             <div class="col text-center"> |             <div class="col text-center"> | ||||||
|               <button name="reboot" type="submit" class="btn btn-outline-primary">Reboot</button> |               <button id="btn-reboot" class="btn-wsevent btn btn-outline-primary">Reboot</button> | ||||||
|             </div> |             </div> | ||||||
|           </div> |           </div> | ||||||
|         </form> |  | ||||||
|         </p> |         </p> | ||||||
|         <!-- Div Group Device Reboot --> |         <!-- Div Group Device Reboot --> | ||||||
|       </div> |       </div> | ||||||
|   | |||||||
| @@ -15,12 +15,31 @@ function initWebSocket() { | |||||||
| } | } | ||||||
|  |  | ||||||
| function initButtons() { | function initButtons() { | ||||||
|   document |  | ||||||
|     .getElementById("btn-ws-stop") |   var elements = document.getElementsByClassName("btn-wsevent"); | ||||||
|     .addEventListener("click", livedebug_stop); |  | ||||||
|   document |   if (elements.length > 0) { | ||||||
|     .getElementById("btn-ws-start") |     for (var i = 0; i < elements.length; i++) { | ||||||
|     .addEventListener("click", livedebug_start); |       var element = elements[i]; | ||||||
|  |       element.addEventListener("click", function () { | ||||||
|  |         websocket_sendevent("btn-" + element.id, 0); | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function initSettingInputs() { | ||||||
|  |  | ||||||
|  |   var elements = document.getElementsByClassName("btn-wssetting"); | ||||||
|  |  | ||||||
|  |   if (elements.length > 0) { | ||||||
|  |     for (var i = 0; i < elements.length; i++) { | ||||||
|  |       var element = elements[i]; | ||||||
|  |       element.addEventListener("change", function () { | ||||||
|  |         websocket_sendevent("set-" + element.id, element.value); | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| function onOpen(event) { | function onOpen(event) { | ||||||
| @@ -112,14 +131,11 @@ function processDataString(dataString, mapping) { | |||||||
| function onLoad(event) { | function onLoad(event) { | ||||||
|   initWebSocket(); |   initWebSocket(); | ||||||
|   initButtons(); |   initButtons(); | ||||||
|  |   initSettingInputs(); | ||||||
| } | } | ||||||
|  |  | ||||||
| function livedebug_start() { | function websocket_sendevent(element_id, element_value) { | ||||||
|   websocket.send("start"); |   websocket.send(element_id + ":" + element_value); | ||||||
| } |  | ||||||
|  |  | ||||||
| function livedebug_stop() { |  | ||||||
|   websocket.send("stop"); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function do_resize(textbox) { | function do_resize(textbox) { | ||||||
|   | |||||||
| @@ -32,6 +32,8 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len); | |||||||
| void Websocket_RefreshClientData_DTCs(uint32_t client_id); | void Websocket_RefreshClientData_DTCs(uint32_t client_id); | ||||||
| void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping = false); | void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping = false); | ||||||
| void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping = false); | void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping = false); | ||||||
|  | void Websocket_HandleButtons(uint8_t *data); | ||||||
|  | void Websocket_HandleSettings(uint8_t *data); | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @brief Initializes the web-based user interface (WebUI) for the ChainLube application. |  * @brief Initializes the web-based user interface (WebUI) for the ChainLube application. | ||||||
| @@ -180,8 +182,6 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request) | |||||||
|       globals.requestEEAction = EE_CFG_SAVE; |       globals.requestEEAction = EE_CFG_SAVE; | ||||||
|     // end: POST Form Oiltank |     // end: POST Form Oiltank | ||||||
|     // begin: POST Form Maintenance |     // begin: POST Form Maintenance | ||||||
|     if (p->name() == "purgepulse") |  | ||||||
|       LubeConfig.BleedingPulses = p->value().toInt(); |  | ||||||
|     if (p->name() == "maintsave") |     if (p->name() == "maintsave") | ||||||
|       globals.requestEEAction = EE_CFG_SAVE; |       globals.requestEEAction = EE_CFG_SAVE; | ||||||
|     if (p->name() == "resettank") |     if (p->name() == "resettank") | ||||||
| @@ -204,15 +204,6 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request) | |||||||
|           globals.requestEEAction = globals.requestEEAction == EE_PDS_FORMAT ? EE_FORMAT_ALL : EE_CFG_FORMAT; |           globals.requestEEAction = globals.requestEEAction == EE_PDS_FORMAT ? EE_FORMAT_ALL : EE_CFG_FORMAT; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     if (p->name() == "purgenow") |  | ||||||
|     { |  | ||||||
|       globals.systemStatus = sysStat_Purge; |  | ||||||
|       globals.purgePulses = LubeConfig.BleedingPulses; |  | ||||||
|     } |  | ||||||
|     if (p->name() == "reboot") |  | ||||||
|     { |  | ||||||
|       globals.systemStatus = sysStat_Shutdown; |  | ||||||
|     } |  | ||||||
|     // end: POST Form Maintenance |     // end: POST Form Maintenance | ||||||
|     // begin: POST Form LED Settings |     // begin: POST Form LED Settings | ||||||
|     if (p->name() == "ledmaxbrightness") |     if (p->name() == "ledmaxbrightness") | ||||||
| @@ -234,12 +225,6 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request) | |||||||
|       globals.requestEEAction = EE_CFG_SAVE; |       globals.requestEEAction = EE_CFG_SAVE; | ||||||
|     } |     } | ||||||
|     // end: POST Form LED SEttings |     // end: POST Form LED SEttings | ||||||
|     // begin: POST Form Measure Pulses |  | ||||||
|     if (p->name() == "measurereset") |  | ||||||
|       globals.measuredPulses = 0; |  | ||||||
|     if (p->name() == "measurestartstop") |  | ||||||
|       globals.measurementActive = !globals.measurementActive; |  | ||||||
|     // end: POST Form Measure Pulses |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -530,21 +515,57 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len) | |||||||
|   { |   { | ||||||
|     data[len] = 0; |     data[len] = 0; | ||||||
|  |  | ||||||
|     Debug_pushMessage("Got WebSocket Message: %s \n", (char *)data); |     if (strncmp((char *)data, "btn-", strlen("btn-")) == 0) | ||||||
|  |     { | ||||||
|  |       Websocket_HandleButtons(data + strlen("btn-")); | ||||||
|  |     } | ||||||
|  |     if (strncmp((char *)data, "set-", strlen("set-")) == 0) | ||||||
|  |     { | ||||||
|  |       Websocket_HandleSettings(data + strlen("set-")); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |       Debug_pushMessage("Got unknown Websocket-Message '%s' from client\n", (char *)data); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|     if (strcmp((char *)data, "start") == 0) | void Websocket_HandleButtons(uint8_t *data) | ||||||
|  | { | ||||||
|  |   if (strcmp((char *)data, "debugstart") == 0) | ||||||
|   { |   { | ||||||
|     SetDebugportStatus(dbg_Webui, enabled); |     SetDebugportStatus(dbg_Webui, enabled); | ||||||
|   } |   } | ||||||
|     else if (strcmp((char *)data, "stop") == 0) |   else if (strcmp((char *)data, "debugstop") == 0) | ||||||
|   { |   { | ||||||
|     SetDebugportStatus(dbg_Webui, disabled); |     SetDebugportStatus(dbg_Webui, disabled); | ||||||
|   } |   } | ||||||
|     else if (strcmp((char *)data, "foo") == 0) |   else if (strcmp((char *)data, "measurereset") == 0) | ||||||
|   { |   { | ||||||
|       Debug_pushMessage("Got WebSocket Message 'foo' from client\n"); |     globals.measuredPulses = 0; | ||||||
|  |   } | ||||||
|  |   else if (strcmp((char *)data, "measurestartstop") == 0) | ||||||
|  |   { | ||||||
|  |     globals.measurementActive = !globals.measurementActive; | ||||||
|  |   } | ||||||
|  |   else if (strcmp((char *)data, "purgenow") == 0) | ||||||
|  |   { | ||||||
|  |     globals.systemStatus = sysStat_Purge; | ||||||
|  |     globals.purgePulses = LubeConfig.BleedingPulses; | ||||||
|  |   } | ||||||
|  |   else if (strcmp((char *)data, "reboot") == 0) | ||||||
|  |   { | ||||||
|  |     globals.systemStatus = sysStat_Shutdown; | ||||||
|  |   } | ||||||
|  |   else | ||||||
|  |   { | ||||||
|  |     Debug_pushMessage("Got unknown Button-id '%s' from ws-client\n", (char *)data); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void Websocket_HandleSettings(uint8_t *data) | ||||||
|  | { | ||||||
|  |   Debug_pushMessage("Got Settings-id and value '%s' from ws-client\n", (char *)data); | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user