lock on charge, not on dock

This commit is contained in:
legop3
2025-11-20 22:00:51 -05:00
parent efdef8ff1c
commit ff094c2a2b
7 changed files with 23 additions and 24 deletions
+3 -2
View File
@@ -11,9 +11,10 @@
## todo
<!-- 1. battery manager -->
2. pi-side sensor throttle (1/5th)
<!-- 2. pi-side sensor throttle (1/5th) -->
<!-- 3. convert rover roster to a reusable component, unbake it from telemetry and admin panels -->
4. room cameras
<!-- 4. room cameras -->
4. fix gamepad input - add manual inversions?
5. home assistant controls
6. nicknames
7. discord bot
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
+2 -2
View File
@@ -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-CzaSKh_t.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DIvshFK3.css">
<script type="module" crossorigin src="/assets/index-Bd5JgrUJ.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-Cc0W7UiH.css">
</head>
<body>
<div id="root"></div>
+11 -13
View File
@@ -20,7 +20,7 @@ function getState(roverId) {
lastPercent: null,
warned: false,
urgent: false,
docked: false,
dockedCharging: false,
batteryLocked: false,
});
}
@@ -62,20 +62,18 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
const chargingState = sensors?.chargingState?.code;
const chargingSources = sensors?.chargingSources;
const docked =
Boolean(chargingSources?.homeBase) ||
chargingState === 2 ||
chargingState === 3 ||
chargingState === 4;
if (docked && !state.docked) {
state.docked = true;
const onDock = Boolean(chargingSources?.homeBase);
const isCharging = chargingState === 1 || chargingState === 2 || chargingState === 3;
const dockedCharging = onDock && isCharging;
if (dockedCharging && !state.dockedCharging) {
state.dockedCharging = true;
publishEvent({
source: 'batteryManager',
type: 'battery.docked',
payload: { roverId, batteryState },
});
} else if (!docked && state.docked) {
state.docked = false;
} else if (!dockedCharging && state.dockedCharging) {
state.dockedCharging = false;
}
const fullThreshold =
@@ -84,7 +82,7 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
(batteryState?.charge != null && fullThreshold != null && batteryState.charge >= fullThreshold) ||
(batteryState?.percent != null && batteryState.percent >= 0.99);
if (docked && lockable && !state.batteryLocked && !isFull) {
if (dockedCharging && lockable && !state.batteryLocked && !isFull) {
logger.info('Auto-locking rover for charging', { roverId });
lockRover(roverId, true, { reason: 'battery' });
state.batteryLocked = true;
@@ -95,8 +93,8 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
});
}
if (state.batteryLocked && (isFull || !docked)) {
logger.info('Unlocking rover after charge', { roverId, isFull, docked });
if (state.batteryLocked && (isFull || !dockedCharging)) {
logger.info('Unlocking rover after charge', { roverId, isFull, docked: dockedCharging });
lockRover(roverId, false, { reason: 'battery' });
state.batteryLocked = false;
publishEvent({
+5 -5
View File
@@ -247,9 +247,9 @@ function OvercurrentOverlay({ motors }) {
if (!motors?.length) return null;
const labels = motors.map((name) => OVERCURRENT_LABELS[name] || name);
return (
<div className="pointer-events-none absolute inset-0 flex items-center justify-center bg-red-900/60">
<div className="text-center text-2xl font-semibold text-white animate-pulse">
<div>Overcurrent</div>
<div className="pointer-events-none absolute flex items-center justify-center bg-red-900/60 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 p-4">
<div className="text-center text-4xl font-semibold text-white animate-pulse">
<div>OVERCURRENT</div>
<div className="mt-0.5 text-xl font-medium text-white">{labels.join(', ')}</div>
</div>
</div>
@@ -270,10 +270,10 @@ function LowBatteryOverlay({ charge, config }) {
const warnTriggered = urgent != null && charge <= urgent;
if (!warnTriggered && !depleted) return null;
const message = depleted ? 'BATTERY VERY LOW, PLEASE DOCK THE ROVER AND CHARGE IMMEDIATELY!!' : 'Battery low! please dock and charge the rover soon.';
const message = depleted ? 'Battery low! please dock and charge the rover soon.' : 'BATTERY VERY LOW, PLEASE DOCK THE ROVER AND CHARGE IMMEDIATELY!!';
return (
<div className="pointer-events-none absolute inset-0 flex items-center justify-center bg-amber-900/60">
<div className="pointer-events-none absolute flex items-center justify-center bg-amber-900/60 top-10 left-1/2 -translate-x-1/2 p-4">
<div className="text-center text-2xl font-semibold text-white animate-pulse">
<div>{message}</div>
</div>