diff --git a/Sources/BoostBLEKit/Hub/Boost.swift b/Sources/BoostBLEKit/Hub/Boost.swift index 3f8eeaf..a515a79 100644 --- a/Sources/BoostBLEKit/Hub/Boost.swift +++ b/Sources/BoostBLEKit/Hub/Boost.swift @@ -14,6 +14,52 @@ public final class Boost { public init() {} + public var connectedIOs: [PortId : IOType] = [ + 0x32: .rgbLight, + 0x00: .builtInMotor, + 0x01: .builtInMotor, + 0x10: .builtInMotor, + 0x3a: .tiltSensor, + 0x3b: .currentSensor, + 0x3c: .voltageSensor, + ] + + public let portMap: [Port: PortId] = [ + .A: 0x00, + .B: 0x01, + .C: 0x02, + .D: 0x03, + .AB: 0x10, + ] + + public func canSupportAsMotor(ioType: IOType) -> Bool { + switch ioType { + case .interactiveMotor, .builtInMotor, .mediumMotor, .trainMotor, .ledLight: + return true + default: + return false + } + } + + public func motorPowerCommand(port: Port, power: Int8) -> Command? { + guard let portId = portId(for: port) else { return nil } + guard let ioType = connectedIOs[portId] else { return nil } + + switch ioType { + case .interactiveMotor, .builtInMotor: + return InteractiveMotorPowerCommand(portId: portId, power: power) + case .mediumMotor, .trainMotor, .ledLight: + return MotorPowerCommand(portId: portId, power: power) + default: + return nil + } + } + } + + public final class MoveHubV1: Hub { + + public init() {} + public var connectedIOs: [PortId : IOType] = [ 0x32: .rgbLight, 0x37: .builtInMotor, diff --git a/Sources/BoostBLEKit/HubType.swift b/Sources/BoostBLEKit/HubType.swift index d87e24b..c851e03 100644 --- a/Sources/BoostBLEKit/HubType.swift +++ b/Sources/BoostBLEKit/HubType.swift @@ -11,6 +11,7 @@ import Foundation public enum HubType { case boost + case boostV1 case poweredUp case duploTrain } @@ -22,7 +23,11 @@ public extension HubType { switch manufacturerData[3] { case 0x40: - self = .boost + if manufacturerData[6] & 0x02 > 0 { + self = .boost + } else { + self = .boostV1 + } case 0x41: self = .poweredUp case 0x20: @@ -39,6 +44,8 @@ extension HubType: CustomStringConvertible { switch self { case .boost: return "Boost Move Hub" + case .boostV1: + return "Boost Move Hub (F/W 1.x)" case .poweredUp: return "Powered Up Smart Hub" case .duploTrain: