Skip to content

Commit

Permalink
Add canSupportAsMotor(ioType:) method
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinichiro Oba committed Jul 23, 2018
1 parent ca10def commit 826e4aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/BoostBLEKit/Hub/Boost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public final class Boost {
.AB: 0x39,
]

public func canSupportAsMotor(ioType: IOType) -> Bool {
switch ioType {
case .interactiveMotor, .builtInMotor, .mediumMotor, .trainMotor:
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 }
Expand Down
2 changes: 2 additions & 0 deletions Sources/BoostBLEKit/Hub/Hub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public protocol Hub {
func port(for portId: PortId) -> Port?
func portId(for port: Port) -> PortId?

func canSupportAsMotor(ioType: IOType) -> Bool

func motorPowerCommand(port: Port, power: Int8) -> Command?
func rgbLightColorCommand(color: RGBLightColorCommand.Color) -> Command?
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/BoostBLEKit/Hub/PoweredUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public final class PoweredUp {
.AB: 0x39,
]

public func canSupportAsMotor(ioType: IOType) -> Bool {
switch ioType {
case .mediumMotor, .trainMotor:
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 }
Expand Down

0 comments on commit 826e4aa

Please sign in to comment.