Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
SGBlePeripheralQueue Class Reference

Implementation of the CBPeripheralDelegate protocol. Queues up operations to be performed with a Bluetooth Low Energy (BLE) peripheral, run them sequentially and notify of their outcome. More...

#include <SGBlePeripheralQueue.h>

Inheritance diagram for SGBlePeripheralQueue:

Instance Methods

Initialization
(instancetype) - initWithPeripheral:centralManagerDelegate:
 Initializes a SGBlePeripheralQueue instance for the given CBPeripheral object, with a central manager delegate and a connection event handler.
 
Connection and disconnection
(void) - queueConnectWithServices:completionHandler:
 Queues a request to connect to the peripheral.
 
(void) - queueDisconnect:
 Queues a request to disconnect the peripheral.
 
Peripheral operations

Valid only for connected peripherals.

(void) - queueReadRssi:
 Queues a request to read the Received Signal Strength Indicator (RSSI).
 
Characteristic operations

Valid only for connected peripherals.

(void) - queueReadValueForCharacteristic:valueReadHandler:
 Queues a request to read the value of the specified service's characteristic.
 
(void) - queueWriteValue:forCharacteristic:type:completionHandler:
 Queues a request to write the value of specified service's characteristic.
 
(void) - queueSetNotifyValueForCharacteristic:valueChangedHandler:completionHandler:
 Queues a request to enable or disable notifications for the specified service's characteristic.
 
Queue management.
(void) - cancelAll
 Cancel any pending or running request.
 

Properties

CBPeripheral * peripheral
 Gets the CBPeripheral object for this peripheral.
 
bool isReady
 Indicates whether the peripheral is connected and has discovered its services.
 
int rssi
 Gets the last read value of the Received Signal Strength Indicator (RSSI).
 
void(^ _Nullable )(SGBlePeripheralQueue *peripheralQueue, SGBleConnectionEvent connectionEvent, SGBleConnectionEventReason reason)
 Callback for notifying connection status changes of the peripheral.
 

Detailed Description

Implementation of the CBPeripheralDelegate protocol. Queues up operations to be performed with a Bluetooth Low Energy (BLE) peripheral, run them sequentially and notify of their outcome.

The next queued operation (a SGBleRequest instance) is run only once the current one completes (whether successfully or not).

The connection request has no time out and waits until the peripheral is connected. Any subsequent request is therefore blocked until the connection is successful.

Call cancelQueue() to cancel all pending operations, including an on-going connection.

Handlers (such as request completion handlers) are called on the shared BLE queue, user code for those handlers should return as quickly as possible to avoid delaying any further BLE event or operation.

On being de-allocated, the instance cancels the connection to peripheral.

Note
A request keep a strong reference to the instance so the later won't be de-allocated until the queue is empty.

Method Documentation

◆ initWithPeripheral:centralManagerDelegate:

- (instancetype) initWithPeripheral: (CBPeripheral *)  peripheral
centralManagerDelegate: (SGBleCentralManagerDelegate *)  centralManagerDelegate 

Initializes a SGBlePeripheralQueue instance for the given CBPeripheral object, with a central manager delegate and a connection event handler.

Parameters
peripheralThe CBPeripheral object for the BLE peripheral.
centralManagerDelegateThe instance of SGBleCentralManagerDelegate that discovered the peripheral.
Returns
The initialized SGBlePeripheral instance.

◆ queueConnectWithServices:completionHandler:

- (void) queueConnectWithServices: (NSArray< CBUUID * > *)  services
completionHandler: (void(^)(NSError *_Nullable error))  completionHandler 

Queues a request to connect to the peripheral.

This request has not time out and waits until the peripheral is connected. Call cancelQueue() to cancel all pending operations.

Parameters
servicesList of services UUIDs that the peripheral should support, may be null or empty.
completionHandlerThe handler for notifying of the request result.

◆ queueDisconnect:

- (void) queueDisconnect: (void(^)(NSError *_Nullable error))  completionHandler

Queues a request to disconnect the peripheral.

Note
The request being queued, it is processed only when previous requests have completed. For an immediate disconnection first call cancelQueue().
Parameters
completionHandlerThe handler for notifying of the request result.

◆ queueReadRssi:

- (void) queueReadRssi: (void(^)(NSError *_Nullable error))  completionHandler

Queues a request to read the Received Signal Strength Indicator (RSSI).

Parameters
completionHandlerThe handler for notifying of the read RSSI and the request status..

◆ queueReadValueForCharacteristic:valueReadHandler:

- (void) queueReadValueForCharacteristic: (CBCharacteristic *)  characteristic
valueReadHandler: (void(^)(SGBlePeripheralQueue *peripheralQueue, CBCharacteristic *characteristic, NSError *_Nullable error))  valueReadHandler 

Queues a request to read the value of the specified service's characteristic.

The call fails if the characteristic is not readable.

Parameters
characteristicThe CBCharacteristic object.
valueReadHandlerThe handler for notifying of the read value and the request status.

◆ queueSetNotifyValueForCharacteristic:valueChangedHandler:completionHandler:

- (void) queueSetNotifyValueForCharacteristic: (CBCharacteristic *)  characteristic
valueChangedHandler: (void(^)(SGBlePeripheralQueue *peripheralQueue, CBCharacteristic *characteristic, NSError *_Nullable error))  valueChangedHandler
completionHandler: (void(^)(NSError *_Nullable error))  completionHandler 

Queues a request to enable or disable notifications for the specified service's characteristic.

Replaces a previously registered value change handler. The call fails if the characteristic doesn't support notifications.

Parameters
characteristicThe CBCharacteristic object.
valueChangedHandlerThe handler for notifying of the characteristic's value changes.
completionHandlerThe handler for notifying of the request result.

◆ queueWriteValue:forCharacteristic:type:completionHandler:

- (void) queueWriteValue: (NSData *)  data
forCharacteristic: (CBCharacteristic *)  characteristic
type: (CBCharacteristicWriteType)  type
completionHandler: (void(^)(NSError *_Nullable error))  completionHandler 

Queues a request to write the value of specified service's characteristic.

The call fails if the characteristic is not writable.

Parameters
dataThe data to write (may be empty but not nil).
characteristicThe CBCharacteristic object.
typeThe write type to perform.
completionHandlerThe handler for notifying of the request result.

The documentation for this class was generated from the following files: