From: liangzhenying <867174124@qq.com> Date: Tue, 2 Jul 2024 06:24:25 +0000 (+0800) Subject: 设置屏幕协议修改 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=8ce54177a7b5c71a7f21c2a1fddeb40ceedee656;p=mirrors%2FIOTBluetooth-iOS.git 设置屏幕协议修改 --- diff --git a/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift b/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift index 2322d08..938dda3 100644 --- a/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift +++ b/IOTBluetooth/IOTBluetooth/Example/AbilityViewController.swift @@ -10,16 +10,24 @@ import IOTBluetooth class AbilityViewController: BaseViewController { + + @IBOutlet weak var listView: UITableView! override func viewDidLoad() { super.viewDidLoad() title = "已连接" + IBManager.currentConnected!.name + navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Log", style: .plain, target: self, action: #selector(showLog)) } deinit { IBManager.remove(self) } + + @objc func showLog(){ + let vc = storyboard!.instantiateViewController(identifier: "LogViewController") + navigationController?.pushViewController(vc, animated: true) + } } extension AbilityViewController: UITableViewDelegate, UITableViewDataSource { diff --git a/IOTBluetooth/IOTBluetooth/Example/Datas.swift b/IOTBluetooth/IOTBluetooth/Example/Datas.swift index 14b1189..17b4dd0 100644 --- a/IOTBluetooth/IOTBluetooth/Example/Datas.swift +++ b/IOTBluetooth/IOTBluetooth/Example/Datas.swift @@ -8,6 +8,8 @@ import Foundation import IOTBluetooth + + let datas: [(ability: IBAbility, label: String, parameters: [IBParameter])] = [ (.userData,"设置用户数据",[.userInfo(IBUserInfo())]), (.language, "设置语言", [.language(.english)]), @@ -23,7 +25,7 @@ let datas: [(ability: IBAbility, label: String, parameters: [IBParameter])] = [ (.reboot, "重新启动", []), (.shutdown, "关机", []), (.fetchScreen, "获取手表屏幕参数", []), - (.screen, "设置手表屏幕参数", [.screen(IBScreen())]), + (.screen, "设置手表屏幕参数", [.screen(Config.setScreen())]), (.fetchBattery, "获取电量", []), (.fetchClock, "获取闹钟设置", []), (.setClock, "发送闹钟设置", [.clock(IBClock())]), @@ -83,6 +85,7 @@ let datas: [(ability: IBAbility, label: String, parameters: [IBParameter])] = [ (.syncCalorie, "同步卡路里历史数据", [.value(0)]), (.syncDistance, "同步距离历史数据", [.value(0)]), (.syncTrain, "同步基础训练历史数据", [.value(0)]), + (.syncSleep, "同步睡眠历史数据", [.value(0)]), (.syncGPS, "同步路径坐标集历史数据", [.value(1654012800)]), (.sendSyncEnd, "发送同步数据结束消息", []), (.addressBook, "发送通讯录", [.addressBook([IBAddressBook()])]), @@ -101,3 +104,17 @@ let datas: [(ability: IBAbility, label: String, parameters: [IBParameter])] = [ (.sendWeather, "发送天气数据", [.weather(IBWeather())]), ] + +class Config{ + static func setScreen()->IBScreenConfig{ + let model = IBScreenConfig() + model.type = 0 + model.brightness = 255 + +// model.type = 1 +// model.duration = .minute +// model.wrist = 0 + + return model + } +} diff --git a/IOTBluetooth/IOTBluetooth/Example/LogViewController.swift b/IOTBluetooth/IOTBluetooth/Example/LogViewController.swift index 246784a..2d8b114 100644 --- a/IOTBluetooth/IOTBluetooth/Example/LogViewController.swift +++ b/IOTBluetooth/IOTBluetooth/Example/LogViewController.swift @@ -19,6 +19,9 @@ class LogViewController: BaseViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) textView.text = IBManager.logs.joined(separator: "\n") + + let range = NSMakeRange(textView.text.count - 1, 1) + textView.scrollRangeToVisible(range) } } diff --git a/IOTBluetooth/IOTBluetooth/Example/ViewController.swift b/IOTBluetooth/IOTBluetooth/Example/ViewController.swift index 1d6af06..0d68752 100644 --- a/IOTBluetooth/IOTBluetooth/Example/ViewController.swift +++ b/IOTBluetooth/IOTBluetooth/Example/ViewController.swift @@ -16,6 +16,7 @@ class ViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() title = "IOTBluetooth" + navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Log", style: .plain, target: self, action: #selector(showLog)) IBManager.subscribe(.connectStateDidChange, observer: self) { object, userInfo in print("connect notice " + "\(object!)") @@ -44,6 +45,7 @@ class ViewController: BaseViewController { } @IBAction func startScan(_ sender: UIButton) { + print("loggger ...") title = "正在扫描蓝牙设备..." IBManager.scan { [unowned self] peripheral in if let _ = datas.filter({ $0.uuid == peripheral.uuid }).last { @@ -64,7 +66,10 @@ class ViewController: BaseViewController { IBManager.stopScan() title = "IOTBluetooth" } - + @objc func showLog(){ + let vc = storyboard!.instantiateViewController(identifier: "LogViewController") + navigationController?.pushViewController(vc, animated: true) + } } extension ViewController: UITableViewDelegate, UITableViewDataSource { diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index a29aacd..a1c401b 100644 Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index b99ea7c..9ace3af 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -14,8 +14,8 @@ filePath = "IOTBluetooth/IBChecker.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "348" - endingLineNumber = "348" + startingLineNumber = "362" + endingLineNumber = "362" landmarkName = "unknown" landmarkType = "0"> @@ -39,16 +39,16 @@ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift index 50ca79f..32277be 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift @@ -175,10 +175,24 @@ struct IBBloodOxygenChecker: IBChecker { } struct IBScreenChecker: IBChecker { static func check(_ parameters: [IBParameter]) -> [UInt8] { - guard case let .screen(value) = parameters[.screen] else { fatalError("缺少参数: screen") } + guard case let .screen(value) = parameters[.screen] else { fatalError("缺少参数: IBScreenConfig") } Logger.log(value.description) - let data = [value.brightness.byte] + [value.duration.rawValue.byte] + [value.wrist.byte] - return data + if value.type == 0{ + if let brightness = value.brightness { + return [value.type.byte] + [brightness.byte] + } + else{ + fatalError("参数错误: IBScreenConfig") + } + } + else{ + if let duration = value.duration,let wrist = value.wrist { + return [value.type.byte] + [duration.rawValue.byte] + [wrist.byte] + } + else{ + fatalError("参数错误: IBScreenConfig") + } + } } } diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBManager.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBManager.swift index 06c43b0..1949760 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBManager.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBManager.swift @@ -27,11 +27,23 @@ public class IBManager { } public static var logs: [String] { Logger.logs } + + +// public static func redirectNSlogToDocumentFolder() { +// let filePath: String = NSHomeDirectory () + "IOTBluetooth_\(Date().format(.long)).log" +// let defaultManager = FileManager.default +// try? defaultManager.removeItem(atPath: filePath) +// +// print("log path = " + filePath) +// +// freopen(filePath.cString(using: String.Encoding.ascii), "a+", stdout) +// freopen(filePath.cString(using: String.Encoding.ascii), "a+", stderr) +// } } public extension IBManager { /// SDK 版本号 - static let version: String = "1.0.14" + static let version: String = "1.0.15" /// 默认为 false static var isDebug: Bool = false { didSet { Logger.isDebug = isDebug } diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift index 1cc8df9..45599c7 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift @@ -67,7 +67,7 @@ public enum IBParameter { /// 血氧 case bloodOxygen(IBBloodOxygen) /// 设置屏幕 - case screen(IBScreen) + case screen(IBScreenConfig) /// 设置声音和震动 case vibrateSound(IBVibrateSound) /// 设置目标设置 diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBHistorySleep.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBHistorySleep.swift index b84a695..aad33d4 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBHistorySleep.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBHistorySleep.swift @@ -15,19 +15,36 @@ import Foundation if(data.count <= 0){ return } - +// 72 01 4b 02 00 00 00 47 00 00 00 01 00 00 00 3e 00 05 0c 00 01 00 1a 49 7e 66 2a 57 7e 66 64 00 0c 00 02 00 ed 53 7e 66 ed 53 7e 66 39 00 0c 00 03 00 28 1e 7e 66 38 2c 7e 66 0a 00 0c 00 04 00 f9 3f 7e 66 f9 3f 7e 66 2a 00 0c 00 05 00 e6 5b var historyList:[IBHistorySleepItem] = [] - let number = data[0].int - - - for i in stride(from: 0, to: data.count, by: 8){ - if data.count > i + 7 { - let model = IBHistorySleepItem() -// model.time = data[i...i+3].int -// model.value = data[i+4...i+7].int -// historyList.append(model) + let times = data[0].int + let contentData:Data = data.suffix(from: 1).map({ $0 }).data + var index = 0 + for _ in 0.. index + 1 { + let len = contentData[index...index+1].int + if contentData.count > index + len { + let itemData = contentData[index+2 ... index+1+len].map({ $0 }).data + let item = IBHistorySleepItem() + item.sleepId = itemData[0].int + item.type = itemData[1].int + item.startTime = itemData[2...5].int + item.endTime = itemData[6...9].int + item.totalSleep = IBSleepTime(hour: itemData[10].int, minute: itemData[11].int) + if(item.type == 1){ + item.deepSleep = IBSleepTime(hour: itemData[12].int, minute: itemData[13].int) + item.lightSleep = IBSleepTime(hour: itemData[14].int, minute: itemData[15].int) + item.remSleep = IBSleepTime(hour: itemData[16].int, minute: itemData[17].int) + item.awake = IBSleepTime(hour: itemData[18].int, minute: itemData[19].int) + item.states = IBSleepState(time: itemData[20...23].int, state: itemData[24].int) + } + historyList.append(item) + } + index += 2 + len } + } + list = historyList } } @@ -35,7 +52,7 @@ import Foundation /// 睡眠历史记录 public class IBHistorySleepItem { /// 睡眠ID,0~255,表示第几次睡眠 - public var sleepId: UInt8 = 0 + public var sleepId: Int = 0 /// 睡眠类型,0:小睡(无总时长之后的所有项目)1:睡眠 public var type: Int = 0 /// 入睡时间戳,Unix时间戳 @@ -45,15 +62,15 @@ public class IBHistorySleepItem { /// 总时长 public var totalSleep: IBSleepTime = IBSleepTime(hour: 0, minute: 0) /// 深睡时长 - public var deepSleep: IBSleepTime = IBSleepTime(hour: 0, minute: 0) + public var deepSleep: IBSleepTime? /// 浅睡时长 - public var lightSleep: IBSleepTime = IBSleepTime(hour: 0, minute: 0) + public var lightSleep: IBSleepTime? /// 快速动眼时长 - public var remSleep: IBSleepTime = IBSleepTime(hour: 0, minute: 0) + public var remSleep: IBSleepTime? /// 清醒时长 - public var awake: IBSleepTime = IBSleepTime(hour: 0, minute: 0) + public var awake: IBSleepTime? /// 睡眠状态 - public var states:[IBSleepState] = [] + public var states:IBSleepState? public init() { } @@ -78,9 +95,14 @@ public struct IBSleepTime { /// 睡眠状态 -public class IBSleepState { +public struct IBSleepState { /// Unix时间戳 public var time: Int = 0 /// 状态,0:进入睡眠 1:浅层睡眠 2:深层睡眠 3:清醒 4:结束睡眠 7:未出睡最后一笔睡眠数据(资料上报结束标志) 9:出睡最后一笔睡眠数据(资料上报结束标志) 12:快速眼动 13:取消入睡通知(睡眠不足 60 分钟出睡上报状态) 14:结束小睡 public var state: Int = 0 + + public init(time: Int, state: Int) { + self.time = time + self.state = state + } } diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBScreen.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBScreen.swift index 26d3cbd..9a1a017 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBScreen.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBScreen.swift @@ -7,6 +7,37 @@ import Foundation +/// 设置屏幕参数 +public class IBScreenConfig { + /// 类型 0,亮度调节; 1,亮屏时长,抬腕亮屏 + public var type: Int = 0 + + /// 亮度 [51, 255], type为0必须设置 + public var brightness: Int? + + /// 亮屏时长, type为1必须设置 + public var duration: IBDuration? + + /// 抬腕亮屏(0=关闭, 1=开启), type为1必须设置 + public var wrist: Int? + + public init() { } + + var description: String { + var str = "IBScreenConfig(type: \(type)," + if let brightness = brightness{ + str += "brightness: \(brightness ))" + } + if let duration = duration { + str += "duration: \(duration )" + } + if let wrist = wrist { + str += "wrist: \(wrist ))" + } + return str + } +} + /// 屏幕参数 public class IBScreen { /// 亮度 [0, 255]