mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-07-05 09:22:04 +02:00
Add some tests and move the helpers into their own TS file
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user