This commit is contained in:
legop3
2026-01-28 13:59:29 -05:00
parent 7e850dab22
commit ae81f8914f
4 changed files with 77 additions and 43 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -11,7 +11,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
<title>Multi Roomba Rover</title>
<script type="module" crossorigin src="/assets/index-DCabXYAC.js"></script>
<script type="module" crossorigin src="/assets/index-COFUfdDa.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-lg9md4T4.css">
</head>
<body>
+21 -5
View File
@@ -5,6 +5,19 @@ const { sendAlert } = require('./alertService');
const ALERT_COLOR = '#00bcd4';
const { handleAck } = require('./commandService');
function coerceBool(value) {
if (typeof value === 'boolean') return value;
if (typeof value === 'number') return value !== 0;
if (typeof value === 'string') {
const normalized = value.trim().toLowerCase();
if (normalized === 'true') return true;
if (normalized === 'false') return false;
if (normalized === '1') return true;
if (normalized === '0') return false;
}
return null;
}
const HEARTBEAT_INTERVAL_MS = 15000;
function handleMessage(roverId, msg) {
@@ -16,13 +29,15 @@ function handleMessage(roverId, msg) {
case 'sensor':
roverManager.handleSensorFrame(roverId, msg);
break;
case 'event':
if (msg.event === 'nightVision.state' && typeof msg.data?.nightVisionOn === 'boolean') {
roverManager.setNightVisionState(roverId, msg.data.nightVisionOn);
case 'event': {
const nightVisionOn = coerceBool(msg.data?.nightVisionOn);
if (msg.event === 'nightVision.state' && nightVisionOn != null) {
roverManager.setNightVisionState(roverId, nightVisionOn);
break;
}
sendAlert({ color: ALERT_COLOR, title: `${roverId} event`, message: msg.event });
break;
}
default:
break;
}
@@ -73,8 +88,9 @@ roverWSS.on('connection', (ws) => {
} else if (msg.type === 'ack') {
handleAck(msg);
} else if (msg.type === 'event') {
if (msg.event === 'nightVision.state' && typeof msg.data?.nightVisionOn === 'boolean') {
roverManager.setNightVisionState(roverId, msg.data.nightVisionOn);
const nightVisionOn = coerceBool(msg.data?.nightVisionOn);
if (msg.event === 'nightVision.state' && nightVisionOn != null) {
roverManager.setNightVisionState(roverId, nightVisionOn);
} else {
sendAlert({ color: ALERT_COLOR, title: `${roverId}`, message: msg.event });
}