Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4857aa5d1b | |||
| 9066b0f703 | |||
| 23d5c3b341 | |||
| 6af7ad6cd2 | |||
| afc83c16c3 | |||
| c5e5280de7 |
@@ -24,9 +24,7 @@
|
||||
|
||||
| 版本 | 主题 | 状态 |
|
||||
| :--- | :--- | :--- |
|
||||
| 1.4.0 | SAF 权限改造 | ✅ 已发布 |
|
||||
| 1.4.5 | 魅族20系补充适配调整 | ✅ 已发布 |
|
||||
| 1.5.0 | 功率计算优化 | 📋 规划中 |
|
||||
| 1.5.0 | 功率计算优化 | ✅ 已发布 |
|
||||
| 2.0.0 | 数据看板扩展(月/季/年趋势) | 📋 远景 |
|
||||
|
||||
---
|
||||
@@ -49,4 +47,5 @@ flutter pub get
|
||||
flutter run
|
||||
|
||||
# Release APK
|
||||
flutter build apk --release
|
||||
flutter build apk --release --target-platform android-arm64
|
||||
```
|
||||
@@ -1,31 +1,36 @@
|
||||
/// 容量提取工具
|
||||
/// 支持两种日志格式:
|
||||
/// 1. learned_cap(21 系列):单位 µAh,除以 1000 得到 mAh
|
||||
/// 2. remaining_cap(20 系列):单位 mAh,直接使用(但 21 系列的 remaining_cap 也是 µAh,需判断)
|
||||
///
|
||||
/// 🟢 1.4.5 优化:仅从 status=Full 的行中提取容量(充满状态下 BMS 最准确)
|
||||
/// 🟢 优先级最高,不受 status 限制(BMS 可能在任意状态行更新此值)
|
||||
/// 2. remaining_cap(20 系列):仅从 status=Full 行提取,单位智能识别(µAh/mAh)
|
||||
class CapacityExtractor {
|
||||
static int? extractCapacity(List<String> lines) {
|
||||
// 🟢 只保留包含 tbat= 且 status=Full 的行
|
||||
final fullLines = lines.where((line) {
|
||||
return line.contains('tbat=') && line.contains('status=Full');
|
||||
}).toList();
|
||||
final validLines = lines.where((line) => line.contains('tbat=')).toList();
|
||||
if (validLines.isEmpty) return null;
|
||||
|
||||
if (fullLines.isEmpty) {
|
||||
// 今天没有充满电的记录,返回 null 表示无有效数据
|
||||
return null;
|
||||
}
|
||||
|
||||
// 模式一:learned_cap(21 系列)
|
||||
// ============================================================
|
||||
// 🟢 第一优先级:learned_cap(21 系列专属)
|
||||
// 不限制 status,在所有有效行中搜索,取最新的一条
|
||||
// ============================================================
|
||||
final learnedReg = RegExp(r'learned_cap=(\d+)');
|
||||
for (String line in fullLines.reversed) {
|
||||
for (String line in validLines.reversed) {
|
||||
final match = learnedReg.firstMatch(line);
|
||||
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_cap(20 系列回退方案)
|
||||
// 仅从 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+)');
|
||||
int? maxRemaining;
|
||||
for (String line in fullLines) {
|
||||
@@ -39,7 +44,7 @@ class CapacityExtractor {
|
||||
}
|
||||
if (maxRemaining == null) return null;
|
||||
|
||||
// 🟢 判断单位:如果数值大于 100000(约 100 mAh),则认为是 µAh,需除以 1000
|
||||
// 🟢 智能单位识别:如果数值大于 100000(约 100 mAh),视为 µAh 需除以 1000
|
||||
if (maxRemaining > 100000) {
|
||||
return maxRemaining ~/ 1000;
|
||||
} else {
|
||||
|
||||
@@ -38,8 +38,9 @@ class ChargeParser {
|
||||
final result = <Map<String, dynamic>>[];
|
||||
for (String line in lines) {
|
||||
final timestamp = TimeUtils.parseLogTimestamp(line);
|
||||
if (!TimeUtils.isLogTimestampValid(timestamp, chargingStartTime))
|
||||
if (!TimeUtils.isLogTimestampValid(timestamp, chargingStartTime)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final isUsb =
|
||||
line.contains('chg_usb') &&
|
||||
@@ -101,7 +102,7 @@ class ChargeParser {
|
||||
return ParseResult(
|
||||
isWireless: false,
|
||||
chargeType: chargeType,
|
||||
power: (vbus * ibus) / 1000000000.0,
|
||||
power: (vbus * ibus) / 1000000000000.0,
|
||||
volt: vbus / 1000000.0,
|
||||
curr: ibus / 1000000.0,
|
||||
wiredLevel: chargeType == 'PPS' ? level : null,
|
||||
|
||||
@@ -613,7 +613,8 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
|
||||
if (_isWireless) {
|
||||
return ChargeUtils.getDisplayPowerWireless(_chargePower);
|
||||
} else {
|
||||
return ChargeUtils.getDisplayPowerWired(
|
||||
// 🟢 1.5.0 改用新格式:实际/标定
|
||||
return ChargeUtils.getMainDisplayPowerWired(
|
||||
_chargePower,
|
||||
_wiredLevel,
|
||||
_chargeType,
|
||||
@@ -630,7 +631,8 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.white,
|
||||
// 🟢 1.5.0 统一状态栏颜色
|
||||
statusBarColor: Color.fromRGBO(157, 212, 237, 0.1),
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import '../constants/charge_maps.dart';
|
||||
|
||||
class ChargeUtils {
|
||||
// ============ 无线充电(保持不变) ============
|
||||
static String getDisplayPowerWireless(double power) {
|
||||
if (power == 0) return '读取中...';
|
||||
const List<int> levels = [5, 7, 15, 27, 40, 50, 66];
|
||||
@@ -12,21 +13,17 @@ class ChargeUtils {
|
||||
return '≈${matchedLevel}W';
|
||||
}
|
||||
|
||||
// ============ 原有有线逻辑(保留兼容,但主界面不再直接调用) ============
|
||||
static String getDisplayPowerWired(
|
||||
double power,
|
||||
int? wiredLevel,
|
||||
String chargeType,
|
||||
) {
|
||||
// USB 慢充锁定 7.5W
|
||||
if (chargeType == "SDP") return "≈7.5W";
|
||||
|
||||
// 🟢 优先使用 wiredLevel 精确匹配
|
||||
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
|
||||
double p = ChargeMaps.wiredPower[wiredLevel]!;
|
||||
if (p > 0) return '≈${p.toInt()}W';
|
||||
}
|
||||
|
||||
// 🟢 匹配阈值收窄到 ±3W,减少跳变
|
||||
double best = 0;
|
||||
for (var entry in ChargeMaps.wiredPower.entries) {
|
||||
if (entry.value <= power + 3 && entry.value > best) {
|
||||
@@ -37,11 +34,61 @@ class ChargeUtils {
|
||||
return best > 0 ? '≈${best.toInt()}W' : '≈${power.round()}W';
|
||||
}
|
||||
|
||||
// ============ 🟢 1.5.0 新增:主界面显示(实际/标定) ============
|
||||
/// 示例:≈30w/65w
|
||||
static String getMainDisplayPowerWired(
|
||||
double power,
|
||||
int? wiredLevel,
|
||||
String chargeType,
|
||||
) {
|
||||
// USB 慢充锁定 7.5W
|
||||
if (chargeType == "SDP") return "≈7.5w";
|
||||
|
||||
if (power == 0) return "读取中...";
|
||||
|
||||
final actual = power.round();
|
||||
|
||||
// 有档位且能查到标定值
|
||||
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
|
||||
final requested = ChargeMaps.wiredPower[wiredLevel]!.round();
|
||||
return "≈${actual}w/${requested}w";
|
||||
}
|
||||
|
||||
// 无档位信息,仅显示实际功率
|
||||
return "≈${actual}w";
|
||||
}
|
||||
|
||||
// ============ 🟢 1.5.0 新增:二级页面标定档位显示 ============
|
||||
/// 示例:≈80w/L-10
|
||||
static String getDetailRequestedPowerWired(
|
||||
double power,
|
||||
int? wiredLevel,
|
||||
String chargeType,
|
||||
) {
|
||||
if (chargeType == "SDP") return "≈7.5w";
|
||||
|
||||
if (power == 0) return "读取中...";
|
||||
|
||||
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
|
||||
final requested = ChargeMaps.wiredPower[wiredLevel]!.round();
|
||||
return "≈${requested}w/L-$wiredLevel";
|
||||
}
|
||||
|
||||
return "≈${power.round()}w";
|
||||
}
|
||||
|
||||
// ============ 🟢 1.5.0 新增:二级页面实际功率显示 ============
|
||||
static String getDetailActualPowerWired(double power, String chargeType) {
|
||||
if (chargeType == "SDP") return "≈7.5w";
|
||||
if (power == 0) return "读取中...";
|
||||
return "≈${power.round()}w";
|
||||
}
|
||||
|
||||
// ============ 充电类型标签(保持不变) ============
|
||||
static String getChargeTypeLabel(bool isWireless, String chargeType) {
|
||||
if (isWireless) {
|
||||
return chargeType == "无线" ? "无线" : chargeType;
|
||||
}
|
||||
// 🟢 空类型显示"识别中...",比"等待log信息"更友好
|
||||
if (chargeType.isEmpty) {
|
||||
return "识别中...";
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../utils/charge_utils.dart';
|
||||
|
||||
/// 充电详情页
|
||||
@@ -11,22 +12,14 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
final int? wiredLevel;
|
||||
|
||||
const ChargeDetailPage({
|
||||
super.key,
|
||||
Key? key,
|
||||
required this.chargeType,
|
||||
required this.isWireless,
|
||||
required this.power,
|
||||
required this.volt,
|
||||
required this.curr,
|
||||
this.wiredLevel,
|
||||
});
|
||||
|
||||
String _getDisplayPower() {
|
||||
if (isWireless) {
|
||||
return ChargeUtils.getDisplayPowerWireless(power);
|
||||
} else {
|
||||
return ChargeUtils.getDisplayPowerWired(power, wiredLevel, chargeType);
|
||||
}
|
||||
}
|
||||
}) : super(key: key);
|
||||
|
||||
String _getProtocolDisplay() {
|
||||
if (isWireless) return '无线充电($chargeType)';
|
||||
@@ -35,13 +28,36 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
return chargeType;
|
||||
}
|
||||
|
||||
String _getRequestedDisplay() {
|
||||
return ChargeUtils.getDetailRequestedPowerWired(
|
||||
power,
|
||||
wiredLevel,
|
||||
chargeType,
|
||||
);
|
||||
}
|
||||
|
||||
String _getActualDisplay() {
|
||||
return ChargeUtils.getDetailActualPowerWired(power, chargeType);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
// 🟢 1.5.0 与主界面统一状态栏样式
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Color.fromRGBO(157, 212, 237, 0.5),
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text('充电详情'),
|
||||
backgroundColor: const Color.fromARGB(0, 255, 255, 255),
|
||||
backgroundColor: Colors.white, // 🟢 与主界面统一
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
shadowColor: Colors.transparent,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
foregroundColor: Colors.black,
|
||||
iconTheme: const IconThemeData(color: Colors.black),
|
||||
),
|
||||
@@ -52,16 +68,31 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
children: [
|
||||
_buildDetailRow('协议', _getProtocolDisplay()),
|
||||
const Divider(),
|
||||
_buildDetailRow('功率', _getDisplayPower()),
|
||||
|
||||
// 有线充电:标定档位 + 实际功率
|
||||
if (!isWireless) ...[
|
||||
_buildDetailRow('标定档位', _getRequestedDisplay()),
|
||||
const Divider(),
|
||||
_buildDetailRow('实际功率', _getActualDisplay()),
|
||||
const Divider(),
|
||||
] else ...[
|
||||
_buildDetailRow(
|
||||
'功率',
|
||||
ChargeUtils.getDisplayPowerWireless(power),
|
||||
),
|
||||
const Divider(),
|
||||
],
|
||||
|
||||
_buildDetailRow('电压', '${volt.toStringAsFixed(2)}V'),
|
||||
const Divider(),
|
||||
_buildDetailRow('电流', '${curr.toStringAsFixed(2)}A'),
|
||||
const Divider(),
|
||||
if (!isWireless && wiredLevel != null)
|
||||
_buildDetailRow('档位', '$wiredLevel'),
|
||||
if (!isWireless && wiredLevel == null) _buildDetailRow('档位', '自动'),
|
||||
|
||||
// 辅助信息
|
||||
if (isWireless) _buildDetailRow('类型', '无线'),
|
||||
if (!isWireless && wiredLevel == null)
|
||||
_buildDetailRow('档位', '自动'),
|
||||
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Text(
|
||||
@@ -72,6 +103,7 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
# 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.
|
||||
version: 1.4.7
|
||||
version: 1.5.0
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.2
|
||||
|
||||
Reference in New Issue
Block a user