Add some tests and move the helpers into their own TS file

This commit is contained in:
Jack Kingsman
2026-04-10 14:52:34 -07:00
parent f9f046a05f
commit 8752320f52
3 changed files with 84 additions and 27 deletions
+1 -27
View File
@@ -17,36 +17,10 @@ import {
BATTERY_DISPLAY_CHANGE_EVENT,
getShowBatteryPercent,
getShowBatteryVoltage,
mvToPercent,
} from '../utils/batteryDisplay';
import { cn } from '@/lib/utils';
// Meshtastic default OCV table (meshtastic/firmware src/power.h)
const OCV_TABLE: [number, number][] = [
[4190, 100],
[4050, 90],
[3990, 80],
[3890, 70],
[3800, 60],
[3720, 50],
[3630, 40],
[3530, 30],
[3420, 20],
[3300, 10],
[3100, 0],
];
function mvToPercent(mv: number): number {
if (mv >= OCV_TABLE[0][0]) return 100;
if (mv <= OCV_TABLE[OCV_TABLE.length - 1][0]) return 0;
for (let i = 0; i < OCV_TABLE.length - 1; i++) {
const [highMv, highPct] = OCV_TABLE[i];
const [lowMv, lowPct] = OCV_TABLE[i + 1];
if (mv >= lowMv)
return Math.round(lowPct + ((mv - lowMv) / (highMv - lowMv)) * (highPct - lowPct));
}
return 0;
}
interface StatusBarProps {
health: HealthStatus | null;
config: RadioConfig | null;