diff --git a/HDFwear/20240110ReadMe.md b/HDFwear/20240110ReadMe.md index 81b9e75..2367097 100644 --- a/HDFwear/20240110ReadMe.md +++ b/HDFwear/20240110ReadMe.md @@ -35,3 +35,13 @@ BluetoothManager+Function func newSetRestore(completion: ((_ error: Int?) -> ())? = nil) 发送: [237, 126, 0, 1, 0, 23, 0, 1, 0, 0, 19, 107] 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 23, 0, 108, 151] + +设置安静心率预警 + func newSetRestHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) { + 发送: [237, 126, 0, 1, 0, 24, 0, 1, 0, 3, 1, 60, 90, 3, 138] + 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 24, 0, 124, 169] + +设置运动心率预警 + func newSetExerciseHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) + 发送: [237, 126, 0, 1, 0, 25, 0, 1, 0, 3, 1, 110, 150, 52, 68] + 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 25, 0, 79, 152] diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index e071981..2cc729f 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -412,6 +412,26 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } + let archiveAction23 = UIAlertAction(title: "newSetRestHeartRateRemind", style: .default) { action in + BluetoothManager.shared.newSetRestHeartRateRemind(bool: true, minHr: 60, maxHr: 90) { error in + if error != nil { + print("newSetRestHeartRateRemind" + (error?.description ?? "")) + }else { + print("newSetRestHeartRateRemind success") + } + } + } + + let archiveAction24 = UIAlertAction(title: "newSetExerciseHeartRateRemind", style: .default) { action in + BluetoothManager.shared.newSetExerciseHeartRateRemind(bool: true, minHr: 110, maxHr: 150) { error in + if error != nil { + print("newSetExerciseHeartRateRemind" + (error?.description ?? "")) + }else { + print("newSetExerciseHeartRateRemind success") + } + } + } + alert.addAction(archiveAction1) alert.addAction(archiveAction2) alert.addAction(archiveAction3) @@ -434,7 +454,10 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction20) alert.addAction(archiveAction21) alert.addAction(archiveAction22) + alert.addAction(archiveAction23) + alert.addAction(archiveAction24) + alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil)) 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 c2662cb..c6c3826 100644 --- a/HDFwear/Tools/BleMessage+Function.swift +++ b/HDFwear/Tools/BleMessage+Function.swift @@ -81,6 +81,16 @@ extension BleMessage { return createDataPacket(key: .setHeartRateLowRemind, bytes: bytes) } + func getRestHeartRateRemindCmd(bool:Bool, minHr: UInt8 = 40, maxHr: UInt8 = 120) -> Data { + let bytes: [UInt8] = [(bool ? 0x01 : 0x00), minHr, maxHr] + return createDataPacket(key: .setRestHeartRateRemind, bytes: bytes) + } + + func getExerciseHeartRateRemindCmd(bool:Bool, minHr: UInt8, maxHr: UInt8 = 187) -> Data { + let bytes: [UInt8] = [(bool ? 0x01 : 0x00), minHr, maxHr] + return createDataPacket(key: .setExerciseHeartRateRemind, bytes: bytes) + } + func getFindWatchCmd(_ bool: Bool) -> Data { let bytes: [UInt8] = bool ? [0x01] : [0x00] return createDataPacket(key: .setFindWatch, bytes: bytes) diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index 3fa81f7..4663f47 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -127,8 +127,10 @@ enum NewCmd: UInt8 { case setLowPowerRemind = 0x15 case setLanguage = 0x16 case setRestore = 0x17 - case setHeartRateHighRemind = 0x18 - case setHeartRateLowRemind = 0x19 + case setHeartRateHighRemind = 0x90// deprecated + case setHeartRateLowRemind = 0x91// deprecated + case setRestHeartRateRemind = 0x18 + case setExerciseHeartRateRemind = 0x19 case setFindWatch = 0x0020 // case setMessage = 0x0021 // case setPhoneCall = 0x0022 diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index 00797a4..09ba6a9 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -111,6 +111,25 @@ extension BluetoothManager { self.setCmdClosure = completion sendData(data) } + // 设置安静心率预警 + // bool 0表示关闭 1表示打开 + // minHr 表示最小值 + // maxHr 表示最大值 + func newSetRestHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) { + let data = BleMessage.shared.getRestHeartRateRemindCmd(bool: bool, minHr: minHr, maxHr: maxHr) + self.setCmdClosure = completion + sendData(data) + } + + // 设置运动心率预警 + // bool 0表示关闭 1表示打开 + // minHr 表示最小值 + // maxHr 表示最大值 + func newSetExerciseHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) { + let data = BleMessage.shared.getExerciseHeartRateRemindCmd(bool: bool, minHr: minHr, maxHr: maxHr) + self.setCmdClosure = completion + sendData(data) + } // 设置查找手表 // bool 0表示关闭 1表示打开