mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 01:50:47 -04:00
battery manager / discord bot fix. add discord tag in chat.
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -5,8 +5,8 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>webui</title>
|
<title>webui</title>
|
||||||
<script type="module" crossorigin src="/assets/index-Bw29mQyW.js"></script>
|
<script type="module" crossorigin src="/assets/index-DAo0n__B.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-vVHPhuT9.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-BjMfmH4X.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ function getState(roverId) {
|
|||||||
warned: false,
|
warned: false,
|
||||||
urgent: false,
|
urgent: false,
|
||||||
dockedCharging: false,
|
dockedCharging: false,
|
||||||
|
charging: false,
|
||||||
batteryLocked: false,
|
batteryLocked: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -64,6 +65,21 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
|||||||
const chargingSources = sensors?.chargingSources;
|
const chargingSources = sensors?.chargingSources;
|
||||||
const onDock = Boolean(chargingSources?.homeBase);
|
const onDock = Boolean(chargingSources?.homeBase);
|
||||||
const isCharging = chargingState === 1 || chargingState === 2 || chargingState === 3;
|
const isCharging = chargingState === 1 || chargingState === 2 || chargingState === 3;
|
||||||
|
if (isCharging && !state.charging) {
|
||||||
|
state.charging = true;
|
||||||
|
publishEvent({
|
||||||
|
source: 'batteryManager',
|
||||||
|
type: 'battery.charging.start',
|
||||||
|
payload: { roverId, batteryState },
|
||||||
|
});
|
||||||
|
} else if (!isCharging && state.charging) {
|
||||||
|
state.charging = false;
|
||||||
|
publishEvent({
|
||||||
|
source: 'batteryManager',
|
||||||
|
type: 'battery.charging.stop',
|
||||||
|
payload: { roverId, batteryState },
|
||||||
|
});
|
||||||
|
}
|
||||||
const dockedCharging = onDock && isCharging;
|
const dockedCharging = onDock && isCharging;
|
||||||
if (dockedCharging && !state.dockedCharging) {
|
if (dockedCharging && !state.dockedCharging) {
|
||||||
state.dockedCharging = true;
|
state.dockedCharging = true;
|
||||||
@@ -74,6 +90,11 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
|||||||
});
|
});
|
||||||
} else if (!dockedCharging && state.dockedCharging) {
|
} else if (!dockedCharging && state.dockedCharging) {
|
||||||
state.dockedCharging = false;
|
state.dockedCharging = false;
|
||||||
|
publishEvent({
|
||||||
|
source: 'batteryManager',
|
||||||
|
type: 'battery.undocked',
|
||||||
|
payload: { roverId, batteryState },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullThreshold =
|
const fullThreshold =
|
||||||
@@ -82,7 +103,9 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
|||||||
(batteryState?.charge != null && fullThreshold != null && batteryState.charge >= fullThreshold) ||
|
(batteryState?.charge != null && fullThreshold != null && batteryState.charge >= fullThreshold) ||
|
||||||
(batteryState?.percent != null && batteryState.percent >= 0.99);
|
(batteryState?.percent != null && batteryState.percent >= 0.99);
|
||||||
|
|
||||||
if (dockedCharging && lockable && !state.batteryLocked && !isFull) {
|
const needsCharge = state.warned;
|
||||||
|
|
||||||
|
if (dockedCharging && lockable && needsCharge && !state.batteryLocked && !isFull) {
|
||||||
logger.info('Auto-locking rover for charging', { roverId });
|
logger.info('Auto-locking rover for charging', { roverId });
|
||||||
lockRover(roverId, true, { reason: 'battery' });
|
lockRover(roverId, true, { reason: 'battery' });
|
||||||
state.batteryLocked = true;
|
state.batteryLocked = true;
|
||||||
@@ -105,6 +128,8 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
|||||||
});
|
});
|
||||||
lockRover(roverId, false, { reason: 'battery' });
|
lockRover(roverId, false, { reason: 'battery' });
|
||||||
state.batteryLocked = false;
|
state.batteryLocked = false;
|
||||||
|
state.warned = false;
|
||||||
|
state.urgent = false;
|
||||||
publishEvent({
|
publishEvent({
|
||||||
source: 'batteryManager',
|
source: 'batteryManager',
|
||||||
type: 'battery.unlocked',
|
type: 'battery.unlocked',
|
||||||
|
|||||||
@@ -306,6 +306,30 @@ function handleBusEvent(event) {
|
|||||||
description: `${payload?.roverId} is docked and charging.`,
|
description: `${payload?.roverId} is docked and charging.`,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case 'battery.undocked':
|
||||||
|
announce({
|
||||||
|
channelId: channels.adminAlerts,
|
||||||
|
color: 0x2196f3,
|
||||||
|
title: 'Undocked',
|
||||||
|
description: `${payload?.roverId} undocked.`,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'battery.charging.start':
|
||||||
|
announce({
|
||||||
|
channelId: channels.adminAlerts,
|
||||||
|
color: 0x2196f3,
|
||||||
|
title: 'Charging Started',
|
||||||
|
description: `${payload?.roverId} started charging.`,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'battery.charging.stop':
|
||||||
|
announce({
|
||||||
|
channelId: channels.adminAlerts,
|
||||||
|
color: 0xf0b651,
|
||||||
|
title: 'Charging Stopped',
|
||||||
|
description: `${payload?.roverId} stopped charging.`,
|
||||||
|
});
|
||||||
|
break;
|
||||||
case 'battery.locked':
|
case 'battery.locked':
|
||||||
announce({
|
announce({
|
||||||
channelId: channels.adminAlerts,
|
channelId: channels.adminAlerts,
|
||||||
|
|||||||
@@ -73,13 +73,18 @@ export default function ChatPanel() {
|
|||||||
<div
|
<div
|
||||||
key={msg.id}
|
key={msg.id}
|
||||||
className={`surface-muted text-sm flex items-start gap-1 ${
|
className={`surface-muted text-sm flex items-start gap-1 ${
|
||||||
isAdmin ? 'border border-amber-400/30' : ''
|
isAdmin ? 'border border-amber-400/30' : msg.fromDiscord? 'border border-indigo-400/30' : ''
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<span className="text-[0.75rem] text-slate-400">{formatTime(msg.ts)}</span>
|
<span className="text-[0.75rem] text-slate-400">{formatTime(msg.ts)}</span>
|
||||||
<span className={`font-semibold text-[0.85rem] ${roleColors(msg.role)}`}>
|
<span className={`font-semibold text-[0.85rem] ${roleColors(msg.role)}`}>
|
||||||
{displayName(msg)}
|
{displayName(msg)}
|
||||||
</span>
|
</span>
|
||||||
|
{msg.fromDiscord && (
|
||||||
|
<span className="rounded bg-indigo-500/30 px-1 text-[0.7rem] text-indigo-100">
|
||||||
|
Discord
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{msg.roverId && (
|
{msg.roverId && (
|
||||||
<span className="rounded bg-slate-800 px-1 text-[0.7rem]">rover {msg.roverId}</span>
|
<span className="rounded bg-slate-800 px-1 text-[0.7rem]">rover {msg.roverId}</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user