From: liangzhenying <867174124@qq.com>
Date: Tue, 2 Jul 2024 06:24:25 +0000 (+0800)
Subject: 设置屏幕协议修改
X-Git-Url: http://git.snicker.com.cn/?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]