Commit c7f4905401ce7a643a1e855a0fb2dfa51e3df93c

Authored by jason
1 parent d3d70671

feat: rest & exercise heart rate remind

HDFwear/20240110ReadMe.md
... ... @@ -35,3 +35,13 @@ BluetoothManager+Function
35 35 func newSetRestore(completion: ((_ error: Int?) -> ())? = nil)
36 36 发送: [237, 126, 0, 1, 0, 23, 0, 1, 0, 0, 19, 107]
37 37 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 23, 0, 108, 151]
  38 +
  39 +设置安静心率预警
  40 + func newSetRestHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) {
  41 + 发送: [237, 126, 0, 1, 0, 24, 0, 1, 0, 3, 1, 60, 90, 3, 138]
  42 + 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 24, 0, 124, 169]
  43 +
  44 +设置运动心率预警
  45 + func newSetExerciseHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil)
  46 + 发送: [237, 126, 0, 1, 0, 25, 0, 1, 0, 3, 1, 110, 150, 52, 68]
  47 + 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 25, 0, 79, 152]
... ...
HDFwear/Mine/MineViewController.swift
... ... @@ -412,6 +412,26 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
412 412 }
413 413 }
414 414  
  415 + let archiveAction23 = UIAlertAction(title: "newSetRestHeartRateRemind", style: .default) { action in
  416 + BluetoothManager.shared.newSetRestHeartRateRemind(bool: true, minHr: 60, maxHr: 90) { error in
  417 + if error != nil {
  418 + print("newSetRestHeartRateRemind" + (error?.description ?? ""))
  419 + }else {
  420 + print("newSetRestHeartRateRemind success")
  421 + }
  422 + }
  423 + }
  424 +
  425 + let archiveAction24 = UIAlertAction(title: "newSetExerciseHeartRateRemind", style: .default) { action in
  426 + BluetoothManager.shared.newSetExerciseHeartRateRemind(bool: true, minHr: 110, maxHr: 150) { error in
  427 + if error != nil {
  428 + print("newSetExerciseHeartRateRemind" + (error?.description ?? ""))
  429 + }else {
  430 + print("newSetExerciseHeartRateRemind success")
  431 + }
  432 + }
  433 + }
  434 +
415 435 alert.addAction(archiveAction1)
416 436 alert.addAction(archiveAction2)
417 437 alert.addAction(archiveAction3)
... ... @@ -434,7 +454,10 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
434 454 alert.addAction(archiveAction20)
435 455 alert.addAction(archiveAction21)
436 456 alert.addAction(archiveAction22)
  457 + alert.addAction(archiveAction23)
  458 + alert.addAction(archiveAction24)
437 459  
  460 + alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil))
438 461 present(alert, animated: true, completion: nil)
439 462 case "我的数据":
440 463 let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthDataVC")
... ...
HDFwear/Tools/BleMessage+Function.swift
... ... @@ -81,6 +81,16 @@ extension BleMessage {
81 81 return createDataPacket(key: .setHeartRateLowRemind, bytes: bytes)
82 82 }
83 83  
  84 + func getRestHeartRateRemindCmd(bool:Bool, minHr: UInt8 = 40, maxHr: UInt8 = 120) -> Data {
  85 + let bytes: [UInt8] = [(bool ? 0x01 : 0x00), minHr, maxHr]
  86 + return createDataPacket(key: .setRestHeartRateRemind, bytes: bytes)
  87 + }
  88 +
  89 + func getExerciseHeartRateRemindCmd(bool:Bool, minHr: UInt8, maxHr: UInt8 = 187) -> Data {
  90 + let bytes: [UInt8] = [(bool ? 0x01 : 0x00), minHr, maxHr]
  91 + return createDataPacket(key: .setExerciseHeartRateRemind, bytes: bytes)
  92 + }
  93 +
84 94 func getFindWatchCmd(_ bool: Bool) -> Data {
85 95 let bytes: [UInt8] = bool ? [0x01] : [0x00]
86 96 return createDataPacket(key: .setFindWatch, bytes: bytes)
... ...
HDFwear/Tools/Bluetooth+Types.swift
... ... @@ -127,8 +127,10 @@ enum NewCmd: UInt8 {
127 127 case setLowPowerRemind = 0x15
128 128 case setLanguage = 0x16
129 129 case setRestore = 0x17
130   - case setHeartRateHighRemind = 0x18
131   - case setHeartRateLowRemind = 0x19
  130 + case setHeartRateHighRemind = 0x90// deprecated
  131 + case setHeartRateLowRemind = 0x91// deprecated
  132 + case setRestHeartRateRemind = 0x18
  133 + case setExerciseHeartRateRemind = 0x19
132 134 case setFindWatch = 0x0020
133 135 // case setMessage = 0x0021
134 136 // case setPhoneCall = 0x0022
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -111,6 +111,25 @@ extension BluetoothManager {
111 111 self.setCmdClosure = completion
112 112 sendData(data)
113 113 }
  114 + // 设置安静心率预警
  115 + // bool 0表示关闭 1表示打开
  116 + // minHr 表示最小值
  117 + // maxHr 表示最大值
  118 + func newSetRestHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) {
  119 + let data = BleMessage.shared.getRestHeartRateRemindCmd(bool: bool, minHr: minHr, maxHr: maxHr)
  120 + self.setCmdClosure = completion
  121 + sendData(data)
  122 + }
  123 +
  124 + // 设置运动心率预警
  125 + // bool 0表示关闭 1表示打开
  126 + // minHr 表示最小值
  127 + // maxHr 表示最大值
  128 + func newSetExerciseHeartRateRemind(bool:Bool, minHr: UInt8, maxHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) {
  129 + let data = BleMessage.shared.getExerciseHeartRateRemindCmd(bool: bool, minHr: minHr, maxHr: maxHr)
  130 + self.setCmdClosure = completion
  131 + sendData(data)
  132 + }
114 133  
115 134 // 设置查找手表
116 135 // bool 0表示关闭 1表示打开
... ...