CGA_InitialViewController
class CGA_InitialViewController : CGA_BaseViewController
extension CGA_InitialViewController: CGA_ScannerViewController
extension CGA_InitialViewController: CGA_UpdatableScreenViewController
extension CGA_InitialViewController: CGA_BlueThoth_Delegate
extension CGA_InitialViewController: UITableViewDataSource
extension CGA_InitialViewController: UITableViewDelegate
This controls the initial view, which is a basic table of discovered devices.
There are two sections: BLE, and BR/EDR (Classic). Each section has rows of devices that fit in that Bluetooth mode.
-
These are the indexes for our sections.
See moreDeclaration
Swift
private enum _SectionIndexes : Int
-
The time between repeats of the RSSI update timer.
Declaration
Swift
private static let _rssiTimerIntervalInSeconds: TimeInterval
-
This is how high each section header will be.
Declaration
Swift
private static let _sectionHeaderHeightInDisplayUnits: CGFloat
-
This is how high the labels that comprise one row will need per line of text.
Declaration
Swift
private static let _labelRowHeightInDisplayUnits: CGFloat
-
The reuse ID that we use for creating new table cells.
Declaration
Swift
private static let _deviceRowReuseID: String
-
The ID of the segue that is executed to display device details.
Declaration
Swift
private static let _deviceDetailSegueID: String
-
This implements a “pull to refresh.”
Declaration
Swift
private let _refreshControl: UIRefreshControl
-
Returns the pushed device details screen. Nil, if none.
Declaration
Swift
private var _currentDeviceScreen: CGA_UpdatableScreenViewController! { get }
-
Returns true, if the Central Manager is currently scanning.
Declaration
Swift
var isScanning: Bool { get }
-
Used as a semaphore (yuck) to indicate that the Central was (or was not) scanning before the view disappeared. It is also used for editing the table, to prevent it from aborting deletes.
Declaration
Swift
var wasScanning: Bool
-
This is the label above the table.
Declaration
Swift
@IBOutlet weak var deviceLabel: UILabel!
-
This is the table that will list the discovered devices.
Declaration
Swift
@IBOutlet weak var deviceTableView: UITableView!
-
This image is displayed if there is no bluetooth available.
Declaration
Swift
@IBOutlet weak var noBTImage: UIImageView!
-
This will animate when the central is scanning.
Declaration
Swift
@IBOutlet weak var scanningButton: UIButton!
-
Declaration
Swift
@IBOutlet weak var editButtonStackView: UIStackView!
-
Declaration
Swift
@IBOutlet weak var editButton: UIButton!
-
This is the about/info button.
Declaration
Swift
@IBOutlet weak var infoButton: UIButton!
-
This is the settings button.
Declaration
Swift
@IBOutlet weak var settingsButton: UIButton!
-
This is called by the table’s “pull to refresh” handler.
When this is called, the Bluetooth subsystem wipes out all of its cached Peripherals, and starts over from scratch.
Declaration
Swift
@objc func startOver(_: Any)
-
This is called when the “Scanning/Not Scanning” button is hit.
Declaration
Swift
@IBAction func scanningButtonHit(_: Any)
-
Declaration
Swift
@IBAction func editButtonHit(_: Any)
-
Called after the view data has been loaded.
Declaration
Swift
override func viewDidLoad()
-
Called just before the view appears. We use this to hide the navBar.
Declaration
Swift
override func viewWillAppear(_ inAnimated: Bool)
Parameters
inAnimated
True, if the appearance is animated (we ignore this).
-
Called just before the view disappears. We use this to show the navBar.
Declaration
Swift
override func viewWillDisappear(_ inAnimated: Bool)
Parameters
inAnimated
True, if the appearance is animated (we ignore this).
-
This is called just before we bring in the device screen (or the about screen).
Declaration
Swift
override func prepare(for inSegue: UIStoryboardSegue, sender inSender: Any?)
Parameters
for
The segue being executed.
sender
The data we want passed into the destination.
-
Make sure that the Navigation Controller is at tits baseline.
Declaration
Swift
private func _resetToRoot()
-
Calling this toggles the scanning mode.
Declaration
Swift
private func _toggleScanningMode()
-
Starts scanning for Peripherals. If already scanning, nothing happens.
Declaration
Swift
private func _startScanning()
-
Makes sure that we have all devices disconnected.
Declaration
Swift
private func _clearAllConnections()
-
Stops scanning for Peripherals. If already stopped, nothing happens.
Declaration
Swift
private func _stopScanning()
-
This sets up the accessibility and voiceover strings for the screen.
Declaration
Swift
func setUpAccessibility()
-
This is called from presented view controllers, and will restart scanning, if we were scanning before. If not, nothing happens.
Declaration
Swift
func restartScanningIfNecessary()
-
This simply makes sure that the table is displayed if BT is available, or the “No BT” image is shown, if it is not.
Declaration
Swift
func updateUI()
-
Called to report an error.
Declaration
Swift
func handleError(_ inError: CGA_Errors, from inCentralManager: RVS_BlueThoth)
Parameters
inError
The error being reported.
from
The manager wrapper view that is calling this.
-
Called to tell the instance that the state of the Central manager just became “powered on.”
Declaration
Swift
func centralManagerPoweredOn(_ inCentralManager: RVS_BlueThoth)
Parameters
inCentralManager
The central manager that is calling this.
-
Called to tell this controller to recalculate its table.
Declaration
Swift
func updateFrom(_ inCentralManager: RVS_BlueThoth)
Parameters
inCentralManager
The manager wrapper view that is calling this.
-
Called to tell the instance that a Peripheral device has been connected.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, didConnectThisDevice inDevice: CGA_Bluetooth_Peripheral)
Parameters
inCentralManager
The central manager that is calling this.
didConnectThisDevice
The device instance that was connected.
-
Called to tell the instance that a peripheral device is about to be disconnected. We use this to reset the view stack to the initial (Peripheral List) screen.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, willDisconnectThisDevice inDevice: CGA_Bluetooth_Peripheral)
Parameters
inCentralManager
The central manager that is calling this.
willDisconnectThisDevice
The device instance that will be removed after this call.
-
This is called to tell the instance that a Peripheral device has had some change.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, deviceInfoChanged inDevice: CGA_Bluetooth_Peripheral)
Parameters
inCentralManager
The central manager that is calling this.
deviceInfoChanged
The device instance that was connected.
-
Called to tell the instance that a Characteristic changed its notification state.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, device inDevice: CGA_Bluetooth_Peripheral, service inService: CGA_Bluetooth_Service, changedCharacteristicNotificationState inCharacteristic: CGA_Bluetooth_Characteristic)
Parameters
inCentralManager
The central manager that is calling this.
device
The device instance that contained the changed Service.
changedService
The Service instance that contained the changed Characteristic.
changedCharacteristicNotificationState
The Characteristic that was changed.
-
Called to tell the instance that a Service changed.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, device inDevice: CGA_Bluetooth_Peripheral, changedService inService: CGA_Bluetooth_Service)
Parameters
inCentralManager
The central manager that is calling this.
device
The device instance that contained the changed Service.
changedService
The Service instance that contained the changed Characteristic.
-
Called to tell the instance that a Characteristic changed its value.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, device inDevice: CGA_Bluetooth_Peripheral, service inService: CGA_Bluetooth_Service, changedCharacteristic inCharacteristic: CGA_Bluetooth_Characteristic)
Parameters
inCentralManager
The central manager that is calling this.
device
The device instance that contained the changed Service.
service
The Service instance that contained the changed Characteristic.
changedCharacteristic
The Characteristic that was changed.
-
Called to tell the instance that a Descriptor changed.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, device inDevice: CGA_Bluetooth_Peripheral, service inService: CGA_Bluetooth_Service, characteristic inCharacteristic: CGA_Bluetooth_Characteristic, changedDescriptor inDescriptor: CGA_Bluetooth_Descriptor)
Parameters
inCentralManager
The central manager that is calling this.
device
The device instance that contained the changed Service.
service
The Service instance that contained the changed Characteristic.
characteristic
The Characteristic that contains the Descriptor that was changed.
changedDescriptor
The Descriptor that was changed.
-
This is called to tell the instance that a Characteristic write with response received its response.
Declaration
Swift
func centralManager(_ inCentralManager: RVS_BlueThoth, device inPeripheral: CGA_Bluetooth_Peripheral, service inService: CGA_Bluetooth_Service, characteristicWriteComplete inCharacteristic: CGA_Bluetooth_Characteristic)
Parameters
inCentralManager
The central manager that is calling this.
device
The device instance that contained the changed Service.
service
The Service instance that contained the changed Characteristic.
characteristicWriteComplete
The Characteristic that had its write completed.
-
This returns the number of available sections.
There will be 2 sections: Classic, and BLE.
Declaration
Swift
func numberOfSections(in inTableView: UITableView) -> Int
Parameters
in
The table view that is asking for the section count.
-
This returns the height of the requested section header.
Declaration
Swift
func tableView(_ inTableView: UITableView, heightForHeaderInSection inSection: Int) -> CGFloat
Parameters
inTableView
The table view that is asking for the header (ignored).
heightForHeaderInSection
The 0-based section index being queried (ignored).
Return Value
The height, in display units, of the header for the section.
-
Returns a section header.
Declaration
Swift
func tableView(_ inTableView: UITableView, viewForHeaderInSection inSection: Int) -> UIView?
Parameters
inTableView
The table view that is asking for the header.
viewForHeaderInSection
The 0-based section index being queried.
Return Value
The header for the section, as a view (a label).
-
This returns the number of available rows, in the given section.
Declaration
Swift
func tableView(_ inTableView: UITableView, numberOfRowsInSection inSection: Int) -> Int
Parameters
inTableView
The table view that is asking for the row count.
numberOfRowsInSection
The 0-based section index being queried.
Return Value
The number of rows in the given section.
-
This returns the number of available rows, in the given section.
Declaration
Swift
func tableView(_ inTableView: UITableView, heightForRowAt inIndexPath: IndexPath) -> CGFloat
Parameters
inTableView
The table view that is asking for the row count.
heightForRowAt
The index of the row.
Return Value
The height of the row, in display units.
-
This returns a view, with the data for the given row and section.
See moreDeclaration
Swift
func tableView(_ inTableView: UITableView, cellForRowAt inIndexPath: IndexPath) -> UITableViewCell
Parameters
inTableView
The table view that is asking for the cell.
cellForRowAt
The index path (section, row) for the cell.
-
Called to test whether or not to allow a row to be selected.
Declaration
Swift
func tableView(_ inTableView: UITableView, willSelectRowAt inIndexPath: IndexPath) -> IndexPath?
Parameters
inTableView
The table view that is asking for the cell.
willSelectRowAt
The index path (section, row) for the cell.
Return Value
The IndexPath of the cell, if approved, or nil, if not.
-
Called to test whether or not to allow a row to be higlighted.
This prevents the unselectable row from “flashing” when someone touches it.
Declaration
Swift
func tableView(_ inTableView: UITableView, shouldHighlightRowAt inIndexPath: IndexPath) -> Bool
Parameters
inTableView
The table view that is asking for the cell.
shouldHighlightRowAt
The index path (section, row) for the cell.
Return Value
The IndexPath of the cell, if approved, or nil, if not.
-
Called when a row is selected.
Declaration
Swift
func tableView(_ inTableView: UITableView, didSelectRowAt inIndexPath: IndexPath)
Parameters
inTableView
The table view that is asking for the cell.
didSelectRowAt
The index path (section, row) for the cell.
-
Indicate that a row can be edited (for left-swipe delete).
Declaration
Swift
func tableView(_: UITableView, canEditRowAt: IndexPath) -> Bool
Parameters
canEditRowAt
Ignored
Return Value
true, but only if we are not scanning. If we are scanning, we can’t edit table rows.
-
Called to do a delete action.
Declaration
Swift
func tableView(_ inTableView: UITableView, commit inEditingStyle: UITableViewCell.EditingStyle, forRowAt inIndexPath: IndexPath)
Parameters
inTableView
The table view being edited
commit
The action to perform.
forRowAt
The indexpath of the row to be deleted.