mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-14 22:55:12 +10:00
Fix repeater battery % inconsistency and add configurable repeater battery chemistry (#199)
* fix(repeater): unify battery percentage math and add repeater chemistry setting - Add shared battery percent utility used by connector, repeater status, and telemetry - Add repeater-specific battery chemistry persistence and service accessors - Add repeater chemistry selector in Repeater Hub - Ensure telemetry and status compute percentages consistently from same chemistry - Add focused battery utility tests Refs #116 Refs #174 * fix: Flutter Analyzer Errors fixed Recent Merge Compatible * Unify repeater battery source across status and telemetry
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
typedef BatteryVoltageRange = ({int minMv, int maxMv});
|
||||
|
||||
BatteryVoltageRange batteryVoltageRange(String chemistry) {
|
||||
switch (chemistry) {
|
||||
case 'lifepo4':
|
||||
return (minMv: 2600, maxMv: 3650);
|
||||
case 'lipo':
|
||||
return (minMv: 3000, maxMv: 4200);
|
||||
case 'nmc':
|
||||
default:
|
||||
return (minMv: 3000, maxMv: 4200);
|
||||
}
|
||||
}
|
||||
|
||||
int estimateBatteryPercentFromMillivolts(int millivolts, String chemistry) {
|
||||
final range = batteryVoltageRange(chemistry);
|
||||
if (millivolts <= range.minMv) return 0;
|
||||
if (millivolts >= range.maxMv) return 100;
|
||||
return (((millivolts - range.minMv) * 100) / (range.maxMv - range.minMv))
|
||||
.round();
|
||||
}
|
||||
|
||||
int estimateBatteryPercentFromVolts(double volts, String chemistry) {
|
||||
final millivolts = (volts * 1000).round();
|
||||
return estimateBatteryPercentFromMillivolts(millivolts, chemistry);
|
||||
}
|
||||
Reference in New Issue
Block a user