diff --git a/HDFwear/Setting/SettingViewController.swift b/HDFwear/Setting/SettingViewController.swift index 6c550a9..9b8fea6 100644 --- a/HDFwear/Setting/SettingViewController.swift +++ b/HDFwear/Setting/SettingViewController.swift @@ -510,9 +510,9 @@ class SettingViewController: UIViewController, LBXScanViewControllerDelegate { } extension SettingViewController: BluetoothSyncDelegate { - func didReceiveBattery(value: Int, isCharging: Bool) { - DeviceIsCharging = isCharging - updateBattery(value, isCharging: isCharging) + func didReceiveBattery(value: Int) { +// DeviceIsCharging = isCharging + updateBattery(value, isCharging: false) } } extension SettingViewController: BluetoothManagerDelegate { diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index cc3121f..fe8a9b9 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -286,7 +286,6 @@ extension BluetoothManager { totalBytes = [] guard bytes.count > 12 else { return } let msgId = Int(UInt16(bytes[4]) << 8 | UInt16(bytes[5])) - let data = Data(bytes: bytes, count: bytes.count) switch msgId { case 0x8001: parseDefaultResponseData(bytes) @@ -296,6 +295,10 @@ extension BluetoothManager { print("实时步数、卡路里、距离自动上报") case 0x8010:// 电量变化自动上报 print("电量变化自动上报") + Battery = Int(bytes[10]) + for delegate in syncDelegateList { + delegate.didReceiveBattery(value: Battery) + } case 0x8014:// 电话挂断 print("电话挂断") case 0x8015:// 找手机 diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index 16c524c..226340a 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -30,7 +30,6 @@ protocol BluetoothSyncDelegate { func didReceiveFindCommand(status: Bool) func didReceiveCameraCommand(status: SetCmd) func didReceiveFindPhoneCommand() - func didReceiveBattery(value: Int, isCharging: Bool) func didReceiveHeartRate(value: Int) func didReceiveBloodOxygen() func didReceiveBloodPressure() @@ -38,12 +37,13 @@ protocol BluetoothSyncDelegate { func didReceiveStep() func firstSync() func syncBug() + // adapted + func didReceiveBattery(value: Int) } extension BluetoothSyncDelegate { func didReceiveFindCommand(status: Bool) { } func didReceiveCameraCommand(status: SetCmd) { } func didReceiveFindPhoneCommand() { } - func didReceiveBattery(value: Int, isCharging: Bool) { } func didReceiveHeartRate(value: Int) { } func didReceiveBloodOxygen() { } func didReceiveBloodPressure() { } @@ -51,6 +51,8 @@ extension BluetoothSyncDelegate { func didReceiveStep() { } func firstSync() {} func syncBug() {} + // adapted + func didReceiveBattery(value: Int) { } } @@ -1161,7 +1163,7 @@ class BluetoothManager: NSObject { } for delegate in syncDelegateList { - delegate.didReceiveBattery(value: Battery, isCharging: isCharging) + delegate.didReceiveBattery(value: Battery) } } @@ -1440,7 +1442,7 @@ extension BluetoothManager: ClientProfileDelegate { print("电量------\([UInt8](data))") Battery = Int([UInt8](data)[0]) for delegate in syncDelegateList { - delegate.didReceiveBattery(value: Battery, isCharging: false) + delegate.didReceiveBattery(value: Battery) } case BLEConfig.MTKDialReadUUID: print("表盘------\([UInt8](data))")