From 191ca3ba8395b40424bacfea6b34675b2903d03f Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 15 Jan 2024 15:21:11 +0800 Subject: [PATCH] feat:heart rate now & history data --- HDFwear/20231111ReadMe.md | 16 ---------------- HDFwear/20240126ReadMe.md | 13 ++++++++++++- HDFwear/Home/HomeViewController.swift | 2 +- HDFwear/Mine/MineViewController.swift | 21 ++++++++++++++++----- HDFwear/ReadMe.txt | 4 ---- HDFwear/Tools/BluetoothManager+Function.swift | 6 +++--- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/HDFwear/20231111ReadMe.md b/HDFwear/20231111ReadMe.md index 8050eb6..4de985d 100644 --- a/HDFwear/20231111ReadMe.md +++ b/HDFwear/20231111ReadMe.md @@ -15,22 +15,6 @@ BluetoothManager+Function 发送: [237, 126, 0, 1, 0, 39, 0, 1, 0, 5, 0, 22, 0, 22, 0, 214, 52] 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 39, 0, 105, 2] -拉取心跳数据 - func getHeartRateHistoryData(closure: HeartRateClosure? = nil) - 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 1, 1, 128, 205] - -接收心跳数据 - func parseHeartRateData (_ content: [UInt8]) - 接收: [237, 126, 0, 1, 128, 22, 0, 1, 0, 5, 101, 73, 152, 158, 60, 178, 104] - -拉取血氧数据 - func getBloodOxygenData(closure: BloodOxygenClosure? = nil) - 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 1, 2, 176, 174] - -接收血氧数据 - func parseBlooodOxygenData (_ content: [UInt8]) - 接收: [237, 126, 0, 1, 128, 23, 0, 1, 0, 5, 101, 73, 152, 158, 90, 209, 77] - 接收查找手机 消息ID 0x8015 触发BluetoothSyncDelegate中的didReceiveFindPhoneCommand diff --git a/HDFwear/20240126ReadMe.md b/HDFwear/20240126ReadMe.md index 1788c79..585df65 100644 --- a/HDFwear/20240126ReadMe.md +++ b/HDFwear/20240126ReadMe.md @@ -26,5 +26,16 @@ BluetoothManager+Function 接收: [237, 126, 0, 1, 128, 23, 0, 2, 0, 25, 101, 156, 126, 112, 98, 101, 156, 133, 120, 99, 101, 156, 140, 128, 98, 101, 156, 147, 136, 99, 101, 156, 154, 144, 100, 144, 4] 接收: [237, 126, 0, 1, 128, 23, 0, 2, 0, 1, 255, 84, 182] - +拉取心跳数据 + func getHeartRateData(option: SyncOption = .now, closure: HeartRateClosure? = nil) + 当前 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 1, 1, 21, 249] + 接收: [237, 126, 0, 1, 128, 22, 0, 1, 0, 25, 101, 158, 8, 48, 98, 101, 158, 15, 56, 90, 101, 158, 22, 64, 75, 101, 158, 29, 72, 88, 101, 158, 36, 80, 100, 44, 45] + 接收: [237, 126, 0, 1, 128, 22, 0, 1, 0, 1, 255, 138, 202] + 历史 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 1, 2, 37, 154] + 接收: [237, 126, 0, 1, 128, 22, 0, 2, 0, 25, 101, 156, 112, 96, 98, 101, 156, 119, 104, 120, 101, 156, 126, 112, 101, 101, 156, 133, 120, 60, 101, 156, 140, 128, 70, 213, 123] + 接收: [237, 126, 0, 1, 128, 22, 0, 2, 0, 25, 101, 156, 112, 96, 98, 101, 156, 119, 104, 120, 101, 156, 126, 112, 101, 101, 156, 133, 120, 60, 101, 156, 140, 128, 70, 213, 123] + 接收: [237, 126, 0, 1, 128, 22, 0, 2, 0, 25, 101, 156, 112, 96, 98, 101, 156, 119, 104, 120, 101, 156, 126, 112, 101, 101, 156, 133, 120, 60, 101, 156, 140, 128, 70, 213, 123] + 接收: [237, 126, 0, 1, 128, 22, 0, 2, 0, 1, 255, 17, 22] 接受数据类 diff --git a/HDFwear/Home/HomeViewController.swift b/HDFwear/Home/HomeViewController.swift index f8d947b..2691771 100644 --- a/HDFwear/Home/HomeViewController.swift +++ b/HDFwear/Home/HomeViewController.swift @@ -752,7 +752,7 @@ extension HomeViewController: XMLParserDelegate { func syncHeartRate(_ day: SyncDay) { print("\(queryArray)---同步心率---\(day)") if queryArray.contains("HeartRate"), let index = queryArray.firstIndex(of: "HeartRate") { - BluetoothManager.shared.getHeartRateHistoryData() {[weak self] hrArray, error in + BluetoothManager.shared.getHeartRateData() {[weak self] hrArray, error in self?.queryArray.remove(at: index) if error == nil { HeartRateModel.addArray(hrArray) diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index 7fcb9ea..f66e993 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -485,13 +485,23 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } - let archiveAction14 = UIAlertAction(title: "getHeartRateHistoryData", style: .default) {[weak self] action in - BluetoothManager.shared.getHeartRateHistoryData() { hrArray, error in + let archiveAction14a = UIAlertAction(title: "getHeartRateData now", style: .default) {[weak self] action in + BluetoothManager.shared.getHeartRateData(option: .now) { hrArray, error in if error != nil { - print("getHeartRateHistoryData" + (error?.description ?? "")) + print("getHeartRateData" + (error?.description ?? "")) }else { self?.showDetailAlert(msg: hrArray.description) - print("getHeartRateHistoryData success") + print("getHeartRateData success") + } + } + } + let archiveAction14b = UIAlertAction(title: "getHeartRateData history", style: .default) {[weak self] action in + BluetoothManager.shared.getHeartRateData(option: .history) { hrArray, error in + if error != nil { + print("getHeartRateData" + (error?.description ?? "")) + }else { + self?.showDetailAlert(msg: hrArray.description) + print("getHeartRateData success") } } } @@ -555,7 +565,8 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction9b) alert.addAction(archiveAction10a) alert.addAction(archiveAction10b) - alert.addAction(archiveAction14) + alert.addAction(archiveAction14a) + alert.addAction(archiveAction14b) alert.addAction(archiveAction15) alert.addAction(archiveAction16) alert.addAction(archiveAction17) diff --git a/HDFwear/ReadMe.txt b/HDFwear/ReadMe.txt index 5492d28..3e06593 100644 --- a/HDFwear/ReadMe.txt +++ b/HDFwear/ReadMe.txt @@ -39,10 +39,6 @@ BluetoothManager+Function func newSetNotDisturb(remind: RemindModel, weekflag:[WeekFlag], isRepeat:Bool, completion: @escaping(_ error: Int?) -> ()) 发送: [237, 126, 0, 1, 0, 39, 0, 1, 0, 7, 0, 1, 33, 22, 0, 22, 0, 159, 5] -21. 拉取心跳数据 - func getHeartRateHistoryData(closure: HeartRateClosure? = nil) - 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 1, 1, 128, 205] - 22. 拉取计步数据 func getStepHistoryData(closure: StepClosure? = nil) 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 1, 3, 160, 143] diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index ab6f429..6183cf2 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -252,7 +252,7 @@ extension BluetoothManager { } // 拉取心跳数据 - func getHeartRateHistoryData(option: SyncOption = .now, closure: HeartRateClosure? = nil) { + func getHeartRateData(option: SyncOption = .now, closure: HeartRateClosure? = nil) { let data = BleMessage.shared.getSyncCmd(.heartRate, option) newStartSyncHealthData(closure: closure, data: data, synType: .heartRate) } @@ -458,8 +458,8 @@ extension BluetoothManager { for delegate in syncDelegateList { delegate.didReceiveFindPhoneCommand(value: ring) } - case 0x8016:// 历史心率数据上报 - print("历史心率数据上报") + case 0x8016:// 心率数据上报 + print("心率数据上报") let content = parseContentFromBytes(bytes) if (content.count == 1 && content.first == 0xff) { for delegate in syncDelegateList { -- libgit2 0.21.4