From 6ef0f40d1d7c7c6c4d2a25440f0ad54fb082700e Mon Sep 17 00:00:00 2001 From: daifengyi Date: Wed, 28 Jun 2023 17:40:53 +0800 Subject: [PATCH] feat:user info --- HDFwear/Tools/BleMessage+Function.swift | 5 +++++ HDFwear/Tools/BleMessage.swift | 5 ----- HDFwear/Tools/BluetoothManager+Function.swift | 7 +++++++ HDFwear/Tools/BluetoothManager.swift | 7 ++++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/HDFwear/Tools/BleMessage+Function.swift b/HDFwear/Tools/BleMessage+Function.swift index 601eee2..484a081 100644 --- a/HDFwear/Tools/BleMessage+Function.swift +++ b/HDFwear/Tools/BleMessage+Function.swift @@ -81,4 +81,9 @@ extension BleMessage { let bytes: [UInt8] = bool ? [0x01] : [0x00] return createDataPacket(key: .setbloodOxygenAutoDetect, bytes: bytes) } + + func getUserInfoCmd(_ user: UserInfoModel) -> Data { + let bytes = [0x00, UInt8(user.weight), 0x00, UInt8(user.height), UInt8(user.gender)] + return createDataPacket(key: .setUserInfo, bytes: bytes) + } } diff --git a/HDFwear/Tools/BleMessage.swift b/HDFwear/Tools/BleMessage.swift index 61168ee..fc2177b 100644 --- a/HDFwear/Tools/BleMessage.swift +++ b/HDFwear/Tools/BleMessage.swift @@ -15,11 +15,6 @@ class BleMessage: NSObject { func getSettingCmd() -> Data { return getSendData(cmd: .set, key: .setting, bytes: []) } - - func getUserCmd(_ user: UserInfoModel) -> Data { - let userBytes = [UInt8(user.gender), UInt8(user.age), UInt8(user.height), UInt8(user.weight), UInt8(user.stepsGoal >> 16 & 0xFF), UInt8(user.stepsGoal >> 8 & 0xFF), UInt8(user.stepsGoal & 0xFF), 0x00] - return getSendData(cmd: .set, key: .user, bytes: userBytes) - } func getUnitCmd(_ distance: DistanceUnit, _ temperature: TemperatureUnit) -> Data { return getSendData(cmd: .set, key: .unit, bytes: [distance.rawValue, temperature.rawValue]) diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index f5a61e9..7c48358 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -112,4 +112,11 @@ extension BluetoothManager { self.setCmdClosure = completion sendData(data) } + + // 设置用户信息 + func newSetUserInfo(_ user: UserInfoModel, completion: ((_ error: Int?) -> ())? = nil) { + let data = BleMessage.shared.getUserInfoCmd(user) + self.setCmdClosure = completion + sendData(data) + } } diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index fe1cd07..84416b5 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -293,9 +293,10 @@ class BluetoothManager: NSObject { func setUserInfo(_ user: UserInfoModel, completion: ((_ error: Int?) -> ())? = nil) { - let data = BleMessage.shared.getUserCmd(user) - self.setCmdClosure = completion - sendData(data) +// let data = BleMessage.shared.getUserCmd(user) +// self.setCmdClosure = completion +// sendData(data) + newSetUserInfo(user, completion: completion) } func setUnit(_ distance: DistanceUnit, _ temperature: TemperatureUnit, completion: ((_ error: Int?) -> ())? = nil) { -- libgit2 0.21.4