fix(power): 完善电池卡片的共同供电判定、功率图标与预估续航
按适配器和电池的实际贡献判定共同供电,以双图标和双色柱展示两路功率。同步三语预估续航文案,在仅外接供电时隐藏估时行。
This commit is contained in:
@@ -17,6 +17,20 @@ import Foundation
|
||||
let combined = read(["BatteryPower": NSNumber(value: UInt64(bitPattern: -8000)), "SystemPowerIn": 30_000])
|
||||
precondition(combined.battery?.watts == -8 && combined.state == .combined)
|
||||
precondition(combined.load == PowerReading(watts: 38, source: .balance))
|
||||
let standby = read(["BatteryPower": -4700, "SystemPowerIn": 100, "SystemLoad": 6300], extra: adapter)
|
||||
precondition(standby.state == .battery && standby.input?.watts == 0.1 && standby.jointSupply == nil)
|
||||
let tinyDischarge = read(["BatteryPower": -100, "SystemPowerIn": 6300, "SystemLoad": 6400])
|
||||
precondition(tinyDischarge.state == .external && tinyDischarge.jointSupply == nil)
|
||||
let contradictory = read(["BatteryPower": -4700, "SystemPowerIn": 6000, "SystemLoad": 6300])
|
||||
precondition(contradictory.state == .discharging && contradictory.jointSupply == nil)
|
||||
var primaryBattery = BatteryMonitor()
|
||||
let withAssist = primaryBattery.powerFlow(["ExternalConnected": true, "PowerTelemetryData":
|
||||
["SystemPowerIn": 12_000, "BatteryPower": -8000, "SystemLoad": 20_000]], externalSupply: false)
|
||||
precondition(withAssist.state == .combined && withAssist.jointSupply?.batteryFraction == 0.4)
|
||||
let estimatedInput = read(["BatteryPower": -8000, "SystemLoad": 38_000])
|
||||
precondition(estimatedInput.jointSupply?.adapter == PowerReading(watts: 30, source: .balance))
|
||||
let estimatedAssist = read(["SystemPowerIn": 30_000, "SystemLoad": 38_000])
|
||||
precondition(estimatedAssist.jointSupply?.discharge == PowerReading(watts: 8, source: .balance))
|
||||
let staleCharge = read(["BatteryPower": 6_000], extra: ["Voltage": 12_000, "InstantAmperage": 0, "IsCharging": false])
|
||||
precondition(staleCharge.battery?.watts == 0 && staleCharge.state == .external)
|
||||
let unknownWatts = read([:], extra: ["IsCharging": true])
|
||||
@@ -65,6 +79,18 @@ import Foundation
|
||||
var joint = combined
|
||||
joint.applyBatterySensor(-10)
|
||||
precondition(joint.battery?.watts == -10 && joint.state == .combined && joint.load == nil)
|
||||
precondition(joint.jointSupply?.batteryFraction == 8.0 / 38 && joint.jointSupply?.discharge.watts == 8)
|
||||
joint.applyBatterySensor(2)
|
||||
precondition(joint.state == .charging && joint.jointSupply == nil)
|
||||
var missingPair = read(["SystemPowerIn": 6000])
|
||||
missingPair.applyBatterySensor(-5)
|
||||
precondition(missingPair.state == .discharging && missingPair.jointSupply == nil)
|
||||
var clock = BatteryMetrics(charge: 0.8, flow: combined, minutesToFull: 20, minutesToEmpty: 345)
|
||||
precondition(clock.minutesRemaining == 345)
|
||||
clock.flow = charging
|
||||
precondition(clock.minutesRemaining == 20)
|
||||
clock.flow = idle
|
||||
precondition(clock.minutesRemaining == nil && BatteryMonitor.positiveMinutes(65535) == nil)
|
||||
print("PASS: signed battery watts, adapter limits, joint supply, measured and derived values, stale telemetry")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,10 @@ import SwiftUI
|
||||
sample.date = sample.date.addingTimeInterval(2)
|
||||
sample.battery?.flow = BatteryPowerFlow(connected: true, externalSupply: true, battery: PowerReading(watts: 34.8))
|
||||
history.append(sample)
|
||||
sample.date.addTimeInterval(2)
|
||||
sample.battery?.flow = BatteryPowerFlow(connected: true, externalSupply: true,
|
||||
battery: PowerReading(watts: -8), input: PowerReading(watts: 12))
|
||||
history.append(sample)
|
||||
}
|
||||
host.rootView = AnyView(PowerResourceCard(snapshot: sample, samples: history.samples, sleepIntervals: history.sleepIntervals,
|
||||
chartInterval: 2, chartBoundaries: [], chartIntervals: history.samples.map(\.expectedInterval)))
|
||||
@@ -81,8 +85,9 @@ import SwiftUI
|
||||
let bars = plot.layoutData.bars
|
||||
precondition(plot.bounds.height >= 24 && plot.bounds.maxY < host.bounds.height)
|
||||
if state == .present {
|
||||
precondition(bars.map(\.charge) == [0.77, 0.77, 0.77])
|
||||
precondition(bars.map(\.state) == [.external, .battery, .charging])
|
||||
precondition(bars.map(\.charge) == [0.77, 0.77, 0.77, 0.77])
|
||||
precondition(bars.map(\.state) == [.external, .battery, .charging, .combined])
|
||||
precondition(bars.last?.batteryFraction == 0.4)
|
||||
for bar in bars { precondition(plot.layoutData.hit(at: bar.x) == .sample(bar.index)) }
|
||||
} else { precondition(bars.isEmpty) }
|
||||
}
|
||||
@@ -161,6 +166,13 @@ import SwiftUI
|
||||
snapshot.battery = BatteryMetrics(charge: charge, flow: flow)
|
||||
history.append(snapshot)
|
||||
}
|
||||
let joint = BatteryPowerFlow(connected: true, externalSupply: true, battery: PowerReading(watts: -10),
|
||||
input: PowerReading(watts: 10))
|
||||
for _ in 0..<3 {
|
||||
snapshot.date.addTimeInterval(2)
|
||||
snapshot.battery = BatteryMetrics(charge: 1, flow: joint)
|
||||
history.append(snapshot)
|
||||
}
|
||||
let plot = BatteryHistoryPlot(frame: CGRect(x: 0, y: 0, width: 590, height: 51))
|
||||
let layout = BatteryHistoryLayout(samples: history.samples, sleeps: [], width: plot.bounds.width)
|
||||
plot.layoutData = layout
|
||||
@@ -175,6 +187,12 @@ import SwiftUI
|
||||
precondition((0.1...0.4).contains(alpha(bars[i].x, 16)))
|
||||
precondition((0.1...0.4).contains(alpha(bars[i].x, 34)))
|
||||
}
|
||||
let jointX = Int(bars[5].x * CGFloat(bitmap.pixelsWide) / plot.bounds.width)
|
||||
let jointPixels = [10, 30].map { y in
|
||||
bitmap.colorAt(x: jointX, y: y * bitmap.pixelsHigh / Int(plot.bounds.height))!.usingColorSpace(.sRGB)!
|
||||
}
|
||||
precondition(jointPixels.contains { $0.blueComponent > $0.greenComponent } &&
|
||||
jointPixels.contains { $0.greenComponent > $0.blueComponent })
|
||||
let half = [alpha(bars[1].x, 16), alpha(bars[1].x, 34)].sorted()
|
||||
precondition((0.1...0.4).contains(half[0]) && half[1] > 0.95)
|
||||
precondition(alpha(bars[2].x, 16) > 0.95 && alpha(bars[2].x, 34) > 0.95)
|
||||
|
||||
Reference in New Issue
Block a user