Commit 6102d0b3ebb4e1803472c253904882d4ef669dd9
1 parent
22694b44
feat:time format
Showing
7 changed files
with
68 additions
and
22 deletions
HDFwear.xcodeproj/project.pbxproj
... | ... | @@ -289,6 +289,8 @@ |
289 | 289 | B23AA1082A18F3F100BB3902 /* SortPageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B23AA1062A18F3F100BB3902 /* SortPageCell.swift */; }; |
290 | 290 | B23AA1092A18F3F100BB3902 /* SortPageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1072A18F3F100BB3902 /* SortPageCell.xib */; }; |
291 | 291 | B262F7C72A1BB71600B4DFD2 /* ZCStringPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B262F7C62A1BB71500B4DFD2 /* ZCStringPickerView.swift */; }; |
292 | + B279A37A2A4AC2F800A7C7B6 /* BluetoothManager+Function.swift in Sources */ = {isa = PBXBuildFile; fileRef = B279A3792A4AC2F800A7C7B6 /* BluetoothManager+Function.swift */; }; | |
293 | + B279A37C2A4AC5B000A7C7B6 /* BleMessage+Function.swift in Sources */ = {isa = PBXBuildFile; fileRef = B279A37B2A4AC5B000A7C7B6 /* BleMessage+Function.swift */; }; | |
292 | 294 | B2AF58822A14C4BE0080B464 /* LaunchMyInfoSettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2AF58812A14C4BE0080B464 /* LaunchMyInfoSettingVC.swift */; }; |
293 | 295 | /* End PBXBuildFile section */ |
294 | 296 | |
... | ... | @@ -665,6 +667,8 @@ |
665 | 667 | B23AA1062A18F3F100BB3902 /* SortPageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortPageCell.swift; sourceTree = "<group>"; }; |
666 | 668 | B23AA1072A18F3F100BB3902 /* SortPageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SortPageCell.xib; sourceTree = "<group>"; }; |
667 | 669 | B262F7C62A1BB71500B4DFD2 /* ZCStringPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZCStringPickerView.swift; sourceTree = "<group>"; }; |
670 | + B279A3792A4AC2F800A7C7B6 /* BluetoothManager+Function.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BluetoothManager+Function.swift"; sourceTree = "<group>"; }; | |
671 | + B279A37B2A4AC5B000A7C7B6 /* BleMessage+Function.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BleMessage+Function.swift"; sourceTree = "<group>"; }; | |
668 | 672 | B2AF58812A14C4BE0080B464 /* LaunchMyInfoSettingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchMyInfoSettingVC.swift; sourceTree = "<group>"; }; |
669 | 673 | C621CFD20D2BD60CF4F959C3 /* Pods-HDFwear.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HDFwear.release.xcconfig"; path = "Target Support Files/Pods-HDFwear/Pods-HDFwear.release.xcconfig"; sourceTree = "<group>"; }; |
670 | 674 | E7F3880C37BC5F6DD15C709D /* Pods-HDFwear.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HDFwear.debug.xcconfig"; path = "Target Support Files/Pods-HDFwear/Pods-HDFwear.debug.xcconfig"; sourceTree = "<group>"; }; |
... | ... | @@ -1102,8 +1106,10 @@ |
1102 | 1106 | children = ( |
1103 | 1107 | 6C411EDE275DE737009B2E02 /* BluetoothManager.swift */, |
1104 | 1108 | 6C1F987E279BF0AA00C0C3BA /* BluetoothManager+Set.swift */, |
1109 | + B279A3792A4AC2F800A7C7B6 /* BluetoothManager+Function.swift */, | |
1105 | 1110 | 6C411EE4275DFF37009B2E02 /* Bluetooth+Types.swift */, |
1106 | 1111 | 6C6051B92760843F00286B37 /* BleMessage.swift */, |
1112 | + B279A37B2A4AC5B000A7C7B6 /* BleMessage+Function.swift */, | |
1107 | 1113 | 6C41D081275F2EC400747BE4 /* GCDTimer.swift */, |
1108 | 1114 | 6C6051BB2760967100286B37 /* crc8.swift */, |
1109 | 1115 | 6C6F406127434C5700F9473C /* UIColor+Extension.swift */, |
... | ... | @@ -1570,6 +1576,7 @@ |
1570 | 1576 | 6C34A242276D8FD100849087 /* MineCell.swift in Sources */, |
1571 | 1577 | 6C80835B27F6DEA700C13EB2 /* BackgroundVC.swift in Sources */, |
1572 | 1578 | 6C1B7E9827B794B300DB9D1C /* NFCCell.swift in Sources */, |
1579 | + B279A37C2A4AC5B000A7C7B6 /* BleMessage+Function.swift in Sources */, | |
1573 | 1580 | 6C34A24E276DE04000849087 /* AdminHelper.swift in Sources */, |
1574 | 1581 | B2AF58822A14C4BE0080B464 /* LaunchMyInfoSettingVC.swift in Sources */, |
1575 | 1582 | 6C2EE98A278026460051413A /* HRReportCell.swift in Sources */, |
... | ... | @@ -1589,6 +1596,7 @@ |
1589 | 1596 | 6CBB0CAA27B7B6FA009B27C1 /* GenerateBlankVC.swift in Sources */, |
1590 | 1597 | 6C2EE979277FF7120051413A /* HealthReportVC.swift in Sources */, |
1591 | 1598 | 6CEA284D27EB1359006A44AB /* MedalDetailVC.swift in Sources */, |
1599 | + B279A37A2A4AC2F800A7C7B6 /* BluetoothManager+Function.swift in Sources */, | |
1592 | 1600 | 6C411EE1275DF6F3009B2E02 /* Data+Extension.swift in Sources */, |
1593 | 1601 | 6C80835927F698B700C13EB2 /* BackgroundProtectionVC.swift in Sources */, |
1594 | 1602 | 6C6F405C27434AC500F9473C /* ZCNavigationController.swift in Sources */, | ... | ... |
HDFwear/Setting/OtherSettingVC.swift
... | ... | @@ -184,14 +184,14 @@ extension OtherSettingVC: UITableViewDelegate, UITableViewDataSource { |
184 | 184 | let user = UserInfo |
185 | 185 | switch settingDic[settingArray[indexPath.section]]![indexPath.row] { |
186 | 186 | case "24小时": |
187 | - BluetoothManager.shared.setTime(format: .hour_24) {[weak self] error in | |
187 | + BluetoothManager.shared.newSetTimeFormat(format: .hour_24) {[weak self] error in | |
188 | 188 | if error == nil { |
189 | 189 | user.timeFormat = 0 |
190 | 190 | self?.updateUI(indexPath, user: user) |
191 | 191 | } |
192 | 192 | } |
193 | 193 | case "12小时": |
194 | - BluetoothManager.shared.setTime(format: .hour_12) {[weak self] error in | |
194 | + BluetoothManager.shared.newSetTimeFormat(format: .hour_24) {[weak self] error in | |
195 | 195 | if error == nil { |
196 | 196 | user.timeFormat = 1 |
197 | 197 | self?.updateUI(indexPath, user: user) | ... | ... |
HDFwear/Tools/BleMessage+Function.swift
0 → 100644
1 | +// | |
2 | +// BleMessage+Function.swift | |
3 | +// HDFwear | |
4 | +// | |
5 | +// Created by daifengyi on 2023/6/27. | |
6 | +// | |
7 | + | |
8 | +import SwiftDate | |
9 | + | |
10 | +extension BleMessage { | |
11 | + func getTimeCmd() -> Data { | |
12 | + let date = DateInRegion().date | |
13 | + let timeBytes: [UInt8] = [UInt8(date.year%100), UInt8(date.month), UInt8(date.day), UInt8(date.hour), UInt8(date.minute), UInt8(date.second)] | |
14 | + // return getSendData(cmd: .set, key: .time, bytes: timeBytes) | |
15 | +// let a = getPackData(key: .setTime, contentBytes: timeBytes) | |
16 | +// let b = createDataPacket(key: .setTime, bytes: timeBytes) | |
17 | + return createDataPacket(key: .setTime, bytes: timeBytes) | |
18 | + } | |
19 | + | |
20 | + func getTimeFormatCmd(format: TimeFormat) -> Data { | |
21 | + let bytes: [UInt8] = [format.rawValue] | |
22 | + return createDataPacket(key: .setTimeFormat, bytes: bytes) | |
23 | + } | |
24 | +} | ... | ... |
HDFwear/Tools/BleMessage.swift
... | ... | @@ -25,18 +25,6 @@ class BleMessage: NSObject { |
25 | 25 | return getSendData(cmd: .set, key: .unit, bytes: [distance.rawValue, temperature.rawValue]) |
26 | 26 | } |
27 | 27 | |
28 | - | |
29 | - | |
30 | - func getTimeCmd(format: TimeFormat) -> Data { | |
31 | - let date = DateInRegion().date | |
32 | - var timeBytes: [UInt8] = [UInt8(date.year%100), UInt8(date.month), UInt8(date.day), UInt8(date.hour), UInt8(date.minute), UInt8(date.second)] | |
33 | -// return getSendData(cmd: .set, key: .time, bytes: timeBytes) | |
34 | - let a = getPackData(key: .setTime, contentBytes: timeBytes) | |
35 | - let b = createDataPacket(key: .setTime, bytes: timeBytes) | |
36 | - print("ddd") | |
37 | - return createDataPacket(key: .setTime, bytes: timeBytes) | |
38 | - } | |
39 | - | |
40 | 28 | func getCameraCmd(_ open: Bool) -> Data { |
41 | 29 | return getSendData(cmd: .device, key: open ? .openCamera : .exitCamera, bytes: [0x01]) |
42 | 30 | } |
... | ... | @@ -235,6 +223,7 @@ class BleMessage: NSObject { |
235 | 223 | |
236 | 224 | } |
237 | 225 | |
226 | + //MARK: - 组包 | |
238 | 227 | func createDataPacket(key: NewCmd, bytes: [UInt8]) -> Data { |
239 | 228 | let identifier: [UInt8] = [0xED, 0x7E] // 标识 |
240 | 229 | let version: [UInt8] = [0x00, 0x01] // 协议版本号 | ... | ... |
HDFwear/Tools/Bluetooth+Types.swift
... | ... | @@ -63,8 +63,8 @@ enum TemperatureUnit: UInt8 { |
63 | 63 | case fahrenheit = 1 |
64 | 64 | } |
65 | 65 | enum TimeFormat: UInt8 { |
66 | - case hour_24 = 0 | |
67 | - case hour_12 = 1 | |
66 | + case hour_24 = 1 | |
67 | + case hour_12 = 0 | |
68 | 68 | } |
69 | 69 | |
70 | 70 | enum BleCmd: UInt8 { |
... | ... | @@ -116,6 +116,8 @@ enum SetCmd: UInt8 { |
116 | 116 | |
117 | 117 | enum NewCmd: UInt8 { |
118 | 118 | case setTime = 0x09 |
119 | + case setTimeFormat = 0x10 | |
120 | + | |
119 | 121 | } |
120 | 122 | |
121 | 123 | enum SyncCmd: UInt8 { | ... | ... |
HDFwear/Tools/BluetoothManager+Function.swift
0 → 100644
1 | +// | |
2 | +// BluetoothManager+Function.swift | |
3 | +// HDFwear | |
4 | +// | |
5 | +// Created by daifengyi on 2023/6/27. | |
6 | +// | |
7 | + | |
8 | +import SwiftDate | |
9 | + | |
10 | + | |
11 | +extension BluetoothManager { | |
12 | + // 设置时间 | |
13 | + func newSetTime(completion: ((_ error: Int?) -> ())? = nil) { | |
14 | + let data = BleMessage.shared.getTimeCmd() | |
15 | + self.setCmdClosure = completion | |
16 | + sendData(data) | |
17 | + } | |
18 | + | |
19 | + // 设置时间格式 | |
20 | + func newSetTimeFormat(format: TimeFormat, completion: ((_ error: Int?) -> ())? = nil) { | |
21 | + let data = BleMessage.shared.getTimeFormatCmd(format: format) | |
22 | + self.setCmdClosure = completion | |
23 | + sendData(data) | |
24 | + } | |
25 | +} | ... | ... |
HDFwear/Tools/BluetoothManager.swift
... | ... | @@ -312,9 +312,7 @@ class BluetoothManager: NSObject { |
312 | 312 | } |
313 | 313 | |
314 | 314 | func setTime(format: TimeFormat, completion: ((_ error: Int?) -> ())? = nil) { |
315 | - let data = BleMessage.shared.getTimeCmd(format: format) | |
316 | - self.setCmdClosure = completion | |
317 | - sendData(data) | |
315 | + newSetTime(completion: completion) | |
318 | 316 | } |
319 | 317 | |
320 | 318 | func setWeather(_ array: [WeatherModel], completion: ((_ error: Int?) -> ())? = nil) { |
... | ... | @@ -408,7 +406,7 @@ class BluetoothManager: NSObject { |
408 | 406 | } |
409 | 407 | |
410 | 408 | func syncTime(format: TimeFormat) { |
411 | - let data = BleMessage.shared.getTimeCmd(format: format) | |
409 | + let data = BleMessage.shared.getTimeCmd() | |
412 | 410 | sendData(data) |
413 | 411 | } |
414 | 412 | |
... | ... | @@ -1233,7 +1231,7 @@ class BluetoothManager: NSObject { |
1233 | 1231 | } |
1234 | 1232 | let newcmd = NewCmd(rawValue: bytes[13]) |
1235 | 1233 | switch newcmd { |
1236 | - case .setTime: | |
1234 | + case .setTime, .setTimeFormat: | |
1237 | 1235 | if setCmdClosure != nil { |
1238 | 1236 | let success = bytes[14] == 0 |
1239 | 1237 | if success { |
... | ... | @@ -1252,7 +1250,7 @@ class BluetoothManager: NSObject { |
1252 | 1250 | |
1253 | 1251 | //MARK: - 发送数据 |
1254 | 1252 | |
1255 | - private func sendData(_ data: Data) { | |
1253 | + func sendData(_ data: Data) { | |
1256 | 1254 | if peripheral == nil { |
1257 | 1255 | print("peripheral == nil") |
1258 | 1256 | return | ... | ... |