From 826e4aacf118b33a1fbc61b2210def9d0304e973 Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Mon, 23 Jul 2018 11:32:06 +0100 Subject: [PATCH] Add `canSupportAsMotor(ioType:)` method --- Sources/BoostBLEKit/Hub/Boost.swift | 9 +++++++++ Sources/BoostBLEKit/Hub/Hub.swift | 2 ++ Sources/BoostBLEKit/Hub/PoweredUp.swift | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/Sources/BoostBLEKit/Hub/Boost.swift b/Sources/BoostBLEKit/Hub/Boost.swift index 8c12b26..4b81e74 100644 --- a/Sources/BoostBLEKit/Hub/Boost.swift +++ b/Sources/BoostBLEKit/Hub/Boost.swift @@ -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 } diff --git a/Sources/BoostBLEKit/Hub/Hub.swift b/Sources/BoostBLEKit/Hub/Hub.swift index 47d198e..6f198a6 100644 --- a/Sources/BoostBLEKit/Hub/Hub.swift +++ b/Sources/BoostBLEKit/Hub/Hub.swift @@ -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? } diff --git a/Sources/BoostBLEKit/Hub/PoweredUp.swift b/Sources/BoostBLEKit/Hub/PoweredUp.swift index 0dd4e7c..80a6283 100644 --- a/Sources/BoostBLEKit/Hub/PoweredUp.swift +++ b/Sources/BoostBLEKit/Hub/PoweredUp.swift @@ -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 }