Commit 07a5f00914d84e218ba5cd81c2cce08e031c3eb8

Authored by daifengyi
1 parent 5f08af0b

feat:language

HDFwear/Tools/BleMessage+Function.swift
... ... @@ -46,4 +46,9 @@ extension BleMessage {
46 46 let bytes: [UInt8] = bool ? [0x01] : [0x00]
47 47 return createDataPacket(key: .setLowPowerRemind, bytes: bytes)
48 48 }
  49 +
  50 + func getLanguageCmd(_ lan: UInt8) -> Data {
  51 + let bytes: [UInt8] = [lan]
  52 + return createDataPacket(key: .setLanguage, bytes: bytes)
  53 + }
49 54 }
... ...
HDFwear/Tools/BleMessage.swift
... ... @@ -37,14 +37,6 @@ class BleMessage: NSObject {
37 37 return getSendData(cmd: .device, key: .battery, bytes: [])
38 38 }
39 39  
40   - func getLanguageCmd(language: AppSettings.Language, timeFormat: TimeFormat, screenOnTime: Int, pair: UInt8) -> Data {
41   - if language == .system {
42   - return getSendData(cmd: .set, key: .language, bytes: [AppSettings.localeLanguage().cmd, timeFormat.rawValue, UInt8(screenOnTime), 0x01])
43   - } else {
44   - return getSendData(cmd: .set, key: .language, bytes: [language.cmd, timeFormat.rawValue, UInt8(screenOnTime), pair])
45   - }
46   - }
47   -
48 40  
49 41 func getWeatherCmd(_ array: [WeatherModel]) -> Data {
50 42 var weatherBytes: [UInt8] = []
... ...
HDFwear/Tools/Bluetooth+Types.swift
... ... @@ -122,6 +122,7 @@ enum NewCmd: UInt8 {
122 122 case setWristSense = 0x13
123 123 case setTouchSense = 0x14
124 124 case setLowPowerRemind = 0x15
  125 + case setLanguage = 0x16
125 126  
126 127 }
127 128  
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -57,4 +57,12 @@ extension BluetoothManager {
57 57 self.setCmdClosure = completion
58 58 sendData(data)
59 59 }
  60 +
  61 + // 设置语言
  62 + // lan 0表示中文,1表示英语
  63 + func newSetLanguage(lan: UInt8, completion: ((_ error: Int?) -> ())? = nil) {
  64 + let data = BleMessage.shared.getLanguageCmd(lan)
  65 + self.setCmdClosure = completion
  66 + sendData(data)
  67 + }
60 68 }
... ...
HDFwear/Tools/BluetoothManager.swift
... ... @@ -305,10 +305,8 @@ class BluetoothManager: NSObject {
305 305 }
306 306  
307 307 func setLanguage(_ language: AppSettings.Language, timeFormat: TimeFormat, screenOnTime: Int, pair: UInt8, completion: ((_ error: Int?) -> ())? = nil) {
308   - let data = BleMessage.shared.getLanguageCmd(language: language, timeFormat: timeFormat, screenOnTime: screenOnTime, pair: pair)
309   - self.setCmdClosure = completion
310   -
311   - sendData(data)
  308 + let lan: UInt8 = language == .Chinese ? 0x00 : 0x01
  309 + newSetLanguage(lan: lan, completion: completion)
312 310 }
313 311  
314 312 func setTime(format: TimeFormat, completion: ((_ error: Int?) -> ())? = nil) {
... ... @@ -398,8 +396,8 @@ class BluetoothManager: NSObject {
398 396  
399 397  
400 398 func syncLanguage() {
401   - let data = BleMessage.shared.getLanguageCmd(language: .system, timeFormat: .hour_24, screenOnTime: 5, pair: 1)
402   - sendData(data)
  399 + let lan: UInt8 = AppSettings.shared.language == .Chinese ? 0x00 : 0x01
  400 + newSetLanguage(lan: lan)
403 401 }
404 402 func syncBase(language: AppSettings.Language, timeFormat: TimeFormat) {
405 403  
... ... @@ -1231,7 +1229,7 @@ class BluetoothManager: NSObject {
1231 1229 }
1232 1230 let newcmd = NewCmd(rawValue: bytes[13])
1233 1231 switch newcmd {
1234   - case .setTime, .setTimeFormat, .setTemperatureUnit, .setDistanceUnit, .setWristSense, .setTouchSense,.setLowPowerRemind:
  1232 + case .setTime, .setTimeFormat, .setTemperatureUnit, .setDistanceUnit, .setWristSense, .setTouchSense, .setLowPowerRemind, .setLanguage:
1235 1233 if setCmdClosure != nil {
1236 1234 let success = bytes[14] == 0
1237 1235 if success {
... ...