Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update battery chemistry protocol with new types
- Rename NMC to LiPo as standard for dev boards
- Add 'none' option for external power (wall-powered devices)
- Add lead acid support (12V solar/off-grid setups)
- Protocol: 0x00=none, 0x01=lipo, 0x02=lifepo4, 0x03=leadacid
- Add migration for old stored values (nmc/liion -> lipo)
- Make return type nullable for 'none' chemistry
  • Loading branch information
rsp2k committed Feb 7, 2026
commit da778b95bb0bdd73997823e8a33ff3af59e8a43a
13 changes: 4 additions & 9 deletions lib/connector/meshcore_connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ class MeshCoreConnector extends ChangeNotifier {
if (_reportedBatteryChemistry != null) return _reportedBatteryChemistry!;
// Fall back to user setting
final deviceId = _device?.remoteId.toString();
if (deviceId == null || _appSettingsService == null) return 'nmc';
if (deviceId == null || _appSettingsService == null) return 'lipo';
return _appSettingsService!.batteryChemistryForDevice(deviceId);
}

// Uses shared utility from battery_utils.dart
int _estimateBatteryPercent(int millivolts, String chemistry) {
int? _estimateBatteryPercent(int millivolts, String chemistry) {
return estimateBatteryPercent(millivolts, chemistry);
}

Expand Down Expand Up @@ -1882,18 +1882,13 @@ class MeshCoreConnector extends ChangeNotifier {
// [1-2] = battery_mv (uint16 LE)
// [3-6] = storage_used_kb (uint32 LE)
// [7-10] = storage_total_kb (uint32 LE)
// [11] = battery_chemistry (optional, 0=NMC, 1=LiFePO4, 2=LiPo)
// [11] = battery_chemistry (optional: 0=none, 1=lipo, 2=lifepo4, 3=leadacid)
if (frame.length >= 3) {
_batteryMillivolts = readUint16LE(frame, 1);

// Check for optional chemistry byte at offset 11 (protocol extension)
if (frame.length > 11) {
final chemByte = frame[11];
_reportedBatteryChemistry = switch (chemByte) {
0x01 => 'lifepo4',
0x02 => 'lipo',
_ => 'nmc',
};
_reportedBatteryChemistry = chemistryFromByte(frame[11]);
}

final volts = (_batteryMillivolts! / 1000.0).toStringAsFixed(2);
Expand Down
7 changes: 4 additions & 3 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@
}
},
"appSettings_batteryChemistryConnectFirst": "Connect to a device to choose",
"appSettings_batteryNmc": "18650 NMC (3.0-4.2V)",
"appSettings_batteryLifepo4": "LiFePO4 (2.6-3.65V)",
"appSettings_batteryLipo": "LiPo (3.0-4.2V)",
"appSettings_batteryNone": "No Battery (External Power)",
"appSettings_batteryLipo": "LiPo (3.7V)",
"appSettings_batteryLifepo4": "LiFePO4 (3.2V)",
"appSettings_batteryLeadAcid": "Lead Acid (12V)",
"appSettings_mapDisplay": "Map Display",
"appSettings_showRepeaters": "Show Repeaters",
"appSettings_showRepeatersSubtitle": "Display repeater nodes on the map",
Expand Down
20 changes: 13 additions & 7 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1108,23 +1108,29 @@ abstract class AppLocalizations {
/// **'Connect to a device to choose'**
String get appSettings_batteryChemistryConnectFirst;

/// No description provided for @appSettings_batteryNmc.
/// No description provided for @appSettings_batteryNone.
///
/// In en, this message translates to:
/// **'18650 NMC (3.0-4.2V)'**
String get appSettings_batteryNmc;
/// **'No Battery (External Power)'**
String get appSettings_batteryNone;

/// No description provided for @appSettings_batteryLipo.
///
/// In en, this message translates to:
/// **'LiPo (3.7V)'**
String get appSettings_batteryLipo;

/// No description provided for @appSettings_batteryLifepo4.
///
/// In en, this message translates to:
/// **'LiFePO4 (2.6-3.65V)'**
/// **'LiFePO4 (3.2V)'**
String get appSettings_batteryLifepo4;

/// No description provided for @appSettings_batteryLipo.
/// No description provided for @appSettings_batteryLeadAcid.
///
/// In en, this message translates to:
/// **'LiPo (3.0-4.2V)'**
String get appSettings_batteryLipo;
/// **'Lead Acid (12V)'**
String get appSettings_batteryLeadAcid;

/// No description provided for @appSettings_mapDisplay.
///
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_bg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,16 @@ class AppLocalizationsBg extends AppLocalizations {
'Свържете се с устройство, за да изберете.';

@override
String get appSettings_batteryNmc => '18650 NMC (3.0-4.2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'Литиев полимер (3.0-4.2V)';

@override
String get appSettings_batteryLifepo4 => 'Литиево желязо фосфат (2.6-3.65V)';

@override
String get appSettings_batteryLipo => 'Литиев полимер (3.0-4.2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Карта за показване';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,16 @@ class AppLocalizationsDe extends AppLocalizations {
'Verbinde ein Gerät, um zu wählen';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0–4,2 V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0–4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6–3,65 V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0–4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Kartendarstellung';
Expand Down
9 changes: 6 additions & 3 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,16 @@ class AppLocalizationsEn extends AppLocalizations {
'Connect to a device to choose';

@override
String get appSettings_batteryNmc => '18650 NMC (3.0-4.2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2.6-3.65V)';
String get appSettings_batteryLipo => 'LiPo (3.7V)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0-4.2V)';
String get appSettings_batteryLifepo4 => 'LiFePO4 (3.2V)';

@override
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Map Display';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,16 @@ class AppLocalizationsEs extends AppLocalizations {
'Conéctate a un dispositivo para elegir';

@override
String get appSettings_batteryNmc => '18650 NMC (3.0-4.2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0-4.2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2.6-3.65V)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0-4.2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Visualización del Mapa';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,16 @@ class AppLocalizationsFr extends AppLocalizations {
'Connectez un appareil pour choisir';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0-4,2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6-3,65V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Affichage de la carte';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,16 @@ class AppLocalizationsIt extends AppLocalizations {
'Connetti a un dispositivo per scegliere';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0-4,2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6-3,65V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Visualizzazione Mappa';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_nl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,16 @@ class AppLocalizationsNl extends AppLocalizations {
'Verbind met een apparaat om te selecteren';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0-4,2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6-3,65V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Kaartweergave';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_pl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,16 @@ class AppLocalizationsPl extends AppLocalizations {
'Połącz się z urządzeniem, aby wybrać';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0-4,2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6-3,65 V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Wyświetlanie mapy';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_pt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,16 @@ class AppLocalizationsPt extends AppLocalizations {
'Conecte-se a um dispositivo para escolher';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0-4,2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6-3,65V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Exibição do Mapa';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,16 @@ class AppLocalizationsRu extends AppLocalizations {
'Подключитесь к устройству, чтобы выбрать';

@override
String get appSettings_batteryNmc => '18650 NMC (3.0–4.2 В)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0–4.2 В)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2.6–3.65 В)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0–4.2 В)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Отображение карты';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_sk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,16 @@ class AppLocalizationsSk extends AppLocalizations {
'Pripojte sa k zariadeniu na výber';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0-4,2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6–3,65V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Zobrazenie mapy';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_sl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,16 @@ class AppLocalizationsSl extends AppLocalizations {
'Za izbiro se poveži z napravo';

@override
String get appSettings_batteryNmc => '18650 NMC (3,0-4,2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6–3,65 V)';

@override
String get appSettings_batteryLipo => 'LiPo (3,0-4,2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Prikaz zemljevida';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_sv.dart
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,16 @@ class AppLocalizationsSv extends AppLocalizations {
'Anslut till en enhet för att välja';

@override
String get appSettings_batteryNmc => '18650 NMC (3.0-4.2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0-4.2V)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2,6–3,65V)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0-4.2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Kartvisning';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_uk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,16 @@ class AppLocalizationsUk extends AppLocalizations {
'Підключіть пристрій, щоб вибрати';

@override
String get appSettings_batteryNmc => '18650 NMC (3.0-4.2В)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0-4.2В)';

@override
String get appSettings_batteryLifepo4 => 'LiFePO4 (2.6-3.65В)';

@override
String get appSettings_batteryLipo => 'LiPo (3.0-4.2В)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => 'Відображення карти';
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_localizations_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,16 @@ class AppLocalizationsZh extends AppLocalizations {
String get appSettings_batteryChemistryConnectFirst => '连接到设备以进行选择';

@override
String get appSettings_batteryNmc => '18650 型号,NMC 电池(3.0-4.2V)';
String get appSettings_batteryNone => 'No Battery (External Power)';

@override
String get appSettings_batteryLipo => '锂离子电池 (3.0-4.2V)';

@override
String get appSettings_batteryLifepo4 => '磷酸铁锂 (2.6-3.65V)';

@override
String get appSettings_batteryLipo => '锂离子电池 (3.0-4.2V)';
String get appSettings_batteryLeadAcid => 'Lead Acid (12V)';

@override
String get appSettings_mapDisplay => '地图展示';
Expand Down
Loading