Commit d1f02dfee301f711b5a61a1b8e83263ffeb25c67

Authored by daifengyi
1 parent 384cb690

feat:battery

HDFwear/Setting/SettingViewController.swift
... ... @@ -510,9 +510,9 @@ class SettingViewController: UIViewController, LBXScanViewControllerDelegate {
510 510 }
511 511  
512 512 extension SettingViewController: BluetoothSyncDelegate {
513   - func didReceiveBattery(value: Int, isCharging: Bool) {
514   - DeviceIsCharging = isCharging
515   - updateBattery(value, isCharging: isCharging)
  513 + func didReceiveBattery(value: Int) {
  514 +// DeviceIsCharging = isCharging
  515 + updateBattery(value, isCharging: false)
516 516 }
517 517 }
518 518 extension SettingViewController: BluetoothManagerDelegate {
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -286,7 +286,6 @@ extension BluetoothManager {
286 286 totalBytes = []
287 287 guard bytes.count > 12 else { return }
288 288 let msgId = Int(UInt16(bytes[4]) << 8 | UInt16(bytes[5]))
289   - let data = Data(bytes: bytes, count: bytes.count)
290 289 switch msgId {
291 290 case 0x8001:
292 291 parseDefaultResponseData(bytes)
... ... @@ -296,6 +295,10 @@ extension BluetoothManager {
296 295 print("实时步数、卡路里、距离自动上报")
297 296 case 0x8010:// 电量变化自动上报
298 297 print("电量变化自动上报")
  298 + Battery = Int(bytes[10])
  299 + for delegate in syncDelegateList {
  300 + delegate.didReceiveBattery(value: Battery)
  301 + }
299 302 case 0x8014:// 电话挂断
300 303 print("电话挂断")
301 304 case 0x8015:// 找手机
... ...
HDFwear/Tools/BluetoothManager.swift
... ... @@ -30,7 +30,6 @@ protocol BluetoothSyncDelegate {
30 30 func didReceiveFindCommand(status: Bool)
31 31 func didReceiveCameraCommand(status: SetCmd)
32 32 func didReceiveFindPhoneCommand()
33   - func didReceiveBattery(value: Int, isCharging: Bool)
34 33 func didReceiveHeartRate(value: Int)
35 34 func didReceiveBloodOxygen()
36 35 func didReceiveBloodPressure()
... ... @@ -38,12 +37,13 @@ protocol BluetoothSyncDelegate {
38 37 func didReceiveStep()
39 38 func firstSync()
40 39 func syncBug()
  40 + // adapted
  41 + func didReceiveBattery(value: Int)
41 42 }
42 43 extension BluetoothSyncDelegate {
43 44 func didReceiveFindCommand(status: Bool) { }
44 45 func didReceiveCameraCommand(status: SetCmd) { }
45 46 func didReceiveFindPhoneCommand() { }
46   - func didReceiveBattery(value: Int, isCharging: Bool) { }
47 47 func didReceiveHeartRate(value: Int) { }
48 48 func didReceiveBloodOxygen() { }
49 49 func didReceiveBloodPressure() { }
... ... @@ -51,6 +51,8 @@ extension BluetoothSyncDelegate {
51 51 func didReceiveStep() { }
52 52 func firstSync() {}
53 53 func syncBug() {}
  54 + // adapted
  55 + func didReceiveBattery(value: Int) { }
54 56 }
55 57  
56 58  
... ... @@ -1161,7 +1163,7 @@ class BluetoothManager: NSObject {
1161 1163 }
1162 1164  
1163 1165 for delegate in syncDelegateList {
1164   - delegate.didReceiveBattery(value: Battery, isCharging: isCharging)
  1166 + delegate.didReceiveBattery(value: Battery)
1165 1167 }
1166 1168 }
1167 1169  
... ... @@ -1440,7 +1442,7 @@ extension BluetoothManager: ClientProfileDelegate {
1440 1442 print("电量------\([UInt8](data))")
1441 1443 Battery = Int([UInt8](data)[0])
1442 1444 for delegate in syncDelegateList {
1443   - delegate.didReceiveBattery(value: Battery, isCharging: false)
  1445 + delegate.didReceiveBattery(value: Battery)
1444 1446 }
1445 1447 case BLEConfig.MTKDialReadUUID:
1446 1448 print("表盘------\([UInt8](data))")
... ...