| 1 |
// |
|
| 2 |
// MeterCapabilities.swift |
|
| 3 |
// USB Meter |
|
| 4 |
// |
|
| 5 |
// Created by Codex on 23/03/2026. |
|
| 6 |
// |
|
| 7 | ||
| 8 |
import SwiftUI |
|
| 9 | ||
| 10 |
struct MeterCapabilities {
|
|
| 11 |
let availableDataGroupIDs: [UInt8] |
|
| 12 |
let supportsDataGroupCommands: Bool |
|
| 13 |
let supportsScreenSettings: Bool |
|
| 14 |
let supportsRecordingThreshold: Bool |
|
| 15 |
let supportsFahrenheit: Bool |
|
| 16 |
let supportsChargerDetection: Bool |
|
| 17 |
let chargerTypeDescriptions: [UInt16: String] |
|
| 18 | ||
| 19 |
func chargerTypeDescription(for index: UInt16) -> String {
|
|
| 20 |
guard supportsChargerDetection else { return "-" }
|
|
| 21 |
if let label = chargerTypeDescriptions[index] {
|
|
| 22 |
return label |
|
| 23 |
} |
|
| 24 |
return index == 0 ? "Unknown" : "Unknown (\(index))" |
|
| 25 |
} |
|
| 26 |
} |
|
| 27 | ||
| 28 |
extension MeterCapabilities {
|
|
| 29 |
static let umFamily = MeterCapabilities( |
|
| 30 |
availableDataGroupIDs: Array(0...9), |
|
| 31 |
supportsDataGroupCommands: true, |
|
| 32 |
supportsScreenSettings: true, |
|
| 33 |
supportsRecordingThreshold: true, |
|
| 34 |
supportsFahrenheit: true, |
|
| 35 |
supportsChargerDetection: true, |
|
| 36 |
chargerTypeDescriptions: [ |
|
| 37 |
1: "QC2", |
|
| 38 |
2: "QC3", |
|
| 39 |
3: "Apple 2.4A", |
|
| 40 |
4: "Apple 2.1A", |
|
| 41 |
5: "Apple 1.0A", |
|
| 42 |
6: "Apple 0.5A", |
|
| 43 |
7: "DCP 1.5A", |
|
| 44 |
8: "Samsung" |
|
| 45 |
] |
|
| 46 |
) |
|
| 47 | ||
| 48 |
static let tc66c = MeterCapabilities( |
|
| 49 |
availableDataGroupIDs: [0, 1], |
|
| 50 |
supportsDataGroupCommands: false, |
|
| 51 |
supportsScreenSettings: false, |
|
| 52 |
supportsRecordingThreshold: false, |
|
| 53 |
supportsFahrenheit: false, |
|
| 54 |
supportsChargerDetection: false, |
|
| 55 |
chargerTypeDescriptions: [:] |
|
| 56 |
) |
|
| 57 |
} |
|
| 58 | ||
| 59 |
extension Model {
|
|
| 60 |
static let byPeripheralName = Dictionary( |
|
| 61 |
uniqueKeysWithValues: allCases.flatMap { model in
|
|
| 62 |
model.peripheralNames.map { ($0, model) }
|
|
| 63 |
} |
|
| 64 |
) |
|
| 65 | ||
| 66 |
var radio: BluetoothRadio {
|
|
| 67 |
switch self {
|
|
| 68 |
case .UM25C, .UM34C: |
|
| 69 |
return .BT18 |
|
| 70 |
case .TC66C: |
|
| 71 |
return .PW0316 |
|
| 72 |
} |
|
| 73 |
} |
|
| 74 | ||
| 75 |
var peripheralNames: [String] {
|
|
| 76 |
switch self {
|
|
| 77 |
case .UM25C: |
|
| 78 |
return ["UM25C"] |
|
| 79 |
case .UM34C: |
|
| 80 |
return ["UM34C"] |
|
| 81 |
case .TC66C: |
|
| 82 |
return ["TC66C", "PW0316"] |
|
| 83 |
} |
|
| 84 |
} |
|
| 85 | ||
| 86 |
var color: Color {
|
|
| 87 |
switch self {
|
|
| 88 |
case .UM25C: |
|
| 89 |
return .blue |
|
| 90 |
case .UM34C: |
|
| 91 |
return .yellow |
|
| 92 |
case .TC66C: |
|
| 93 |
return .black |
|
| 94 |
} |
|
| 95 |
} |
|
| 96 | ||
| 97 |
var capabilities: MeterCapabilities {
|
|
| 98 |
switch self {
|
|
| 99 |
case .UM25C, .UM34C: |
|
| 100 |
return .umFamily |
|
| 101 |
case .TC66C: |
|
| 102 |
return .tc66c |
|
| 103 |
} |
|
| 104 |
} |
|
| 105 |
} |