Add WebSocket support for switch status updates
- Define `LoadSwStatus` protobuf message for switch state data (`main` and `usb`). - Introduce `updateSwitchStatusUI` to synchronize UI with WebSocket switch status payloads. - Update backend logic to manage and broadcast switch status changes dynamically. Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
initUI,
|
||||
updateControlStatus,
|
||||
updateSensorUI,
|
||||
updateSwitchStatusUI,
|
||||
updateUptimeUI,
|
||||
updateWebsocketStatus,
|
||||
updateWifiStatusUI
|
||||
@@ -85,6 +86,12 @@ function onWsMessage(event) {
|
||||
updateWifiStatusUI(decodedMessage.wifiStatus);
|
||||
break;
|
||||
|
||||
case 'swStatus':
|
||||
if (decodedMessage.swStatus) {
|
||||
updateSwitchStatusUI(decodedMessage.swStatus);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'uartData':
|
||||
if (term && decodedMessage.uartData && decodedMessage.uartData.data) {
|
||||
term.write(decodedMessage.uartData.data);
|
||||
|
||||
@@ -61,6 +61,21 @@ export function updateUptimeUI(uptimeInSeconds) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the power switch toggle states based on WebSocket data.
|
||||
* @param {Object} swStatus - The switch status object from the WebSocket message.
|
||||
*/
|
||||
export function updateSwitchStatusUI(swStatus) {
|
||||
if (swStatus) {
|
||||
if (swStatus.main !== undefined) {
|
||||
dom.mainPowerToggle.checked = swStatus.main;
|
||||
}
|
||||
if (swStatus.usb !== undefined) {
|
||||
dom.usbPowerToggle.checked = swStatus.usb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Wi-Fi status indicator in the header.
|
||||
* @param {Object} data - The Wi-Fi status object from the WebSocket.
|
||||
|
||||
Reference in New Issue
Block a user