diff --git a/README.md b/README.md index d6cac1e..7cdffaa 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,34 @@ # SwiftyPi -## OUT OF DATE 9/15/21 - This package is heavily based on and would not be possible without [SwiftyGPIO](https://github.com/uraimo/SwiftyGPIO). This is not meant to be a replacement, more like an extra layer to make using Swift with rPi devices such as buttons, relays, LEDs, UART and LCDs easier. Support is currently limited as this is a hobby. Since SwiftyPi is made to work in conjunction with [ApusRupus](https://github.com/doHernandezM/ApusRubus) I have decided against implementing a delegate. You will have to actively poll each device in a loop for state. I may change this to implement the timer better. -## Funtionality options: +## See SwiftyPi.DocC / In source comments + + +## ~~Funtionality options: I recommend visiting SwiftyGPIO and getting familiar with this API first. However, the goal to eventually be able to call many devices, so eventually SwiftyDevice is all you need to worry about. -Do this: +~~Do this: ```swift .package(url: "https://github.com/doHernandezM/SwiftyPi.git", ._exactItem("0.1.30")), ``` -### GPIO -* Use this to create a GPIO pin using the SwiftyGPIO pin naming convention, i.e. "P4" for pin 4. +### ~~GPIO +* ~~Use this to create a GPIO pin using the SwiftyGPIO pin naming convention, i.e. "P4" for pin 4. ```swift public init(gpioPinName: String, theType: SwiftyPiType) ``` -### Device actions -* Each device has an action that can be run at a certain time depending on type and protocol. This is a simple block that returns nothing, of the type: +### ~~Device actions +* ~~Each device has an action that can be run at a certain time depending on type and protocol. This is a simple block that returns nothing, of the type: ```swift public typealias CompletionHandler = () -> Void ``` -* To set this action assign a block( () -> Void ) to a device's handler. This block will be called during the device's "action" event. +* ~~To set this action assign a block( () -> Void ) to a device's handler. This block will be called during the device's "action" event. ```swift public var handler: CompletionHandler? = nil ``` -* To set or get a device's state, or pin value, use: +* ~~To set or get a device's state, or pin value, use: ```swift public var bool: Bool public var int: Int diff --git a/Sources/SwiftyPi/DeviceController.swift b/Sources/SwiftyPi/DeviceController.swift deleted file mode 100644 index 3dd8d77..0000000 --- a/Sources/SwiftyPi/DeviceController.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// File.swift -// -// -// Created by Dennis Hernandez on 9/13/21. -// - -import Foundation -import SwiftyGPIO - -///Optional controller for SwiftyPi devices. -/// -///You can access youur devices and their values directly or have the controller do it for you. -open class DeviceController { - public typealias Devices = [String:SwiftyPiDevice] - private var devices:Devices = [:] - private var timer:Timer - private var timeInterval:TimeInterval = 0.1 - private var loops:Int = 0 - - ///Init the controller with the default time interval and loop - public init(devices: [SwiftyPiDevice]) { - timer = Timer(timeInterval: self.timeInterval, loops: self.loops) - - self.add(devices: devices) - - timer.handler = { [self] in - action() - } - } - - ///Init the controller with custom time interval and loop - public init(timeInterval: TimeInterval, loops: Int, devices: [SwiftyPiDevice]) { - timer = Timer(timeInterval: self.timeInterval, loops: self.loops) - - self.add(devices: devices) - - timer.handler = { [self] in - action() - } - } - - ///Set off action for all of the devices. - func action() { - self.devices.forEach { _,device in - device.action() - } - } - - ///Add device to controller's device dictionary. - open func add(devices:[SwiftyPiDevice]) { - devices.forEach { device in - self.devices[device.state.name] = device - } - } - -} diff --git a/Sources/SwiftyPi/Pin.swift b/Sources/SwiftyPi/Pin.swift index 052fda9..8c82e51 100644 --- a/Sources/SwiftyPi/Pin.swift +++ b/Sources/SwiftyPi/Pin.swift @@ -17,7 +17,7 @@ public struct PinState: DeviceState, Codable { } } -//MARK:GPIO +//MARK:Pin ///This is our basic "pin" device. /// ///The best way to use this is to get the ``int``/``bool``/``mode``. diff --git a/Sources/SwiftyPi/SwiftyPiDevice.swift b/Sources/SwiftyPi/SwiftyPiDevice.swift index c4ab706..8362263 100644 --- a/Sources/SwiftyPi/SwiftyPiDevice.swift +++ b/Sources/SwiftyPi/SwiftyPiDevice.swift @@ -13,6 +13,7 @@ import SwiftyGPIO public enum DeviceProtocol: String { case GPIO, PWM, MC3008, PCA9685, UART, I2C, SPI } + public enum Device: String { case DigitalPin,AnalogPin, PWMPin }