From c61d39a7e1f47f94aceaac1bb7e538afa913c332 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 24 Feb 2024 10:43:15 -0800 Subject: [PATCH] Pull device hardware from a local json file --- Meshtastic.xcodeproj/project.pbxproj | 4 + .../contents | 8 + Meshtastic/Resources/DeviceHardware.json | 274 ++++++++++++++++++ Meshtastic/Views/Settings/Channels.swift | 3 +- .../Views/Settings/Config/PowerConfig.swift | 1 + Meshtastic/Views/Settings/FirmwareApi.swift | 7 +- 6 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 Meshtastic/Resources/DeviceHardware.json diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 56190b9c..4c34f671 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ DD0E20FC2B87090400F2D100 /* atak.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0E20F92B87090400F2D100 /* atak.pb.swift */; }; DD0E20FD2B87090400F2D100 /* clientonly.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0E20FA2B87090400F2D100 /* clientonly.pb.swift */; }; DD0E20FE2B87090400F2D100 /* paxcount.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0E20FB2B87090400F2D100 /* paxcount.pb.swift */; }; + DD0E21012B8A6F1300F2D100 /* DeviceHardware.json in Resources */ = {isa = PBXBuildFile; fileRef = DD0E21002B8A6BC500F2D100 /* DeviceHardware.json */; }; DD0F791B28713C8A00A6FDAD /* AdminMessageList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0F791A28713C8A00A6FDAD /* AdminMessageList.swift */; }; DD13AA492AB73BF400BA0C98 /* PositionPopover.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD13AA482AB73BF400BA0C98 /* PositionPopover.swift */; }; DD1925B728CDA5A400720036 /* CannedMessagesConfigEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1925B628CDA5A400720036 /* CannedMessagesConfigEnums.swift */; }; @@ -264,6 +265,7 @@ DD0E20FA2B87090400F2D100 /* clientonly.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = clientonly.pb.swift; sourceTree = ""; }; DD0E20FB2B87090400F2D100 /* paxcount.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = paxcount.pb.swift; sourceTree = ""; }; DD0E20FF2B892E1300F2D100 /* MeshtasticDataModelV 28.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 28.xcdatamodel"; sourceTree = ""; }; + DD0E21002B8A6BC500F2D100 /* DeviceHardware.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = DeviceHardware.json; sourceTree = ""; }; DD0E9C222A30CE3A00580CBB /* MeshtasticDataModelV14.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModelV14.xcdatamodel; sourceTree = ""; }; DD0F791A28713C8A00A6FDAD /* AdminMessageList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdminMessageList.swift; sourceTree = ""; }; DD13AA482AB73BF400BA0C98 /* PositionPopover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionPopover.swift; sourceTree = ""; }; @@ -865,6 +867,7 @@ children = ( DDB75A192A05EB67006ED576 /* alpha.png */, DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */, + DD0E21002B8A6BC500F2D100 /* DeviceHardware.json */, ); path = Resources; sourceTree = ""; @@ -1137,6 +1140,7 @@ DDDE5A1329AFEAB900490C6C /* Assets.xcassets in Resources */, DDB75A1A2A05EB67006ED576 /* alpha.png in Resources */, DDC2E15C26CE248F0042C5E4 /* Assets.xcassets in Resources */, + DD0E21012B8A6F1300F2D100 /* DeviceHardware.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 28.xcdatamodel/contents b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 28.xcdatamodel/contents index 5c178f33..daadbce4 100644 --- a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 28.xcdatamodel/contents +++ b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV 28.xcdatamodel/contents @@ -72,6 +72,14 @@ + + + + + + + + diff --git a/Meshtastic/Resources/DeviceHardware.json b/Meshtastic/Resources/DeviceHardware.json new file mode 100644 index 00000000..c7940a0a --- /dev/null +++ b/Meshtastic/Resources/DeviceHardware.json @@ -0,0 +1,274 @@ +[ + { + "hwModel": 1, + "hwModelSlug": "TLORA_V2", + "platformioTarget": "tlora-v2", + "architecture": "esp32", + "activelySupported": false, + "displayName": "T-LoRa V2" + }, + { + "hwModel": 2, + "hwModelSlug": "TLORA_V1", + "platformioTarget": "tlora-v1", + "architecture": "esp32", + "activelySupported": false, + "displayName": "T-LoRa V1" + }, + { + "hwModel": 3, + "hwModelSlug": "TLORA_V2_1_1P6", + "platformioTarget": "tlora-v2-1-1_6", + "architecture": "esp32", + "activelySupported": true, + "displayName": "T-LoRa V2.1-1.6" + }, + { + "hwModel": 4, + "hwModelSlug": "TBEAM", + "platformioTarget": "tbeam", + "architecture": "esp32", + "activelySupported": true, + "displayName": "T-Beam" + }, + { + "hwModel": 5, + "hwModelSlug": "HELTEC_V2_0", + "platformioTarget": "heltec-v2_0", + "architecture": "esp32", + "activelySupported": false, + "displayName": "Heltec V2.0" + }, + { + "hwModel": 6, + "hwModelSlug": "TBEAM_V0P7", + "platformioTarget": "tbeam0_7", + "architecture": "esp32", + "activelySupported": false, + "displayName": "T-Beam V0.7" + }, + { + "hwModel": 7, + "hwModelSlug": "T_ECHO", + "platformioTarget": "t-echo", + "architecture": "nrf52840", + "activelySupported": true, + "displayName": "T-Echo" + }, + { + "hwModel": 8, + "hwModelSlug": "TLORA_V1_1P3", + "platformioTarget": "tlora-v1_3", + "architecture": "esp32", + "activelySupported": false, + "displayName": "T-LoRa V1.1-1.3" + }, + { + "hwModel": 9, + "hwModelSlug": "RAK4631", + "platformioTarget": "rak4631", + "architecture": "nrf52840", + "activelySupported": true, + "displayName": "RAK4631" + }, + { + "hwModel": 10, + "hwModelSlug": "HELTEC_V2_1", + "platformioTarget": "heltec-v2_1", + "architecture": "esp32", + "activelySupported": false, + "displayName": "Heltec V2.1" + }, + { + "hwModel": 11, + "hwModelSlug": "HELTEC_V1", + "platformioTarget": "heltec-v1", + "architecture": "esp32", + "activelySupported": false, + "displayName": "Heltec V1" + }, + { + "hwModel": 12, + "hwModelSlug": "TBEAM_S3_CORE", + "platformioTarget": "tbeam-s3-core", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "T-Beam S3 Core" + }, + { + "hwModel": 13, + "hwModelSlug": "RAK11200", + "platformioTarget": "rak11200", + "architecture": "esp32", + "activelySupported": false, + "displayName": "RAK11200" + }, + { + "hwModel": 14, + "hwModelSlug": "NANO_G1", + "platformioTarget": "nano-g1", + "architecture": "esp32", + "activelySupported": true, + "displayName": "Nano G1" + }, + { + "hwModel": 15, + "hwModelSlug": "TLORA_V2_1_1P8", + "platformioTarget": "tlora-v2-1-1_8", + "architecture": "esp32", + "activelySupported": true, + "displayName": "T-LoRa V2.1-1.8" + }, + { + "hwModel": 16, + "hwModelSlug": "TLORA_T3_S3", + "platformioTarget": "tlora-t3s3-v1", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "T-LoRa T3-S3" + }, + { + "hwModel": 17, + "hwModelSlug": "NANO_G1_EXPLORER", + "platformioTarget": "nano-g1-explorer", + "architecture": "esp32", + "activelySupported": true, + "displayName": "Nano G1 Explorer" + }, + { + "hwModel": 18, + "hwModelSlug": "NANO_G2_ULTRA", + "platformioTarget": "nano-g2-ultra", + "architecture": "nrf52840", + "activelySupported": true, + "displayName": "Nano G2 Ultra" + }, + { + "hwModel": 25, + "hwModelSlug": "STATION_G1", + "platformioTarget": "station-g1", + "architecture": "esp32", + "activelySupported": true, + "displayName": "Station G1" + }, + { + "hwModel": 26, + "hwModelSlug": "RAK11310", + "platformioTarget": "rak11310", + "architecture": "rp2040", + "activelySupported": true, + "displayName": "RAK11310" + }, + { + "hwModel": 39, + "hwModelSlug": "DIY_V1", + "platformioTarget": "meshtastic-diy-v1", + "architecture": "esp32", + "activelySupported": true, + "displayName": "DIY V1" + }, + { + "hwModel": 39, + "hwModelSlug": "HYDRA", + "platformioTarget": "hydra", + "architecture": "esp32", + "activelySupported": true, + "displayName": "Hydra" + }, + { + "hwModel": 41, + "hwModelSlug": "DR_DEV", + "platformioTarget": "meshtastic-dr-dev", + "architecture": "esp32", + "activelySupported": true, + "displayName": "DR-DEV" + }, + { + "hwModel": 42, + "hwModelSlug": "M5STACK", + "platformioTarget": "m5stack-core", + "architecture": "esp32", + "activelySupported": true, + "displayName": "M5 Stack" + }, + { + "hwModel": 43, + "hwModelSlug": "HELTEC_V3", + "platformioTarget": "heltec-v3", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "Heltec V3" + }, + { + "hwModel": 44, + "hwModelSlug": "HELTEC_WSL_V3", + "platformioTarget": "heltec-wsl-v3", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "Heltec Wireless Stick Lite V3" + }, + { + "hwModel": 47, + "hwModelSlug": "RPI_PICO", + "platformioTarget": "pico", + "architecture": "rp2040", + "activelySupported": true, + "displayName": "Raspberry Pi Pico" + }, + { + "hwModel": 47, + "hwModelSlug": "RPI_PICO", + "platformioTarget": "picow", + "architecture": "rp2040", + "activelySupported": true, + "displayName": "Raspberry Pi Pico W" + }, + { + "hwModel": 48, + "hwModelSlug": "HELTEC_WIRELESS_TRACKER", + "platformioTarget": "heltec-wireless-tracker", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "Heltec Wireless Tracker" + }, + { + "hwModel": 49, + "hwModelSlug": "HELTEC_WIRELESS_PAPER", + "platformioTarget": "heltec-wireless-paper", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "Heltec Wireless Paper" + }, + { + "hwModel": 50, + "hwModelSlug": "T_DECK", + "platformioTarget": "t-deck", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "T-Deck" + }, + { + "hwModel": 51, + "hwModelSlug": "T_WATCH_S3", + "platformioTarget": "t-watch-s3", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "T-Watch S3" + }, + { + "hwModel": 52, + "hwModelSlug": "PICOMPUTER_S3", + "platformioTarget": "picomputer-s3", + "architecture": "esp32-s3", + "activelySupported": true, + "displayName": "Pi Computer S3" + }, + { + "hwModel": 53, + "hwModelSlug": "HELTEC_HT62", + "platformioTarget": "heltec-ht62-esp32c3-sx1262", + "architecture": "esp32-c3", + "activelySupported": true, + "displayName": "Heltec HT62" + } +] diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index 6209fee4..04f95032 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -228,9 +228,10 @@ struct Channels: View { } Section(header: Text("position")) { + VStack(alignment: .leading) { Toggle(isOn: $positionsEnabled) { - Label("Positions Enabled", systemImage: positionsEnabled ? "mappin" : "mappin.slash") + Label(channelRole == 1 ? "Positions Enabled" : "Allow Position Requests", systemImage: positionsEnabled ? "mappin" : "mappin.slash") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) .disabled(!supportedVersion) diff --git a/Meshtastic/Views/Settings/Config/PowerConfig.swift b/Meshtastic/Views/Settings/Config/PowerConfig.swift index ae3536cd..aa207f83 100644 --- a/Meshtastic/Views/Settings/Config/PowerConfig.swift +++ b/Meshtastic/Views/Settings/Config/PowerConfig.swift @@ -122,6 +122,7 @@ struct PowerConfig: View { } Api().loadDeviceHardwareData { (hw) in + for device in hw { let currentHardware = node?.user?.hwModel ?? "UNSET" let deviceString = device.hwModelSlug.replacingOccurrences(of: "_", with: "") diff --git a/Meshtastic/Views/Settings/FirmwareApi.swift b/Meshtastic/Views/Settings/FirmwareApi.swift index f020e514..fe9b5128 100644 --- a/Meshtastic/Views/Settings/FirmwareApi.swift +++ b/Meshtastic/Views/Settings/FirmwareApi.swift @@ -46,10 +46,13 @@ struct FirmwareRelease: Codable { class Api : ObservableObject{ func loadDeviceHardwareData(completion:@escaping ([DeviceHardware]) -> ()) { - guard let url = URL(string: "https://api.meshtastic.org/resource/deviceHardware") else { - print("Invalid url...") + + /// List from https://api.meshtastic.org/resource/deviceHardware + guard let url = Bundle.main.url(forResource: "DeviceHardware.json", withExtension: nil) else { + print("Couldn't find DeviceHardware.json in main bundle.") return } + URLSession.shared.dataTask(with: url) { data, response, error in let deviceHardware = try! JSONDecoder().decode([DeviceHardware].self, from: data!) DispatchQueue.main.async {