RVS_BTDriver
public class RVS_BTDriver : NSObject
extension RVS_BTDriver: RVS_BTDriverCommunicatorTools
extension RVS_BTDriver: RVS_SequenceProtocol
This is the main driver class. It is the “manager” for all the bluetooth-connected devices, which are accessible as RVS_BTDriver_DeviceProtocol
-conformant instances.
The RVS_BTDriver
instance can be treated like a Sequence, with an iterator, higher-order functions and subscripting.
Just remember that it aggregates a protocol, not a class/struct, so you see a “mask” over a different class that is known internally.
-
This contains the device list for this instance of the driver.
Declaration
Swift
private var _device_list: [RVS_BTDriver_Device]
-
This is a flag that specifies that the scanner can be continuously running, and “re-finding” duplicate devices. If true, it could adversely affect battery life. Default is false.
Declaration
Swift
internal var internal_AllowDuplicatesInBLEScan: Bool
-
This is a flag that tells us to remain connected continuously, until explicitly disconnected by the user. Default is false.
Declaration
Swift
internal var internal_stayConnected: Bool
-
This contains instances that have not yet passed a credit check.
Declaration
Swift
internal var internal_holding_pen: [RVS_BTDriver_Device] { get set }
-
This contains any queue we’re supposed to use. Nil (default) is the main queue.
Declaration
Swift
internal weak var internal_queue: DispatchQueue!
-
The delegate. It is a weak reference.
Declaration
Swift
internal weak var internal_delegate: RVS_BTDriverDelegate!
-
This will contain our vendor factory instances. This is loaded at instantiation time.
Declaration
Swift
internal var internal_vendors: [RVS_BTDriver_VendorProtocol]
-
The main internal initializer.
Declaration
Swift
internal init(_ inDelegate: RVS_BTDriverDelegate, vendors inVendors: [RVS_BTDriver_VendorTypes] = [], queue inQueue: DispatchQueue? = nil, allowDuplicatesInBLEScan inAllowDuplicatesInBLEScan: Bool = false, stayConnected inStayConnected: Bool = false)
Parameters
inDelegate
The delegate to be used with this instance. It cannot be nil, and is a weak reference.
vendors
This is an Array of vendor enums, and is used to determine which vendors will be loaded.
queue
This is a desired queue for the CB manager to operate from. It is optional, and default is nil (main queue).
allowDuplicatesInBLEScan
This is a flag that specifies that the scanner can be continuously running, and “re-finding” duplicate devices. If true, it could adversely affect battery life. Default is false.
stayConnected
This is set to true, if you want all your device connections to be persistent. That is, once connected, they must be explicitly disconencted by the user. Otherwise, each device will be connected only while interacting. This is optional. Default is false.
-
Make sure that everything is put back the way we found it…
Declaration
Swift
deinit
-
This is here to satisfy the sequence protocol. It should not be called.
Declaration
Swift
public required init(sequence_contents inSequence_contents: [RVS_BTDriver_DeviceProtocol])
Parameters
sequence_contents
Ignored
-
This method will find a device in the holding pen, and replace it with a new device.
Declaration
Swift
internal func replaceThisDeviceInTheHoldingPen(_ inDevice: RVS_BTDriver_Device, withThisDevice inReplacementDevice: RVS_BTDriver_Device)
Parameters
inDevice
The device object to be replaced.
withThisDevice
The device to be used as a replacement.
-
This method will move a device from the holding pen to the main list.
Declaration
Swift
internal func moveDeviceFromHoldingPenToMainList(_ inDevice: RVS_BTDriver_Device)
Parameters
inDevice
The device object to be moved.
-
This method runs through our “holding pen,” and will start device on their initialization (if not started), or move them to the completed queue, if they are done.
Declaration
Swift
internal func triageHoldingPen()
-
This method will remove a device from the holding pen or the main list.
Declaration
Swift
internal func removeThisDevice(_ inDevice: RVS_BTDriver_Device)
Parameters
inDevice
The device object to be removed.
-
Called to report that our holding pen is empty.
Declaration
Swift
internal func reportCompletion()
-
See if the given device is still in the holding pen.
Declaration
Swift
internal func deviceIsInHoldingPen(_ inDevice: RVS_BTDriver_Device) -> Bool
Return Value
True, if the device is still in the holding pen.
-
See if the given device is done with initialization, and is in the main list.
Declaration
Swift
internal func deviceIsInMainList(_ inDevice: RVS_BTDriver_Device) -> Bool
Return Value
True, if the device is in the main list.
-
Declaration
Swift
internal func addDiscoveredDevice(_ inDevice: RVS_BTDriver_Device)
-
The buck stops here.
Declaration
Swift
internal func reportThisError(_ inError: RVS_BTDriver.Errors)
Parameters
inError
The error to be sent to the delegate.
-
This method will send the driver delegate an update event, on behalf of a interface.
Declaration
Swift
internal func sendInterfaceUpdate(_ inInterface: RVS_BTDriver_InterfaceProtocol)
Parameters
inInterface
The interface that wants to send an update.
-
This method will send the driver delegate an update event, on behalf of a device.
Declaration
Swift
internal func sendDeviceUpdate(_ inDevice: RVS_BTDriver_Device)
Parameters
inDevice
The device that wants to send an update.
-
We aggregate devices.
Declaration
Swift
public typealias Element = RVS_BTDriver_DeviceProtocol
-
This is a public read-only list of devices, masked by the protocol.
Declaration
Swift
public var sequence_contents: [Element] { get set }
-
The error enum declaration.
See moreDeclaration
Swift
public enum Errors : Error
-
Simple “String Key” subscript, so we can treat the array as a dictionary.
Declaration
Swift
public subscript(inStringKey: String) -> RVS_BTDriver_DeviceProtocol! { get }
Parameters
inStringKey
A String, containing the unique UUID of the device we are looking for.
Return Value
The device, or nil, if not found.
-
A weak reference to the instance delegate.
Declaration
Swift
public var delegate: RVS_BTDriverDelegate! { get set }
-
This is KVO (READ-ONLY)
Declaration
Swift
@objc dynamic public var isBTAvailable: Bool { get }
Return Value
true, if all of the vendor interfaces have Bluetooth powered on.
-
This is KVO (READ-ONLY)
Declaration
Swift
@objc dynamic public var isScanning: Bool { get }
Return Value
true, if even one of the vendor interfaces is in active scanning.
-
Tells the vendor interfaces (all of them) to start scanning for services.
Declaration
Swift
public func startScanning()
-
Tells the vendor interfaces to stop scanning.
Declaration
Swift
public func stopScanning()
-
Removes an indicated device from our list.
Declaration
Swift
public func removeDevice(_ inDevice: RVS_BTDriver_DeviceProtocol)
Parameters
inDevice
The device instance to be removed. After this call, it should be considered invalid.
-
The main initializer.
Declaration
Swift
public convenience init(delegate inDelegate: RVS_BTDriverDelegate, vendors inVendors: [RVS_BTDriver_VendorTypes] = [], queue inQueue: DispatchQueue? = nil, allowDuplicatesInBLEScan inAllowDuplicatesInBLEScan: Bool = false, stayConnected inStayConnected: Bool = false)
Parameters
delegate
The delegate to be used with this instance. It cannot be nil, and is a weak reference.
vendors
This is an Array of vendor enums, and is used to determine which vendors will be loaded.
queue
This is a desired queue for the CB manager to operate from. It is optional, and default is nil (main queue).
allowDuplicatesInBLEScan
This is a flag that specifies that the scanner can be continuously running, and “re-finding” duplicate devices. If true, it could adversely affect battery life. Default is false.
stayConnected
This is set to true, if you want all your device connections to be persistent. That is, once connected, they must be explicitly disconencted by the user. Otherwise, each device will be connected only while interacting. This is optional. Default is false.
-
This is a simplified, readable description of the instance that should be quite useful.
Declaration
Swift
@objc dynamic public override var description: String { get }