From 02bd7bf86392d84fd2927599f7096b3581f54ef0 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 29 Jan 2024 19:24:33 +0800 Subject: [PATCH] feat:no disturb --- HDFwear.xcodeproj/project.pbxproj | 4 ++++ HDFwear/20231111ReadMe.md | 5 ----- HDFwear/20240126ReadMe.md | 10 ++++++++++ HDFwear/Home/Model/NewNoDisturbModel.swift | 39 +++++++++++++++++++++++++++++++++++++++ HDFwear/Mine/MineViewController.swift | 20 +++++++++++++++++++- HDFwear/ReadMe.txt | 4 ---- HDFwear/Tools/BleMessage+Function.swift | 12 ++---------- HDFwear/Tools/Bluetooth+Types.swift | 1 + HDFwear/Tools/BluetoothManager+Function.swift | 32 +++++++++++++++++++++++++++++--- HDFwear/Tools/BluetoothManager.swift | 6 +++++- 10 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 HDFwear/Home/Model/NewNoDisturbModel.swift diff --git a/HDFwear.xcodeproj/project.pbxproj b/HDFwear.xcodeproj/project.pbxproj index d09c0d2..6ac0b31 100644 --- a/HDFwear.xcodeproj/project.pbxproj +++ b/HDFwear.xcodeproj/project.pbxproj @@ -285,6 +285,7 @@ 8473FB622B4BF1A200409148 /* TaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8473FB612B4BF1A200409148 /* TaskManager.swift */; }; 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; }; 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */; }; + 8477AD722B67B8C40011F0EA /* NewNoDisturbModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8477AD712B67B8C40011F0EA /* NewNoDisturbModel.swift */; }; 8477B04C2B5A243B0018ADA8 /* NewExerciseRealtimeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8477B04B2B5A243B0018ADA8 /* NewExerciseRealtimeModel.swift */; }; 8477B04E2B5A79EE0018ADA8 /* NewExerciseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8477B04D2B5A79EE0018ADA8 /* NewExerciseModel.swift */; }; 84792A222B5FACAC00851211 /* LETransceiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 84792A1F2B5FACAB00851211 /* LETransceiver.m */; }; @@ -675,6 +676,7 @@ 8473FB612B4BF1A200409148 /* TaskManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskManager.swift; sourceTree = ""; }; 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = ""; }; 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewBeiDouContactModel.swift; sourceTree = ""; }; + 8477AD712B67B8C40011F0EA /* NewNoDisturbModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewNoDisturbModel.swift; sourceTree = ""; }; 8477B04B2B5A243B0018ADA8 /* NewExerciseRealtimeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewExerciseRealtimeModel.swift; sourceTree = ""; }; 8477B04D2B5A79EE0018ADA8 /* NewExerciseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewExerciseModel.swift; sourceTree = ""; }; 84792A1B2B5FACAB00851211 /* OTAManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OTAManager.m; sourceTree = ""; }; @@ -1317,6 +1319,7 @@ 847B88EE2B5780CA00851EE7 /* NewIntensiveTimeModel.swift */, 8477B04B2B5A243B0018ADA8 /* NewExerciseRealtimeModel.swift */, 8477B04D2B5A79EE0018ADA8 /* NewExerciseModel.swift */, + 8477AD712B67B8C40011F0EA /* NewNoDisturbModel.swift */, ); path = Model; sourceTree = ""; @@ -1771,6 +1774,7 @@ 6C411EE5275DFF37009B2E02 /* Bluetooth+Types.swift in Sources */, 847B88EF2B5780CA00851EE7 /* NewIntensiveTimeModel.swift in Sources */, 6C0AE825279151260064D377 /* AppVersionView.swift in Sources */, + 8477AD722B67B8C40011F0EA /* NewNoDisturbModel.swift in Sources */, 6C2EE98E2780265B0051413A /* SleepReportCell.swift in Sources */, 6C1B7EA127B7976600DB9D1C /* NFCProblemsVC.swift in Sources */, 6CB3664A2781912F008BF0CB /* EndMotionVC.swift in Sources */, diff --git a/HDFwear/20231111ReadMe.md b/HDFwear/20231111ReadMe.md index 4de985d..7993466 100644 --- a/HDFwear/20231111ReadMe.md +++ b/HDFwear/20231111ReadMe.md @@ -9,11 +9,6 @@ BluetoothManager+Function func newSetTime(completion: ((_ error: Int?) -> ())? = nil) 发送: [237, 126, 0, 1, 0, 9, 0, 1, 0, 7, 23, 11, 12, 20, 14, 35, 7, 28, 46] 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 9, 0, 76, 235] - -设置勿扰模式 - func newSetNotDisturb(remind: RemindModel, completion: @escaping(_ error: Int?) -> ()) - 发送: [237, 126, 0, 1, 0, 39, 0, 1, 0, 5, 0, 22, 0, 22, 0, 214, 52] - 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 39, 0, 105, 2] 接收查找手机 消息ID 0x8015 diff --git a/HDFwear/20240126ReadMe.md b/HDFwear/20240126ReadMe.md index 09c7446..15cd724 100644 --- a/HDFwear/20240126ReadMe.md +++ b/HDFwear/20240126ReadMe.md @@ -145,6 +145,16 @@ BluetoothManager+Function func newGetfirmwareVersionData(option: SyncOption = .now, closure: FirmwareVersionClosure? = nil) 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 20, 1, 233, 127] 接收: [237, 126, 0, 1, 128, 55, 0, 1, 0, 2, 1, 4, 5, 79] + +设置勿扰模式 + func newSetNotDisturb(noDisturb: NewNoDisturbModel, completion: @escaping(_ error: Int?) -> ()) + 发送: [237, 126, 0, 1, 0, 39, 0, 1, 0, 5, 1, 8, 30, 15, 45, 209, 222] + 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 39, 0, 105, 2] + +拉取勿扰模式 + func newGetNoDisturbData(option: SyncOption = .now, closure: NoDisturbClosure? = nil) + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 13, 1, 80, 148] + 接收: [237, 126, 0, 1, 128, 48, 0, 1, 0, 5, 1, 8, 30, 15, 45, 208, 24] 接受数据类 diff --git a/HDFwear/Home/Model/NewNoDisturbModel.swift b/HDFwear/Home/Model/NewNoDisturbModel.swift new file mode 100644 index 0000000..75f7aad --- /dev/null +++ b/HDFwear/Home/Model/NewNoDisturbModel.swift @@ -0,0 +1,39 @@ +// +// NewNoDisturbModel.swift +// HDFwear +// +// Created by admin on 2024/1/29. +// + +import Foundation +import UIKit +import HandyJSON +import SwiftDate + +class NewNoDisturbModel: NSObject { + required override init() { } + + var enable: Bool = false + var startHour: Int = 0 + var startMinute: Int = 0 + var endHour: Int = 0 + var endMinute: Int = 0 + + override var description: String { + return "NewNoDisturbModel: [enable: \(enable), startHour: \(startHour), startMinute: \(startMinute), endHour: \(endHour), endMinute: \(endMinute)]" + } + + class func toNoDisturbModel(_ data: [UInt8]) -> NewNoDisturbModel { + let s = NewNoDisturbModel() + guard data.count >= 5 else { + return s + } + s.enable = (data[0] == 0x01) + s.startHour = Int(data[1]) + s.startMinute = Int(data[2]) + s.endHour = Int(data[3]) + s.endMinute = Int(data[4]) + return s; + } +} + diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index 7b598c7..c7037d2 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -279,7 +279,13 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } let archiveAction12 = UIAlertAction(title: "newSetNotDisturb", style: .default) { action in - BluetoothManager.shared.newSetNotDisturb(remind: CurDevice.disturb) { error in + let noDisturb = NewNoDisturbModel() + noDisturb.enable = true + noDisturb.startHour = 8 + noDisturb.startMinute = 30 + noDisturb.endHour = 15 + noDisturb.endMinute = 45 + BluetoothManager.shared.newSetNotDisturb(noDisturb: noDisturb) { error in if error != nil { print("newSetNotDisturb" + (error?.description ?? "")) }else { @@ -693,6 +699,17 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } + let archiveAction106 = UIAlertAction(title: "newGetNoDisturbData", style: .default) {[weak self] action in + BluetoothManager.shared.newGetNoDisturbData() {noDisturb, error in + if error != nil { + print("newGetNoDisturbData" + (error?.description ?? "")) + }else { + self?.showDetailAlert(msg: noDisturb?.description) + print("newGetNoDisturbData success") + } + } + } + alert.addAction(archiveAction9a) alert.addAction(archiveAction9b) @@ -713,6 +730,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction104a) alert.addAction(archiveAction104b) alert.addAction(archiveAction105) + alert.addAction(archiveAction106) alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil)) present(alert, animated: true, completion: nil) diff --git a/HDFwear/ReadMe.txt b/HDFwear/ReadMe.txt index 8508827..3ec71b4 100644 --- a/HDFwear/ReadMe.txt +++ b/HDFwear/ReadMe.txt @@ -35,10 +35,6 @@ BluetoothManager+Function func newSetHeartRateLowRemind(minHr: UInt8, completion: ((_ error: Int?) -> ())? = nil) 发送: [237, 126, 0, 1, 0, 25, 0, 1, 0, 1, 120, 5, 95] -18. 设置勿扰模式 - func newSetNotDisturb(remind: RemindModel, weekflag:[WeekFlag], isRepeat:Bool, completion: @escaping(_ error: Int?) -> ()) - 发送: [237, 126, 0, 1, 0, 39, 0, 1, 0, 7, 0, 1, 33, 22, 0, 22, 0, 159, 5] - 接受数据类 1. 通用返回数据 private func parseDefaultResponseData(_ bytes: [UInt8]) diff --git a/HDFwear/Tools/BleMessage+Function.swift b/HDFwear/Tools/BleMessage+Function.swift index 048554c..89ff880 100644 --- a/HDFwear/Tools/BleMessage+Function.swift +++ b/HDFwear/Tools/BleMessage+Function.swift @@ -111,16 +111,8 @@ extension BleMessage { return createDataPacket(key: .setUserInfo, bytes: bytes) } - func getNotDisturbCmd(_ remind: RemindModel) -> Data { -// guard !weekflag.isEmpty else { -// return createDataPacket(key: .setDistanceUnit, bytes: []) -// } -// var flag: UInt8 = 0 -// for item in weekflag { -// flag |= 1 << item.rawValue -// } -// let bytes: [UInt8] = [remind.isOn ? 0x01 : 0x00, isRepeat ? 0x01: 0x00, flag, UInt8(remind.startDate.hour), UInt8(remind.startDate.minute), UInt8(remind.endDate.hour), UInt8(remind.endDate.minute)] - let bytes: [UInt8] = [remind.isOn ? 0x01 : 0x00, UInt8(remind.startDate.hour), UInt8(remind.startDate.minute), UInt8(remind.endDate.hour), UInt8(remind.endDate.minute)] + func getNotDisturbCmd(_ noDisturb: NewNoDisturbModel) -> Data { + let bytes: [UInt8] = [noDisturb.enable ? 0x01 : 0x00, UInt8(noDisturb.startHour), UInt8(noDisturb.startMinute), UInt8(noDisturb.endHour), UInt8(noDisturb.endMinute)] return createDataPacket(key: .setNoDisturb, bytes: bytes) } diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index 7efeeb7..629a504 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -178,6 +178,7 @@ enum SyncType: UInt8 { case gps = 0x0A case intensiveTime = 0x0B case beidouCard = 0x0C + case noDisturb = 0x0D case firmwareVersion = 0x14 case other = 0xff } diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index 1d5bd03..fd2a17b 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -164,9 +164,8 @@ extension BluetoothManager { } // 设置勿扰模式 - // remind 使用RemindModel数据类型,该接口使用到了isOn,startDate,endDate这三个字段 - func newSetNotDisturb(remind: RemindModel, completion: @escaping(_ error: Int?) -> ()) { - let data = BleMessage.shared.getNotDisturbCmd(remind) + func newSetNotDisturb(noDisturb: NewNoDisturbModel, completion: @escaping(_ error: Int?) -> ()) { + let data = BleMessage.shared.getNotDisturbCmd(noDisturb) self.setCmdClosure = completion sendData(data) } @@ -259,6 +258,12 @@ extension BluetoothManager { newStartSyncHealthData(closure: closure, data: data, synType: .beidouCard) } + // 拉取勿扰模式 + func newGetNoDisturbData(option: SyncOption = .now, closure: NoDisturbClosure? = nil) { + let data = BleMessage.shared.getSyncCmd(.noDisturb, option) + newStartSyncHealthData(closure: closure, data: data, synType: .noDisturb) + } + // 拉取固件版本号 func newGetfirmwareVersionData(option: SyncOption = .now, closure: FirmwareVersionClosure? = nil) { let data = BleMessage.shared.getSyncCmd(.firmwareVersion, option) @@ -624,6 +629,16 @@ extension BluetoothManager { }else { parseBeidouCardData(content) } + case 0x8030://勿扰模式 + print("勿扰模式") + let content = parseContentFromBytes(bytes) + if (content.count == 1 && content.first == 0xff) { + for delegate in syncDelegateList { + delegate.didReceiveFinishCommand(0x8030) + } + }else { + parseNoDisturbData(content) + } case 0x8037://固件版本号 print("固件版本号") let content = parseContentFromBytes(bytes) @@ -850,6 +865,17 @@ extension BluetoothManager { beidouCardClosure?(card, nil) } + // 勿扰模式 + func parseNoDisturbData(_ content: [UInt8]) { + guard content.count > 0 else { + print("无有效的信息") + noDisturbClosure?(nil, nil) + return + } + let noDisturb = NewNoDisturbModel.toNoDisturbModel(content) + noDisturbClosure?(noDisturb, nil) + } + // 运动数据 func parseExerciseData(_ content: [UInt8], _ index: Int) { guard content.count > 0 else { diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index 4ce7489..8d520bb 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -108,6 +108,8 @@ class BluetoothManager: NSObject { var intensiveTimeClosure: IntensiveTimeClosure? typealias BeidouCardClosure = (_ card:String?, _ error: Int?) -> Void var beidouCardClosure: BeidouCardClosure? + typealias NoDisturbClosure = (_ noDisturb:NewNoDisturbModel?, _ error: Int?) -> Void + var noDisturbClosure: NoDisturbClosure? typealias FirmwareVersionClosure = (_ first:Int?, _ second:Int?, _ error: Int?) -> Void var firmwareVersionClosure: FirmwareVersionClosure? @@ -418,7 +420,7 @@ class BluetoothManager: NSObject { } func setNotDisturb(remind: RemindModel, completion: @escaping(_ error: Int?) -> ()) { - newSetNotDisturb(remind: remind, completion: completion) +// newSetNotDisturb(remind: remind, completion: completion) } func setWristSense(_ bool: Bool, completion: ((_ error: Int?) -> ())? = nil) { @@ -1357,6 +1359,8 @@ class BluetoothManager: NSObject { intensiveTimeClosure = closure as? IntensiveTimeClosure case is BeidouCardClosure: beidouCardClosure = closure as? BeidouCardClosure + case is NoDisturbClosure: + noDisturbClosure = closure as? NoDisturbClosure case is FirmwareVersionClosure: firmwareVersionClosure = closure as? FirmwareVersionClosure default: -- libgit2 0.21.4