From e9e55374bd71f9e7bdb97eafd1bf521d4d4ac7ba Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Mon, 10 Sep 2018 23:50:42 +0100 Subject: [PATCH] Improve comments --- Sources/BoostBLEKit/IOType.swift | 14 +++++++------- Sources/BoostBLEKit/Notification.swift | 15 +++++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Sources/BoostBLEKit/IOType.swift b/Sources/BoostBLEKit/IOType.swift index 354933d..54db0a2 100644 --- a/Sources/BoostBLEKit/IOType.swift +++ b/Sources/BoostBLEKit/IOType.swift @@ -42,19 +42,19 @@ extension IOType { case .piezoSpeaker: return nil case .rgbLight: - return 0 + return 0 // Not working on Boost and Powered Up case .tiltSensor: - return 1 + return 1 // 0: Tilt (x,y), 1: 2D Orientation, 2: Impact Count?? (3 bytes) 3: Tilt (x,y,z) case .motionSensor: - return 0 + return 0 // 0: Distance, 1: Count, 2: ?? (6 bytes) case .colorAndDistanceSensor: - return 8 + return 8 // 8: Color, Distance, and Ambient Light Level case .interactiveMotor: - return 2 + return 2 // 0: ??, 1: Speed, 2: Position case .builtInMotor: - return 2 + return 2 // 0: ??, 1: Speed, 2: Position case .builtInTiltSensor: - return 1 + return 2 // 0: Tilt (x,y), 1: 2D Orientation, 2: 3D Orientation, 3: Impact Count, 4: Tilt (x,y,z) } } } diff --git a/Sources/BoostBLEKit/Notification.swift b/Sources/BoostBLEKit/Notification.swift index 2f34b14..124938e 100644 --- a/Sources/BoostBLEKit/Notification.swift +++ b/Sources/BoostBLEKit/Notification.swift @@ -53,12 +53,19 @@ extension Notification: CustomStringConvertible { public var description: String { switch self { case .connected(let portId, let ioType): - return "Connected \(ioType) into \(portId)" + return "Connected \(ioType) into Port \(portId.hexString)" case .disconnected(let portId): - return "Disconnected an I/O from \(portId)" + return "Disconnected an I/O from Port \(portId.hexString)" case .sensorValue(let portId, let value): - let hex = value.map { String(format: "%02x", $0) }.joined(separator: " ") - return "Sensor value \(hex) from \(portId)" + let hex = value.map { $0.hexString }.joined(separator: " ") + return "Sensor value [\(hex)] from Port \(portId.hexString)" } } } + +private extension UInt8 { + + var hexString: String { + return String(format: "%02x", self) + } +}