mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
new battery bars!!!
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
File diff suppressed because one or more lines are too long
@@ -11,8 +11,8 @@
|
||||
<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-DLm82-hG.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-CnYxiRu2.css">
|
||||
<script type="module" crossorigin src="/assets/index-Ds3QBek7.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-Bz1ixYh7.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -196,6 +196,14 @@ function computeBatteryState(record, sensors) {
|
||||
if (percent != null) {
|
||||
percent = Math.max(0, Math.min(1, percent));
|
||||
}
|
||||
const percentDisplay = computeBatteryDisplayPercent({
|
||||
charge,
|
||||
full,
|
||||
warn,
|
||||
urgent,
|
||||
percent,
|
||||
capacity,
|
||||
});
|
||||
return {
|
||||
charge,
|
||||
capacity,
|
||||
@@ -203,13 +211,41 @@ function computeBatteryState(record, sensors) {
|
||||
warn,
|
||||
urgent,
|
||||
percent,
|
||||
percentDisplay: percent == null ? null : Math.round(percent * 100),
|
||||
percentDisplay,
|
||||
warnActive: Boolean(warn != null && charge != null && charge <= warn),
|
||||
urgentActive: Boolean(urgent != null && charge != null && charge <= urgent),
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
function computeBatteryDisplayPercent({ charge, full, warn, urgent, percent, capacity }) {
|
||||
if (
|
||||
charge != null &&
|
||||
full != null &&
|
||||
warn != null &&
|
||||
urgent != null &&
|
||||
full > warn &&
|
||||
warn > urgent
|
||||
) {
|
||||
if (charge <= urgent) return 0;
|
||||
if (charge <= warn) {
|
||||
const t = (charge - urgent) / (warn - urgent);
|
||||
return Math.round(Math.max(0, Math.min(1, t)) * 10);
|
||||
}
|
||||
if (charge >= full) return 100;
|
||||
const t = (charge - warn) / (full - warn);
|
||||
return Math.round((0.1 + Math.max(0, Math.min(1, t)) * 0.9) * 100);
|
||||
}
|
||||
if (percent != null && Number.isFinite(percent)) {
|
||||
return Math.round(Math.max(0, Math.min(1, percent)) * 100);
|
||||
}
|
||||
if (charge != null && capacity != null && capacity > 0) {
|
||||
const fallback = charge / capacity;
|
||||
return Math.round(Math.max(0, Math.min(1, fallback)) * 100);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function handleSensorFrame(roverId, frame) {
|
||||
const record = rovers.get(roverId);
|
||||
if (!record) return;
|
||||
|
||||
Reference in New Issue
Block a user