充电逻辑修改初步定档
This commit is contained in:
@@ -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 "识别中...";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user