85 lines
4.3 KiB
Swift
85 lines
4.3 KiB
Swift
import Foundation
|
||
|
||
/// Erfundene Werte für den Simulator, damit sich die Ansichten ohne iPhone und
|
||
/// ohne Fahrzeug prüfen lassen. Eingeschaltet über `CAMPER_DEMO=1`:
|
||
///
|
||
/// xcrun simctl launch --terminate-running-process booted \
|
||
/// de.fritob.CamperMonitor.watchkitapp
|
||
/// # mit SIMCTL_CHILD_CAMPER_DEMO=1 davor
|
||
///
|
||
/// Im normalen Betrieb wird hiervon nichts ausgeführt.
|
||
enum WatchDemo {
|
||
|
||
private static let profile = Profile(name: "Kastenwagen", symbol: "box.truck",
|
||
trackWidth: 1.85, wheelbase: 3.50)
|
||
|
||
private static let solarID = UUID(uuidString: "00000000-0000-0000-0000-000000000050")!
|
||
private static let batteryID = UUID(uuidString: "00000000-0000-0000-0000-0000000000A0")!
|
||
private static let fridgeID = UUID(uuidString: "00000000-0000-0000-0000-0000000000F0")!
|
||
private static let levelID = UUID(uuidString: "00000000-0000-0000-0000-0000000000E0")!
|
||
|
||
/// `seconds` läuft weiter, damit sich die Neigung bewegt – sonst zeigt der
|
||
/// Ausrichtungs-Assistent nie einen Trend.
|
||
static func payload(at seconds: Double) -> WatchPayload {
|
||
let now = Date()
|
||
let swing = sin(seconds / 8)
|
||
|
||
var level = LevelState()
|
||
level.pitch = 1.4 * swing + 0.3
|
||
level.roll = -0.9 * cos(seconds / 11)
|
||
level.pitchOffset = 0.4
|
||
level.rollOffset = -0.2
|
||
|
||
var solar = DeviceSnapshot(deviceID: solarID, timestamp: now, rssi: -58)
|
||
solar.state = "Konstantspannung (Absorption)"
|
||
solar.metrics = [
|
||
Metric("pv_power", "PV-Leistung", 284 + 40 * swing, unit: "W", precision: 0, primary: true),
|
||
Metric("battery_voltage", "Batteriespannung", 14.12, unit: "V", precision: 2),
|
||
Metric("battery_current", "Ladestrom", 18.6, unit: "A", precision: 1),
|
||
]
|
||
|
||
var battery = DeviceSnapshot(deviceID: batteryID, timestamp: now, rssi: -64)
|
||
battery.state = "Lädt"
|
||
battery.metrics = [
|
||
Metric("soc", "Ladezustand", 78.4, unit: "%", precision: 1, primary: true),
|
||
Metric("voltage", "Spannung", 13.66, unit: "V", precision: 2),
|
||
Metric("current", "Strom", 18.6, unit: "A", precision: 1),
|
||
Metric("capacity", "Restkapazität", 156.8, unit: "Ah", precision: 1),
|
||
]
|
||
|
||
var fridge = DeviceSnapshot(deviceID: fridgeID, timestamp: now, rssi: -66)
|
||
fridge.state = "Kompressor läuft"
|
||
fridge.metrics = [
|
||
Metric("temperature", "Innentemperatur", 6, unit: "°C", precision: 0, primary: true),
|
||
Metric("target", "Solltemperatur", 4, unit: "°C", precision: 0),
|
||
Metric("battery_voltage", "Bordspannung", 12.7, unit: "V", precision: 1),
|
||
]
|
||
|
||
return WatchPayload(
|
||
generatedAt: now,
|
||
profile: profile,
|
||
isRadioReady: true,
|
||
radioStatus: "Demo-Modus",
|
||
devices: [
|
||
WatchDevice(id: levelID, name: "Nivellierung", role: .leveling,
|
||
link: .live, snapshot: level.snapshot(deviceID: levelID, rssi: -70),
|
||
level: level, orientation: .identity/*, fridge: nil*/),
|
||
/*WatchDevice(id: batteryID, name: "Bulltron 200 Ah", role: .bms,
|
||
link: .live, snapshot: battery, level: nil,
|
||
orientation: nil, fridge: nil),
|
||
WatchDevice(id: solarID, name: "Solar Dach", role: .solarCharger,
|
||
link: .live, snapshot: solar, level: nil,
|
||
orientation: nil, fridge: nil),
|
||
WatchDevice(id: fridgeID, name: "Kühlbox", role: .fridge,
|
||
link: .live, snapshot: fridge, level: nil, orientation: nil,
|
||
fridge: WatchFridge(isLive: true, updated: now,
|
||
isPoweredOn: true, isEco: true, isLocked: false,
|
||
isDualZone: false, unitSymbol: "°C",
|
||
leftTarget: 4, leftCurrent: 6,
|
||
rightTarget: nil, rightCurrent: nil,
|
||
minTarget: -20, maxTarget: 20,
|
||
batteryVolts: 12.7)),*/
|
||
])
|
||
}
|
||
}
|