Skip to content

Commit

Permalink
Support Boost Move Hub F/W 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinichiro Oba committed Jun 29, 2019
1 parent 6b9ac6a commit 7960bfc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
46 changes: 46 additions & 0 deletions Sources/BoostBLEKit/Hub/Boost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion Sources/BoostBLEKit/HubType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
public enum HubType {

case boost
case boostV1
case poweredUp
case duploTrain
}
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 7960bfc

Please sign in to comment.