针对1.4.7的擦屁股操作:优化status=full的判定逻辑

This commit is contained in:
2026-07-08 23:30:20 +08:00
parent 6af7ad6cd2
commit 23d5c3b341
4 changed files with 26 additions and 21 deletions
+22 -17
View File
@@ -1,31 +1,36 @@
/// 容量提取工具 /// 容量提取工具
/// 支持两种日志格式: /// 支持两种日志格式:
/// 1. learned_cap21 系列):单位 µAh,除以 1000 得到 mAh /// 1. learned_cap21 系列):单位 µAh,除以 1000 得到 mAh
/// 2. remaining_cap20 系列):单位 mAh,直接使用(但 21 系列的 remaining_cap 也是 µAh,需判断 /// 🟢 优先级最高,不受 status 限制(BMS 可能在任意状态行更新此值
/// /// 2. remaining_cap20 系列):仅从 status=Full 行提取,单位智能识别(µAh/mAh)
/// 🟢 1.4.5 优化:仅从 status=Full 的行中提取容量(充满状态下 BMS 最准确)
class CapacityExtractor { class CapacityExtractor {
static int? extractCapacity(List<String> lines) { static int? extractCapacity(List<String> lines) {
// 🟢 只保留包含 tbat= 且 status=Full 的行 final validLines = lines.where((line) => line.contains('tbat=')).toList();
final fullLines = lines.where((line) { if (validLines.isEmpty) return null;
return line.contains('tbat=') && line.contains('status=Full');
}).toList();
if (fullLines.isEmpty) { // ============================================================
// 今天没有充满电的记录,返回 null 表示无有效数据 // 🟢 第一优先级:learned_cap(21 系列专属)
return null; // 不限制 status,在所有有效行中搜索,取最新的一条
} // ============================================================
// 模式一:learned_cap21 系列)
final learnedReg = RegExp(r'learned_cap=(\d+)'); final learnedReg = RegExp(r'learned_cap=(\d+)');
for (String line in fullLines.reversed) { for (String line in validLines.reversed) {
final match = learnedReg.firstMatch(line); final match = learnedReg.firstMatch(line);
if (match != null) { if (match != null) {
return int.parse(match.group(1)!) ~/ 1000; final value = int.parse(match.group(1)!);
// learned_cap 单位固定为 µAh,直接除以 1000 转 mAh
return value ~/ 1000;
} }
} }
// 模式二:remaining_cap 最大值(20 系列,或 21 系列回退) // ============================================================
// 🟢 第二优先级:remaining_cap20 系列回退方案)
// 仅从 status=Full 行提取(充满状态下 BMS 最准确)
// ============================================================
final fullLines = validLines
.where((line) => line.contains('status=Full'))
.toList();
if (fullLines.isEmpty) return null;
final remainingReg = RegExp(r'remaining_cap=(\d+)'); final remainingReg = RegExp(r'remaining_cap=(\d+)');
int? maxRemaining; int? maxRemaining;
for (String line in fullLines) { for (String line in fullLines) {
@@ -39,7 +44,7 @@ class CapacityExtractor {
} }
if (maxRemaining == null) return null; if (maxRemaining == null) return null;
// 🟢 判断单位:如果数值大于 100000(约 100 mAh),则认为是 µAh需除以 1000 // 🟢 智能单位识别:如果数值大于 100000(约 100 mAh),视为 µAh 需除以 1000
if (maxRemaining > 100000) { if (maxRemaining > 100000) {
return maxRemaining ~/ 1000; return maxRemaining ~/ 1000;
} else { } else {
+1 -1
View File
@@ -71,7 +71,7 @@ class ChargeUtils {
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) { if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
final requested = ChargeMaps.wiredPower[wiredLevel]!.round(); final requested = ChargeMaps.wiredPower[wiredLevel]!.round();
return "${requested}w/L-${wiredLevel}"; return "${requested}w/L-$wiredLevel";
} }
return "${power.round()}w"; return "${power.round()}w";
+2 -2
View File
@@ -11,14 +11,14 @@ class ChargeDetailPage extends StatelessWidget {
final int? wiredLevel; final int? wiredLevel;
const ChargeDetailPage({ const ChargeDetailPage({
Key? key, super.key,
required this.chargeType, required this.chargeType,
required this.isWireless, required this.isWireless,
required this.power, required this.power,
required this.volt, required this.volt,
required this.curr, required this.curr,
this.wiredLevel, this.wiredLevel,
}) : super(key: key); });
String _getProtocolDisplay() { String _getProtocolDisplay() {
if (isWireless) return '无线充电($chargeType'; if (isWireless) return '无线充电($chargeType';
+1 -1
View File
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 1.5.0-dev.1 version: 1.5.0-dev.3
environment: environment:
sdk: ^3.9.2 sdk: ^3.9.2