Commit 66e40f136b41b25dcd08987b5685cab3d1687d0f
1 parent
070709ae
feat: blood oxygen & hr & pressure & gps
Showing
5 changed files
with
151 additions
and
95 deletions
HDFwear/20240110ReadMe.md
... | ... | @@ -82,3 +82,15 @@ BluetoothManager+Function |
82 | 82 | 0x8022 |
83 | 83 | 接收: [237, 126, 0, 1, 128, 34, 0, 1, 0, 1, 0, 189, 23] |
84 | 84 | 接收: [237, 126, 0, 1, 128, 34, 0, 1, 0, 1, 1, 173, 54] |
85 | + | |
86 | +心跳数据 | |
87 | + func parseHeartRateData (_ content: [UInt8]) | |
88 | + 接收: [237, 126, 0, 1, 128, 22, 0, 1, 0, 0, 109, 26] | |
89 | + | |
90 | +血氧数据 | |
91 | + func parseBlooodOxygenData (_ content: [UInt8]) | |
92 | + 接收: [237, 126, 0, 1, 128, 23, 0, 1, 0, 0, 199, 75] | |
93 | + | |
94 | +压力数据 | |
95 | + func parsePressureData (_ content: [UInt8]) | |
96 | + 接收: [237, 126, 0, 1, 128, 32, 0, 1, 0, 0, 172, 113] | ... | ... |
HDFwear/Mine/MineViewController.swift
... | ... | @@ -189,6 +189,11 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { |
189 | 189 | // let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "AboutAppVC") |
190 | 190 | // navigationController?.pushViewController(vc, animated: true) |
191 | 191 | let alert = UIAlertController(title: "plz select", message: nil, preferredStyle: .actionSheet) |
192 | + | |
193 | + let archiveAction0 = UIAlertAction(title: "Fetch Date", style: .default) { action in | |
194 | + self.fetchDataAlert() | |
195 | + } | |
196 | + | |
192 | 197 | let archiveAction1 = UIAlertAction(title: "newSetTouchSense", style: .default) { action in |
193 | 198 | BluetoothManager.shared.newSetTouchSense(bool: true) { error in |
194 | 199 | if error != nil { |
... | ... | @@ -261,25 +266,6 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { |
261 | 266 | } |
262 | 267 | } |
263 | 268 | } |
264 | - let archiveAction9 = UIAlertAction(title: "getSleepHistoryData", style: .default) { action in | |
265 | - BluetoothManager.shared.getSleepHistoryData() { sleepArray, error in | |
266 | - if error != nil { | |
267 | - print("getSleepHistoryData" + (error?.description ?? "")) | |
268 | - }else { | |
269 | - print("getSleepHistoryData success") | |
270 | - SleepModel.addArray(sleepArray) | |
271 | - } | |
272 | - } | |
273 | - } | |
274 | - let archiveAction10 = UIAlertAction(title: "getBloodOxygenHistoryData", style: .default) { action in | |
275 | - BluetoothManager.shared.getBloodOxygenHistoryData() { boArray, error in | |
276 | - if error != nil { | |
277 | - print("getBloodOxygenHistoryData" + (error?.description ?? "")) | |
278 | - }else { | |
279 | - print("getBloodOxygenHistoryData success") | |
280 | - } | |
281 | - } | |
282 | - } | |
283 | 269 | |
284 | 270 | let archiveAction11 = UIAlertAction(title: "queryDeviceInfo", style: .default) { action in |
285 | 271 | BluetoothManager.shared.queryDeviceInfo(queryItems: [0x02,0x03]) { error in |
... | ... | @@ -311,46 +297,6 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { |
311 | 297 | } |
312 | 298 | } |
313 | 299 | |
314 | - let archiveAction14 = UIAlertAction(title: "getHeartRateHistoryData", style: .default) { action in | |
315 | - BluetoothManager.shared.getHeartRateHistoryData() { boArray, error in | |
316 | - if error != nil { | |
317 | - print("getHeartRateHistoryData" + (error?.description ?? "")) | |
318 | - }else { | |
319 | - print("getHeartRateHistoryData success") | |
320 | - } | |
321 | - } | |
322 | - } | |
323 | - | |
324 | - let archiveAction15 = UIAlertAction(title: "getStepHistoryData", style: .default) { action in | |
325 | - BluetoothManager.shared.getStepHistoryData() { boArray, error in | |
326 | - if error != nil { | |
327 | - print("getStepHistoryData" + (error?.description ?? "")) | |
328 | - }else { | |
329 | - print("getStepHistoryData success") | |
330 | - } | |
331 | - } | |
332 | - } | |
333 | - | |
334 | - let archiveAction16 = UIAlertAction(title: "getTrainHistoryData", style: .default) { action in | |
335 | - BluetoothManager.shared.getTrainHistoryData() { boArray, error in | |
336 | - if error != nil { | |
337 | - print("getTrainHistoryData" + (error?.description ?? "")) | |
338 | - }else { | |
339 | - print("getTrainHistoryData success") | |
340 | - } | |
341 | - } | |
342 | - } | |
343 | - | |
344 | - let archiveAction17 = UIAlertAction(title: "getPressureHistoryData", style: .default) { action in | |
345 | - BluetoothManager.shared.getPressureHistoryData() { boArray, error in | |
346 | - if error != nil { | |
347 | - print("getPressureHistoryData" + (error?.description ?? "")) | |
348 | - }else { | |
349 | - print("getPressureHistoryData success") | |
350 | - } | |
351 | - } | |
352 | - } | |
353 | - | |
354 | 300 | let archiveAction18 = UIAlertAction(title: "newSetTime", style: .default) { action in |
355 | 301 | BluetoothManager.shared.newSetTime { error in |
356 | 302 | if error != nil { |
... | ... | @@ -402,16 +348,6 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { |
402 | 348 | } |
403 | 349 | } |
404 | 350 | |
405 | - let archiveAction22 = UIAlertAction(title: "newGetBatteryData", style: .default) { action in | |
406 | - BluetoothManager.shared.newGetBatteryData { error in | |
407 | - if error != nil { | |
408 | - print("newGetBatteryData" + (error?.description ?? "")) | |
409 | - }else { | |
410 | - print("newGetBatteryData success") | |
411 | - } | |
412 | - } | |
413 | - } | |
414 | - | |
415 | 351 | let archiveAction23 = UIAlertAction(title: "newSetRestHeartRateRemind", style: .default) { action in |
416 | 352 | BluetoothManager.shared.newSetRestHeartRateRemind(bool: true, minHr: 60, maxHr: 90) { error in |
417 | 353 | if error != nil { |
... | ... | @@ -453,7 +389,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { |
453 | 389 | } |
454 | 390 | |
455 | 391 | |
456 | - | |
392 | + alert.addAction(archiveAction0) | |
457 | 393 | alert.addAction(archiveAction1) |
458 | 394 | alert.addAction(archiveAction2) |
459 | 395 | alert.addAction(archiveAction3) |
... | ... | @@ -462,20 +398,16 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { |
462 | 398 | alert.addAction(archiveAction6) |
463 | 399 | alert.addAction(archiveAction7) |
464 | 400 | alert.addAction(archiveAction8) |
465 | - alert.addAction(archiveAction9) | |
466 | - alert.addAction(archiveAction10) | |
401 | + | |
467 | 402 | alert.addAction(archiveAction11) |
468 | 403 | alert.addAction(archiveAction12) |
469 | 404 | alert.addAction(archiveAction13) |
470 | - alert.addAction(archiveAction14) | |
471 | - alert.addAction(archiveAction15) | |
472 | - alert.addAction(archiveAction16) | |
473 | - alert.addAction(archiveAction17) | |
405 | + | |
474 | 406 | alert.addAction(archiveAction18) |
475 | 407 | alert.addAction(archiveAction19) |
476 | 408 | alert.addAction(archiveAction20) |
477 | 409 | alert.addAction(archiveAction21) |
478 | - alert.addAction(archiveAction22) | |
410 | + | |
479 | 411 | alert.addAction(archiveAction23) |
480 | 412 | alert.addAction(archiveAction24) |
481 | 413 | alert.addAction(archiveAction25) |
... | ... | @@ -498,4 +430,101 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { |
498 | 430 | } |
499 | 431 | } |
500 | 432 | |
433 | + func fetchDataAlert () { | |
434 | + let alert = UIAlertController(title: "plz select fetch type", message: nil, preferredStyle: .actionSheet) | |
435 | + | |
436 | + let archiveAction9 = UIAlertAction(title: "getSleepHistoryData", style: .default) { action in | |
437 | + BluetoothManager.shared.getSleepHistoryData() { sleepArray, error in | |
438 | + if error != nil { | |
439 | + print("getSleepHistoryData" + (error?.description ?? "")) | |
440 | + }else { | |
441 | + print("getSleepHistoryData success") | |
442 | + SleepModel.addArray(sleepArray) | |
443 | + } | |
444 | + } | |
445 | + } | |
446 | + let archiveAction10 = UIAlertAction(title: "getBloodOxygenHistoryData", style: .default) { action in | |
447 | + BluetoothManager.shared.getBloodOxygenHistoryData() { boArray, error in | |
448 | + if error != nil { | |
449 | + print("getBloodOxygenHistoryData" + (error?.description ?? "")) | |
450 | + }else { | |
451 | + print("getBloodOxygenHistoryData success") | |
452 | + } | |
453 | + } | |
454 | + } | |
455 | + | |
456 | + let archiveAction14 = UIAlertAction(title: "getHeartRateHistoryData", style: .default) { action in | |
457 | + BluetoothManager.shared.getHeartRateHistoryData() { boArray, error in | |
458 | + if error != nil { | |
459 | + print("getHeartRateHistoryData" + (error?.description ?? "")) | |
460 | + }else { | |
461 | + print("getHeartRateHistoryData success") | |
462 | + } | |
463 | + } | |
464 | + } | |
465 | + | |
466 | + let archiveAction15 = UIAlertAction(title: "getStepHistoryData", style: .default) { action in | |
467 | + BluetoothManager.shared.getStepHistoryData() { boArray, error in | |
468 | + if error != nil { | |
469 | + print("getStepHistoryData" + (error?.description ?? "")) | |
470 | + }else { | |
471 | + print("getStepHistoryData success") | |
472 | + } | |
473 | + } | |
474 | + } | |
475 | + | |
476 | + let archiveAction16 = UIAlertAction(title: "getTrainHistoryData", style: .default) { action in | |
477 | + BluetoothManager.shared.getTrainHistoryData() { boArray, error in | |
478 | + if error != nil { | |
479 | + print("getTrainHistoryData" + (error?.description ?? "")) | |
480 | + }else { | |
481 | + print("getTrainHistoryData success") | |
482 | + } | |
483 | + } | |
484 | + } | |
485 | + | |
486 | + let archiveAction17 = UIAlertAction(title: "getPressureHistoryData", style: .default) { action in | |
487 | + BluetoothManager.shared.getPressureHistoryData() { boArray, error in | |
488 | + if error != nil { | |
489 | + print("getPressureHistoryData" + (error?.description ?? "")) | |
490 | + }else { | |
491 | + print("getPressureHistoryData success") | |
492 | + } | |
493 | + } | |
494 | + } | |
495 | + | |
496 | + let archiveAction22 = UIAlertAction(title: "newGetBatteryData", style: .default) { action in | |
497 | + BluetoothManager.shared.newGetBatteryData { error in | |
498 | + if error != nil { | |
499 | + print("newGetBatteryData" + (error?.description ?? "")) | |
500 | + }else { | |
501 | + print("newGetBatteryData success") | |
502 | + } | |
503 | + } | |
504 | + } | |
505 | + | |
506 | + let archiveAction101 = UIAlertAction(title: "newGetGpsData", style: .default) { action in | |
507 | + BluetoothManager.shared.newGetGpsData() {error in | |
508 | + if error != nil { | |
509 | + print("newGetGpsData" + (error?.description ?? "")) | |
510 | + }else { | |
511 | + print("newGetGpsData success") | |
512 | + } | |
513 | + } | |
514 | + } | |
515 | + | |
516 | + | |
517 | + alert.addAction(archiveAction9) | |
518 | + alert.addAction(archiveAction10) | |
519 | + alert.addAction(archiveAction14) | |
520 | + alert.addAction(archiveAction15) | |
521 | + alert.addAction(archiveAction16) | |
522 | + alert.addAction(archiveAction17) | |
523 | + alert.addAction(archiveAction22) | |
524 | + alert.addAction(archiveAction101) | |
525 | + | |
526 | + alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil)) | |
527 | + present(alert, animated: true, completion: nil) | |
528 | + } | |
529 | + | |
501 | 530 | } | ... | ... |
HDFwear/ReadMe.txt
... | ... | @@ -75,19 +75,9 @@ BluetoothManager+Function |
75 | 75 | 2. 设备信息数据 |
76 | 76 | private func parseDeviceInfoData (_ content:[UInt8]) |
77 | 77 | |
78 | -3. 心跳数据 | |
79 | - func parseHeartRateData (_ content: [UInt8]) | |
80 | - 接收: [237, 126, 0, 1, 128, 22, 0, 7, 0, 200, 100, 157, 163, 180, 112, 100, 157, 170, 188, 247, 100, 157, 177, 196, 6, 100, 157, 184, 204, 0, 100, 157, 191, 212, 22, 100, 157, 198, 220, 249, 100, 157, 205, 228, 6, 100, 157, 212, 236, 0, 100, 157, 219, 244, 0, 100, 157, 226, 252, 251, 100, 157, 234, 4, 6, 100, 157, 241, 12, 0, 100, 157, 248, 20, 229, 100, 157, 255, 28, 253, 100, 158, 6, 36, 6, 100, 158, 13, 44, 0, 100, 158, 20, 52, 197, 100, 158, 27, 60, 255, 100, 158, 34, 68, 6, 100, 158, 41, 76, 0, 100, 158, 48, 84, 180, 100, 158, 55, 92, 1, 100, 158, 62, 100, 7, 100, 158, 69, 108, 0, 100, 158, 76, 116, 158, 100, 158, 83, 124, 2, 100, 158, 90, 132, 7, 100, 158, 97, 140, 0, 100, 158, 104, 148, 131, 100, 158, 111, 156, 4, 100, 158, 118, 164, 7, 100, 158, 125, 172, 0, 100, 158, 132, 180, 114, 100, 158, 139, 188, 6, 100, 158, 146, 196, 7, 100, 158, 153, 204, 0, 100, 158, 160, 212, 87, 100, 158, 167, 220, 8, 100, 158, 174, 228, 7, 100, 158, 181, 236, 20, 23, 62] | |
81 | - | |
82 | -4. 血氧数据 | |
83 | - func parseBlooodOxygenData (_ content: [UInt8]) | |
84 | - | |
85 | 78 | 5. 体温数据 |
86 | 79 | func parseTemperaturData (_ content: [UInt8]) |
87 | 80 | |
88 | -6. 压力数据 | |
89 | - func parsePressureData (_ content: [UInt8]) | |
90 | - | |
91 | 81 | 7. 计步数据 |
92 | 82 | func parseStepData (_ content: [UInt8]) |
93 | 83 | ... | ... |
HDFwear/Tools/Bluetooth+Types.swift
HDFwear/Tools/BluetoothManager+Function.swift
... | ... | @@ -195,13 +195,6 @@ extension BluetoothManager { |
195 | 195 | sendData(data) |
196 | 196 | } |
197 | 197 | |
198 | - // 拉取电量数据 | |
199 | - func newGetBatteryData( completion: ((_ error: Int?) -> ())? = nil) { | |
200 | - let data = BleMessage.shared.getSyncCmd(.battery) | |
201 | - self.setCmdClosure = completion | |
202 | - sendData(data) | |
203 | - } | |
204 | - | |
205 | 198 | // 心率测量间隔设置 |
206 | 199 | func newSetHeartRateDetectInterval(bool: Bool, interval: UInt8, completion: @escaping(_ error: Int?) -> ()) { |
207 | 200 | let data = BleMessage.shared.getHeartRateDetectIntervalCmd(bool: bool, interval: interval) |
... | ... | @@ -218,6 +211,25 @@ extension BluetoothManager { |
218 | 211 | } |
219 | 212 | |
220 | 213 | //MARK: - 同步健康数据 |
214 | + //拉取数据 | |
215 | + func newGetData(type:SyncType, completion: ((_ error: Int?) -> ())? = nil) { | |
216 | + let data = BleMessage.shared.getSyncCmd(type) | |
217 | + self.setCmdClosure = completion | |
218 | + sendData(data) | |
219 | + } | |
220 | + | |
221 | + // 拉取电量数据 | |
222 | + func newGetBatteryData( completion: ((_ error: Int?) -> ())? = nil) { | |
223 | + newGetData(type: .battery, completion: completion) | |
224 | + } | |
225 | + | |
226 | + // 拉取GPS轨迹数据 | |
227 | + //jtd! 需要使用特定的回调,这样才能够直接把数据回调出来 | |
228 | + func newGetGpsData( completion: ((_ error: Int?) -> ())? = nil) { | |
229 | + newGetData(type: .gps, completion: completion) | |
230 | + } | |
231 | + | |
232 | + //MARK: - history | |
221 | 233 | // 拉取睡眠数据 |
222 | 234 | func getSleepHistoryData( closure: SleepClosure? = nil) { |
223 | 235 | let data = BleMessage.shared.getSyncCmd(.sleep) |
... | ... | @@ -615,4 +627,17 @@ extension BluetoothManager { |
615 | 627 | } |
616 | 628 | stepClosure?([step], nil) |
617 | 629 | } |
630 | + | |
631 | + // GPS数据 | |
632 | + func parseGPSData (_ content: [UInt8]) { | |
633 | + //jtd! parse gps data | |
634 | +// guard content.count > 0 else { | |
635 | +// print("无有效的信息") | |
636 | +// heartRateClosure?([], nil) | |
637 | +// return | |
638 | +// } | |
639 | +// let hrArray = HeartRateModel.toHeartRateArray(content) | |
640 | +// HeartRateModel.addArray(hrArray)// 加入数据库 | |
641 | +// heartRateClosure?(hrArray, nil) | |
642 | + } | |
618 | 643 | } | ... | ... |