From b05829d01e158245159c263e03e545075cda1d6c Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 17 Nov 2023 15:19:59 +0800 Subject: [PATCH] feat:set weather --- HDFwear.xcodeproj/project.pbxproj | 4 ++++ HDFwear/20231111ReadMe.md | 8 ++++++++ HDFwear/Home/Model/NewWeatherModel.swift | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ HDFwear/Mine/MineViewController.swift | 18 ++++++++++++++++++ HDFwear/Tools/BleMessage+Function.swift | 26 ++++++++++++++++++++++++++ HDFwear/Tools/Bluetooth+Types.swift | 1 + HDFwear/Tools/BluetoothManager+Function.swift | 8 ++++++++ 7 files changed, 148 insertions(+), 0 deletions(-) create mode 100644 HDFwear/Home/Model/NewWeatherModel.swift diff --git a/HDFwear.xcodeproj/project.pbxproj b/HDFwear.xcodeproj/project.pbxproj index 73ffdbf..37c479c 100644 --- a/HDFwear.xcodeproj/project.pbxproj +++ b/HDFwear.xcodeproj/project.pbxproj @@ -282,6 +282,7 @@ 6CFEEBC02773353700621863 /* BOReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBBF2773353700621863 /* BOReferenceVC.swift */; }; 6CFEEBC22773354500621863 /* HRReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC12773354500621863 /* HRReferenceVC.swift */; }; 6CFEEBC42773355700621863 /* SleepReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */; }; + 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; }; B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; }; B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; }; B23AA1032A1879E200BB3902 /* SortPageSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1022A1879E200BB3902 /* SortPageSectionHeader.xib */; }; @@ -657,6 +658,7 @@ 6CFEEBBF2773353700621863 /* BOReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BOReferenceVC.swift; sourceTree = ""; }; 6CFEEBC12773354500621863 /* HRReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HRReferenceVC.swift; sourceTree = ""; }; 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepReferenceVC.swift; sourceTree = ""; }; + 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = ""; }; 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = ""; }; B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = ""; }; @@ -1269,6 +1271,7 @@ children = ( 6C6F40942743933100F9473C /* HealthModel.swift */, 6C6051BD2760C0CB00286B37 /* WeatherModel.swift */, + 847482752B03793C0004F0C2 /* NewWeatherModel.swift */, ); path = Model; sourceTree = ""; @@ -1616,6 +1619,7 @@ 6CC6E57927717FF8006C01A7 /* DailSyncViewController.swift in Sources */, 6C6F406D2743509500F9473C /* MotionViewController.swift in Sources */, 6C1D4D3F27B89BD000C43AA3 /* NFCCardCell.swift in Sources */, + 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */, 6C6505CE2799059D0043DB7A /* TitleView.swift in Sources */, 6C5B545C27759CFA007F7901 /* RemindViewController.swift in Sources */, 6CFE53F4277AAA9900520B00 /* UIImage+Category.swift in Sources */, diff --git a/HDFwear/20231111ReadMe.md b/HDFwear/20231111ReadMe.md index efdef17..e91b428 100644 --- a/HDFwear/20231111ReadMe.md +++ b/HDFwear/20231111ReadMe.md @@ -1,5 +1,7 @@ 接口说明 +示例入口:我的->关于 + 接口实现 BluetoothManager+Function @@ -33,3 +35,9 @@ BluetoothManager+Function 消息ID 0x8015 触发BluetoothSyncDelegate中的didReceiveFindPhoneCommand 接收: [237, 126, 0, 1, 128, 21, 0, 1, 0, 1, 1, 74, 251] + +设置天气 + func newSetWeather(weather: NewWeatherModel, completion: @escaping(_ error: Int?) -> ()) { +发送: [237, 126, 0, 1, 0, 49, 0, 1, 0, 34, 101, 86, 25, 192, 15, 10, 20, 2, 4, 3, 6, 4, 1, 11, 21, 1, 12, 22, 1, 13, 23, 1, 14, 24, 1, 15, 25, 6, 233, 149, 191, 230, 178, 153, 198, 52] +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 0, 192, 215] +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 14, 33, 25] diff --git a/HDFwear/Home/Model/NewWeatherModel.swift b/HDFwear/Home/Model/NewWeatherModel.swift new file mode 100644 index 0000000..cb5a0e8 --- /dev/null +++ b/HDFwear/Home/Model/NewWeatherModel.swift @@ -0,0 +1,83 @@ +// +// NewWeatherModel.swift +// HDFwear +// +// Created by admin on 2023/11/14. +// + +import UIKit +import HandyJSON +import SwiftDate + +enum NewWeatherType: Int, HandyJSONEnum { + case sunny = 1 + case cloudy = 2 + case overcast = 3 + case rain = 4 + case snow = 5 + case smog = 6 + case hail = 7 +} + +enum NewAirQuality: Int, HandyJSONEnum { + case you = 1 + case liang = 2 + case qingdu = 3 + case moderate = 4 + case zhongdu = 5 + case yanzhong = 6 +} + +enum NewWindType: Int, HandyJSONEnum { + case east = 1 + case south = 2 + case west = 3 + case north = 4 + case southeast = 5 + case northeast = 6 + case southwest = 7 + case northwest = 8 +} + +class NewNextWeatherModel: NSObject, HandyJSON { + required override init() { } + var highestTemperature: Int = 0 + var lowestTemperature: Int = 0 + var type: NewWeatherType = .sunny + + init(highestTemperature: Int, lowestTemperature: Int, type: NewWeatherType) { + self.highestTemperature = highestTemperature + self.lowestTemperature = lowestTemperature + self.type = type + } +} + +class NewWeatherModel: NSObject, HandyJSON { + required override init() { } + + var date: Date? + var currentTemperature: Int = 0 + var highestTemperature: Int = 0 + var lowestTemperature: Int = 0 + var type: NewWeatherType = .sunny + var airQuality: NewAirQuality = .you + var humidity: Int = 0 + var wind: NewWindType = .east + var windForce: Int = 0 + var next5Days: Array = [] + var position: String = "" + + init(date: Date? = Date(), currentTemperature: Int, highestTemperature: Int, lowestTemperature: Int, type: NewWeatherType, airQuality: NewAirQuality, humidity: Int, wind: NewWindType, windForce: Int, next5Days: Array, position: String) { + self.date = date + self.currentTemperature = currentTemperature + self.highestTemperature = highestTemperature + self.lowestTemperature = lowestTemperature + self.type = type + self.airQuality = airQuality + self.humidity = humidity + self.wind = wind + self.windForce = windForce + self.next5Days = next5Days + self.position = position + } +} diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index 93b8385..9682185 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -361,6 +361,23 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } + let archiveAction19 = UIAlertAction(title: "newSetWeather", style: .default) { action in + let next5day = [NewNextWeatherModel(highestTemperature: 21, lowestTemperature: 11, type: .sunny), + NewNextWeatherModel(highestTemperature: 22, lowestTemperature: 12, type: .sunny), + NewNextWeatherModel(highestTemperature: 23, lowestTemperature: 13, type: .sunny), + NewNextWeatherModel(highestTemperature: 24, lowestTemperature: 14, type: .sunny), + NewNextWeatherModel(highestTemperature: 25, lowestTemperature: 15, type: .sunny) + ] + let weather = NewWeatherModel(currentTemperature: 18, highestTemperature: 20, lowestTemperature: 10, type: .cloudy, airQuality: .moderate, humidity: 3, wind: .northeast, windForce: 4, next5Days: next5day, position: "长沙") + BluetoothManager.shared.newSetWeather(weather: weather) { error in + if error != nil { + print("newSetWeather" + (error?.description ?? "")) + }else { + print("newSetWeather success") + } + } + } + alert.addAction(archiveAction1) alert.addAction(archiveAction2) alert.addAction(archiveAction3) @@ -379,6 +396,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction16) alert.addAction(archiveAction17) alert.addAction(archiveAction18) + alert.addAction(archiveAction19) present(alert, animated: true, completion: nil) case "我的数据": let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthDataVC") diff --git a/HDFwear/Tools/BleMessage+Function.swift b/HDFwear/Tools/BleMessage+Function.swift index 111119d..f731242 100644 --- a/HDFwear/Tools/BleMessage+Function.swift +++ b/HDFwear/Tools/BleMessage+Function.swift @@ -118,4 +118,30 @@ extension BleMessage { let bytes: [UInt8] = [type.rawValue] return createDataPacket(key: .setSynWatch, bytes: bytes) } + + func getNewWeatherCmd(_ weather: NewWeatherModel) -> Data { + let timeInterval = UInt32(weather.date?.timeIntervalSince1970 ?? 0) + let byte1: UInt8 = UInt8((timeInterval >> 24) & 0xFF) + let byte2: UInt8 = UInt8((timeInterval >> 16) & 0xFF) + let byte3: UInt8 = UInt8((timeInterval >> 8) & 0xFF) + let byte4: UInt8 = UInt8(timeInterval & 0xFF) + +// var uint32Data : [UInt8] = [] +// withUnsafeBytes(of: timeInterval) { uint32Data.append(contentsOf: $0) } + + + var bytes:[UInt8] = [byte1, byte2, byte3, byte4, UInt8(weather.currentTemperature), UInt8(weather.lowestTemperature), UInt8(weather.highestTemperature), UInt8(weather.type.rawValue), UInt8(weather.airQuality.rawValue), UInt8(weather.humidity), UInt8(weather.wind.rawValue), UInt8(weather.windForce)] + for day in weather.next5Days { + bytes += [UInt8(day.type.rawValue), UInt8(day.lowestTemperature), UInt8(day.highestTemperature)] + } + + if let utf8Data = weather.position.data(using: .utf8) { + let utf8Array = Array(utf8Data) + bytes += [UInt8(utf8Array.count)] + utf8Array + } else { + // jtd! + print("转换失败") + } + return createDataPacket(key: .setWeather, bytes: bytes) + } } diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index 9ea3c73..b9a5e3e 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -138,6 +138,7 @@ enum NewCmd: UInt8 { case setUserInfo = 0x0026 case setNoDisturb = 0x0027 case setSynWatch = 0x0028 + case setWeather = 0x0031 //jtd! // case setBeiDouContact = 0x0029 // case setBeiDouQuickAnswer = 0x0030 diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index a8560e8..19c6b89 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -152,6 +152,14 @@ extension BluetoothManager { sendData(data) } + // 设置天气 + // + func newSetWeather(weather: NewWeatherModel, completion: @escaping(_ error: Int?) -> ()) { + let data = BleMessage.shared.getNewWeatherCmd(weather) + self.setCmdClosure = completion + sendData(data) + } + //MARK: - 同步健康数据 // 拉取睡眠数据 func getSleepHistoryData( closure: SleepClosure? = nil) { -- libgit2 0.21.4