Commit b05829d01e158245159c263e03e545075cda1d6c

Authored by jason
1 parent 9b19e727

feat:set weather

HDFwear.xcodeproj/project.pbxproj
... ... @@ -282,6 +282,7 @@
282 282 6CFEEBC02773353700621863 /* BOReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBBF2773353700621863 /* BOReferenceVC.swift */; };
283 283 6CFEEBC22773354500621863 /* HRReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC12773354500621863 /* HRReferenceVC.swift */; };
284 284 6CFEEBC42773355700621863 /* SleepReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */; };
  285 + 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; };
285 286 B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; };
286 287 B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; };
287 288 B23AA1032A1879E200BB3902 /* SortPageSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1022A1879E200BB3902 /* SortPageSectionHeader.xib */; };
... ... @@ -657,6 +658,7 @@
657 658 6CFEEBBF2773353700621863 /* BOReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BOReferenceVC.swift; sourceTree = "<group>"; };
658 659 6CFEEBC12773354500621863 /* HRReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HRReferenceVC.swift; sourceTree = "<group>"; };
659 660 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepReferenceVC.swift; sourceTree = "<group>"; };
  661 + 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = "<group>"; };
660 662 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = "<group>"; };
661 663 B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; };
662 664 B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = "<group>"; };
... ... @@ -1269,6 +1271,7 @@
1269 1271 children = (
1270 1272 6C6F40942743933100F9473C /* HealthModel.swift */,
1271 1273 6C6051BD2760C0CB00286B37 /* WeatherModel.swift */,
  1274 + 847482752B03793C0004F0C2 /* NewWeatherModel.swift */,
1272 1275 );
1273 1276 path = Model;
1274 1277 sourceTree = "<group>";
... ... @@ -1616,6 +1619,7 @@
1616 1619 6CC6E57927717FF8006C01A7 /* DailSyncViewController.swift in Sources */,
1617 1620 6C6F406D2743509500F9473C /* MotionViewController.swift in Sources */,
1618 1621 6C1D4D3F27B89BD000C43AA3 /* NFCCardCell.swift in Sources */,
  1622 + 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */,
1619 1623 6C6505CE2799059D0043DB7A /* TitleView.swift in Sources */,
1620 1624 6C5B545C27759CFA007F7901 /* RemindViewController.swift in Sources */,
1621 1625 6CFE53F4277AAA9900520B00 /* UIImage+Category.swift in Sources */,
... ...
HDFwear/20231111ReadMe.md
1 1 接口说明
2 2  
  3 +示例入口:我的->关于
  4 +
3 5 接口实现
4 6 BluetoothManager+Function
5 7  
... ... @@ -33,3 +35,9 @@ BluetoothManager+Function
33 35 消息ID 0x8015
34 36 触发BluetoothSyncDelegate中的didReceiveFindPhoneCommand
35 37 接收: [237, 126, 0, 1, 128, 21, 0, 1, 0, 1, 1, 74, 251]
  38 +
  39 +设置天气
  40 + func newSetWeather(weather: NewWeatherModel, completion: @escaping(_ error: Int?) -> ()) {
  41 +发送: [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]
  42 +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 0, 192, 215]
  43 +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 14, 33, 25]
... ...
HDFwear/Home/Model/NewWeatherModel.swift 0 → 100644
  1 +//
  2 +// NewWeatherModel.swift
  3 +// HDFwear
  4 +//
  5 +// Created by admin on 2023/11/14.
  6 +//
  7 +
  8 +import UIKit
  9 +import HandyJSON
  10 +import SwiftDate
  11 +
  12 +enum NewWeatherType: Int, HandyJSONEnum {
  13 + case sunny = 1
  14 + case cloudy = 2
  15 + case overcast = 3
  16 + case rain = 4
  17 + case snow = 5
  18 + case smog = 6
  19 + case hail = 7
  20 +}
  21 +
  22 +enum NewAirQuality: Int, HandyJSONEnum {
  23 + case you = 1
  24 + case liang = 2
  25 + case qingdu = 3
  26 + case moderate = 4
  27 + case zhongdu = 5
  28 + case yanzhong = 6
  29 +}
  30 +
  31 +enum NewWindType: Int, HandyJSONEnum {
  32 + case east = 1
  33 + case south = 2
  34 + case west = 3
  35 + case north = 4
  36 + case southeast = 5
  37 + case northeast = 6
  38 + case southwest = 7
  39 + case northwest = 8
  40 +}
  41 +
  42 +class NewNextWeatherModel: NSObject, HandyJSON {
  43 + required override init() { }
  44 + var highestTemperature: Int = 0
  45 + var lowestTemperature: Int = 0
  46 + var type: NewWeatherType = .sunny
  47 +
  48 + init(highestTemperature: Int, lowestTemperature: Int, type: NewWeatherType) {
  49 + self.highestTemperature = highestTemperature
  50 + self.lowestTemperature = lowestTemperature
  51 + self.type = type
  52 + }
  53 +}
  54 +
  55 +class NewWeatherModel: NSObject, HandyJSON {
  56 + required override init() { }
  57 +
  58 + var date: Date?
  59 + var currentTemperature: Int = 0
  60 + var highestTemperature: Int = 0
  61 + var lowestTemperature: Int = 0
  62 + var type: NewWeatherType = .sunny
  63 + var airQuality: NewAirQuality = .you
  64 + var humidity: Int = 0
  65 + var wind: NewWindType = .east
  66 + var windForce: Int = 0
  67 + var next5Days: Array<NewNextWeatherModel> = []
  68 + var position: String = ""
  69 +
  70 + init(date: Date? = Date(), currentTemperature: Int, highestTemperature: Int, lowestTemperature: Int, type: NewWeatherType, airQuality: NewAirQuality, humidity: Int, wind: NewWindType, windForce: Int, next5Days: Array<NewNextWeatherModel>, position: String) {
  71 + self.date = date
  72 + self.currentTemperature = currentTemperature
  73 + self.highestTemperature = highestTemperature
  74 + self.lowestTemperature = lowestTemperature
  75 + self.type = type
  76 + self.airQuality = airQuality
  77 + self.humidity = humidity
  78 + self.wind = wind
  79 + self.windForce = windForce
  80 + self.next5Days = next5Days
  81 + self.position = position
  82 + }
  83 +}
... ...
HDFwear/Mine/MineViewController.swift
... ... @@ -361,6 +361,23 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
361 361 }
362 362 }
363 363  
  364 + let archiveAction19 = UIAlertAction(title: "newSetWeather", style: .default) { action in
  365 + let next5day = [NewNextWeatherModel(highestTemperature: 21, lowestTemperature: 11, type: .sunny),
  366 + NewNextWeatherModel(highestTemperature: 22, lowestTemperature: 12, type: .sunny),
  367 + NewNextWeatherModel(highestTemperature: 23, lowestTemperature: 13, type: .sunny),
  368 + NewNextWeatherModel(highestTemperature: 24, lowestTemperature: 14, type: .sunny),
  369 + NewNextWeatherModel(highestTemperature: 25, lowestTemperature: 15, type: .sunny)
  370 + ]
  371 + let weather = NewWeatherModel(currentTemperature: 18, highestTemperature: 20, lowestTemperature: 10, type: .cloudy, airQuality: .moderate, humidity: 3, wind: .northeast, windForce: 4, next5Days: next5day, position: "长沙")
  372 + BluetoothManager.shared.newSetWeather(weather: weather) { error in
  373 + if error != nil {
  374 + print("newSetWeather" + (error?.description ?? ""))
  375 + }else {
  376 + print("newSetWeather success")
  377 + }
  378 + }
  379 + }
  380 +
364 381 alert.addAction(archiveAction1)
365 382 alert.addAction(archiveAction2)
366 383 alert.addAction(archiveAction3)
... ... @@ -379,6 +396,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
379 396 alert.addAction(archiveAction16)
380 397 alert.addAction(archiveAction17)
381 398 alert.addAction(archiveAction18)
  399 + alert.addAction(archiveAction19)
382 400 present(alert, animated: true, completion: nil)
383 401 case "我的数据":
384 402 let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthDataVC")
... ...
HDFwear/Tools/BleMessage+Function.swift
... ... @@ -118,4 +118,30 @@ extension BleMessage {
118 118 let bytes: [UInt8] = [type.rawValue]
119 119 return createDataPacket(key: .setSynWatch, bytes: bytes)
120 120 }
  121 +
  122 + func getNewWeatherCmd(_ weather: NewWeatherModel) -> Data {
  123 + let timeInterval = UInt32(weather.date?.timeIntervalSince1970 ?? 0)
  124 + let byte1: UInt8 = UInt8((timeInterval >> 24) & 0xFF)
  125 + let byte2: UInt8 = UInt8((timeInterval >> 16) & 0xFF)
  126 + let byte3: UInt8 = UInt8((timeInterval >> 8) & 0xFF)
  127 + let byte4: UInt8 = UInt8(timeInterval & 0xFF)
  128 +
  129 +// var uint32Data : [UInt8] = []
  130 +// withUnsafeBytes(of: timeInterval) { uint32Data.append(contentsOf: $0) }
  131 +
  132 +
  133 + 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)]
  134 + for day in weather.next5Days {
  135 + bytes += [UInt8(day.type.rawValue), UInt8(day.lowestTemperature), UInt8(day.highestTemperature)]
  136 + }
  137 +
  138 + if let utf8Data = weather.position.data(using: .utf8) {
  139 + let utf8Array = Array(utf8Data)
  140 + bytes += [UInt8(utf8Array.count)] + utf8Array
  141 + } else {
  142 + // jtd!
  143 + print("转换失败")
  144 + }
  145 + return createDataPacket(key: .setWeather, bytes: bytes)
  146 + }
121 147 }
... ...
HDFwear/Tools/Bluetooth+Types.swift
... ... @@ -138,6 +138,7 @@ enum NewCmd: UInt8 {
138 138 case setUserInfo = 0x0026
139 139 case setNoDisturb = 0x0027
140 140 case setSynWatch = 0x0028
  141 + case setWeather = 0x0031
141 142 //jtd!
142 143 // case setBeiDouContact = 0x0029
143 144 // case setBeiDouQuickAnswer = 0x0030
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -152,6 +152,14 @@ extension BluetoothManager {
152 152 sendData(data)
153 153 }
154 154  
  155 + // 设置天气
  156 + //
  157 + func newSetWeather(weather: NewWeatherModel, completion: @escaping(_ error: Int?) -> ()) {
  158 + let data = BleMessage.shared.getNewWeatherCmd(weather)
  159 + self.setCmdClosure = completion
  160 + sendData(data)
  161 + }
  162 +
155 163 //MARK: - 同步健康数据
156 164 // 拉取睡眠数据
157 165 func getSleepHistoryData( closure: SleepClosure? = nil) {
... ...