Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
|
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>
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. | |
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.
- (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.
peripheral | The CBPeripheral object for the BLE peripheral. |
centralManagerDelegate | The instance of SGBleCentralManagerDelegate that discovered the peripheral. |
- (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.
services | List of services UUIDs that the peripheral should support, may be null or empty. |
completionHandler | The handler for notifying of the request result. |
- (void) queueDisconnect: | (void(^)(NSError *_Nullable error)) | completionHandler |
Queues a request to disconnect the peripheral.
completionHandler | The handler for notifying of the request result. |
- (void) queueReadRssi: | (void(^)(NSError *_Nullable error)) | completionHandler |
Queues a request to read the Received Signal Strength Indicator (RSSI).
completionHandler | The handler for notifying of the read RSSI and the request status.. |
- (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.
characteristic | The CBCharacteristic object. |
valueReadHandler | The handler for notifying of the read value and the request status. |
- (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.
characteristic | The CBCharacteristic object. |
valueChangedHandler | The handler for notifying of the characteristic's value changes. |
completionHandler | The handler for notifying of the request result. |
- (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.
data | The data to write (may be empty but not nil). |
characteristic | The CBCharacteristic object. |
type | The write type to perform. |
completionHandler | The handler for notifying of the request result. |