充电逻辑修改初步定档
This commit is contained in:
@@ -613,7 +613,8 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
|
|||||||
if (_isWireless) {
|
if (_isWireless) {
|
||||||
return ChargeUtils.getDisplayPowerWireless(_chargePower);
|
return ChargeUtils.getDisplayPowerWireless(_chargePower);
|
||||||
} else {
|
} else {
|
||||||
return ChargeUtils.getDisplayPowerWired(
|
// 🟢 1.5.0 改用新格式:实际/标定
|
||||||
|
return ChargeUtils.getMainDisplayPowerWired(
|
||||||
_chargePower,
|
_chargePower,
|
||||||
_wiredLevel,
|
_wiredLevel,
|
||||||
_chargeType,
|
_chargeType,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import '../constants/charge_maps.dart';
|
import '../constants/charge_maps.dart';
|
||||||
|
|
||||||
class ChargeUtils {
|
class ChargeUtils {
|
||||||
|
// ============ 无线充电(保持不变) ============
|
||||||
static String getDisplayPowerWireless(double power) {
|
static String getDisplayPowerWireless(double power) {
|
||||||
if (power == 0) return '读取中...';
|
if (power == 0) return '读取中...';
|
||||||
const List<int> levels = [5, 7, 15, 27, 40, 50, 66];
|
const List<int> levels = [5, 7, 15, 27, 40, 50, 66];
|
||||||
@@ -12,21 +13,17 @@ class ChargeUtils {
|
|||||||
return '≈${matchedLevel}W';
|
return '≈${matchedLevel}W';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ 原有有线逻辑(保留兼容,但主界面不再直接调用) ============
|
||||||
static String getDisplayPowerWired(
|
static String getDisplayPowerWired(
|
||||||
double power,
|
double power,
|
||||||
int? wiredLevel,
|
int? wiredLevel,
|
||||||
String chargeType,
|
String chargeType,
|
||||||
) {
|
) {
|
||||||
// USB 慢充锁定 7.5W
|
|
||||||
if (chargeType == "SDP") return "≈7.5W";
|
if (chargeType == "SDP") return "≈7.5W";
|
||||||
|
|
||||||
// 🟢 优先使用 wiredLevel 精确匹配
|
|
||||||
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
|
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
|
||||||
double p = ChargeMaps.wiredPower[wiredLevel]!;
|
double p = ChargeMaps.wiredPower[wiredLevel]!;
|
||||||
if (p > 0) return '≈${p.toInt()}W';
|
if (p > 0) return '≈${p.toInt()}W';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🟢 匹配阈值收窄到 ±3W,减少跳变
|
|
||||||
double best = 0;
|
double best = 0;
|
||||||
for (var entry in ChargeMaps.wiredPower.entries) {
|
for (var entry in ChargeMaps.wiredPower.entries) {
|
||||||
if (entry.value <= power + 3 && entry.value > best) {
|
if (entry.value <= power + 3 && entry.value > best) {
|
||||||
@@ -37,11 +34,61 @@ class ChargeUtils {
|
|||||||
return best > 0 ? '≈${best.toInt()}W' : '≈${power.round()}W';
|
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) {
|
static String getChargeTypeLabel(bool isWireless, String chargeType) {
|
||||||
if (isWireless) {
|
if (isWireless) {
|
||||||
return chargeType == "无线" ? "无线" : chargeType;
|
return chargeType == "无线" ? "无线" : chargeType;
|
||||||
}
|
}
|
||||||
// 🟢 空类型显示"识别中...",比"等待log信息"更友好
|
|
||||||
if (chargeType.isEmpty) {
|
if (chargeType.isEmpty) {
|
||||||
return "识别中...";
|
return "识别中...";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,22 +11,14 @@ class ChargeDetailPage extends StatelessWidget {
|
|||||||
final int? wiredLevel;
|
final int? wiredLevel;
|
||||||
|
|
||||||
const ChargeDetailPage({
|
const ChargeDetailPage({
|
||||||
super.key,
|
Key? 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 _getDisplayPower() {
|
|
||||||
if (isWireless) {
|
|
||||||
return ChargeUtils.getDisplayPowerWireless(power);
|
|
||||||
} else {
|
|
||||||
return ChargeUtils.getDisplayPowerWired(power, wiredLevel, chargeType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String _getProtocolDisplay() {
|
String _getProtocolDisplay() {
|
||||||
if (isWireless) return '无线充电($chargeType)';
|
if (isWireless) return '无线充电($chargeType)';
|
||||||
@@ -35,12 +27,26 @@ class ChargeDetailPage extends StatelessWidget {
|
|||||||
return chargeType;
|
return chargeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 🟢 1.5.0 标定档位显示
|
||||||
|
String _getRequestedDisplay() {
|
||||||
|
return ChargeUtils.getDetailRequestedPowerWired(
|
||||||
|
power,
|
||||||
|
wiredLevel,
|
||||||
|
chargeType,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 🟢 1.5.0 实际功率显示
|
||||||
|
String _getActualDisplay() {
|
||||||
|
return ChargeUtils.getDetailActualPowerWired(power, chargeType);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('充电详情'),
|
title: const Text('充电详情'),
|
||||||
backgroundColor: const Color.fromARGB(0, 255, 255, 255),
|
backgroundColor: Colors.transparent,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
foregroundColor: Colors.black,
|
foregroundColor: Colors.black,
|
||||||
iconTheme: const IconThemeData(color: Colors.black),
|
iconTheme: const IconThemeData(color: Colors.black),
|
||||||
@@ -52,16 +58,28 @@ class ChargeDetailPage extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
_buildDetailRow('协议', _getProtocolDisplay()),
|
_buildDetailRow('协议', _getProtocolDisplay()),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
_buildDetailRow('功率', _getDisplayPower()),
|
|
||||||
|
// 🟢 1.5.0 有线充电:标定档位 + 实际功率 两行
|
||||||
|
if (!isWireless) ...[
|
||||||
|
_buildDetailRow('标定档位', _getRequestedDisplay()),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
_buildDetailRow('实际功率', _getActualDisplay()),
|
||||||
|
const Divider(),
|
||||||
|
] else ...[
|
||||||
|
// 无线充电:保持原样,只显示功率
|
||||||
|
_buildDetailRow('功率', ChargeUtils.getDisplayPowerWireless(power)),
|
||||||
|
const Divider(),
|
||||||
|
],
|
||||||
|
|
||||||
_buildDetailRow('电压', '${volt.toStringAsFixed(2)}V'),
|
_buildDetailRow('电压', '${volt.toStringAsFixed(2)}V'),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
_buildDetailRow('电流', '${curr.toStringAsFixed(2)}A'),
|
_buildDetailRow('电流', '${curr.toStringAsFixed(2)}A'),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
if (!isWireless && wiredLevel != null)
|
|
||||||
_buildDetailRow('档位', '$wiredLevel'),
|
// 辅助信息
|
||||||
if (!isWireless && wiredLevel == null) _buildDetailRow('档位', '自动'),
|
|
||||||
if (isWireless) _buildDetailRow('类型', '无线'),
|
if (isWireless) _buildDetailRow('类型', '无线'),
|
||||||
|
if (!isWireless && wiredLevel == null) _buildDetailRow('档位', '自动'),
|
||||||
|
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|||||||
+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
|
# 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.4.7
|
version: 1.5.0-dev.1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.9.2
|
sdk: ^3.9.2
|
||||||
|
|||||||
Reference in New Issue
Block a user