mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
hopefully fixed discord dock / undock alerts?
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
@@ -5,8 +5,8 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>webui</title>
|
||||
<script type="module" crossorigin src="/assets/index-DAo0n__B.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-BjMfmH4X.css">
|
||||
<script type="module" crossorigin src="/assets/index-Dsw_Z9n0.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-CCqAmxiE.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -20,6 +20,7 @@ function getState(roverId) {
|
||||
lastPercent: null,
|
||||
warned: false,
|
||||
urgent: false,
|
||||
onDock: false,
|
||||
dockedCharging: false,
|
||||
charging: false,
|
||||
batteryLocked: false,
|
||||
@@ -64,6 +65,21 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
||||
const chargingState = sensors?.chargingState?.code;
|
||||
const chargingSources = sensors?.chargingSources;
|
||||
const onDock = Boolean(chargingSources?.homeBase);
|
||||
if (onDock && !state.onDock) {
|
||||
state.onDock = true;
|
||||
publishEvent({
|
||||
source: 'batteryManager',
|
||||
type: 'battery.docked',
|
||||
payload: { roverId, batteryState },
|
||||
});
|
||||
} else if (!onDock && state.onDock) {
|
||||
state.onDock = false;
|
||||
publishEvent({
|
||||
source: 'batteryManager',
|
||||
type: 'battery.undocked',
|
||||
payload: { roverId, batteryState },
|
||||
});
|
||||
}
|
||||
const isCharging = chargingState === 1 || chargingState === 2 || chargingState === 3;
|
||||
if (isCharging && !state.charging) {
|
||||
state.charging = true;
|
||||
@@ -83,18 +99,8 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
||||
const dockedCharging = onDock && isCharging;
|
||||
if (dockedCharging && !state.dockedCharging) {
|
||||
state.dockedCharging = true;
|
||||
publishEvent({
|
||||
source: 'batteryManager',
|
||||
type: 'battery.docked',
|
||||
payload: { roverId, batteryState },
|
||||
});
|
||||
} else if (!dockedCharging && state.dockedCharging) {
|
||||
state.dockedCharging = false;
|
||||
publishEvent({
|
||||
source: 'batteryManager',
|
||||
type: 'battery.undocked',
|
||||
payload: { roverId, batteryState },
|
||||
});
|
||||
}
|
||||
|
||||
const fullThreshold =
|
||||
|
||||
@@ -2,7 +2,8 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useChat } from '../context/ChatContext.jsx';
|
||||
import { useSession } from '../context/SessionContext.jsx';
|
||||
|
||||
function roleColors(role) {
|
||||
function roleColors(role, fromDiscord) {
|
||||
if (fromDiscord) return 'text-indigo-200';
|
||||
switch (role) {
|
||||
case 'admin':
|
||||
case 'lockdown':
|
||||
@@ -73,11 +74,15 @@ export default function ChatPanel() {
|
||||
<div
|
||||
key={msg.id}
|
||||
className={`surface-muted text-sm flex items-start gap-1 ${
|
||||
isAdmin ? 'border border-amber-400/30' : msg.fromDiscord? 'border border-indigo-400/30' : ''
|
||||
isAdmin
|
||||
? 'border border-amber-400/30'
|
||||
: msg.fromDiscord
|
||||
? 'border border-indigo-400/30 bg-indigo-900/20'
|
||||
: ''
|
||||
}`}
|
||||
>
|
||||
<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, msg.fromDiscord)}`}>
|
||||
{displayName(msg)}
|
||||
</span>
|
||||
{msg.fromDiscord && (
|
||||
|
||||
Reference in New Issue
Block a user