Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
SGBlePeripheralQueue.h
Go to the documentation of this file.
1
6#ifndef SGBlePeripheralQueue_h
7#define SGBlePeripheralQueue_h
8
9#import <Foundation/Foundation.h>
10#import <CoreBluetooth/CoreBluetooth.h>
12#import "SGBleTypes.h"
13#import "SGBleRequest.h"
14
15NS_ASSUME_NONNULL_BEGIN
16
44@interface SGBlePeripheralQueue : NSObject<CBPeripheralDelegate>
46{
47 dispatch_queue_t _queue; // Run all peripheral requests
48 SGBleCentralManagerDelegate *_centralDelegate;
49 CBPeripheral *_peripheral;
50
51 // Connection
52 NSArray<CBUUID *> *_requiredServices;
53 NSUInteger _discoveringServicesCounter;
54 SGBleConnectionEventReason _disconnectReason;
55
56 // Last RSSI
57 int _rssi;
58
59 // Requests
60 SGBleRequest *_runningRequest; // Accessed only from queue
61 NSMutableArray<SGBleRequest *> *_pendingRequests; // Always synchronize access to this list
62
63 // Read notifications
65 NSMapTable<CBCharacteristic *, SGBleCharacteristicValueEventHandler> *_valueChangedHandlers;
66}
67
68// Property getters
69- (CBPeripheral *)peripheral;
70- (bool)isConnected;
71- (int)rssi;
73
77@property(readonly, getter=peripheral) CBPeripheral *peripheral;
78
82@property(assign) bool isReady;
83
87@property(readonly, getter=rssi) int rssi;
88
92@property(strong) void (^ _Nullable connectionEventHandler)(SGBlePeripheralQueue *peripheralQueue, SGBleConnectionEvent connectionEvent, SGBleConnectionEventReason reason);
93
96
105- (instancetype)initWithPeripheral:(CBPeripheral *)peripheral
106 centralManagerDelegate:(SGBleCentralManagerDelegate *)centralManagerDelegate;
107
111
121- (void)queueConnectWithServices:(NSArray<CBUUID *> *)services
122 completionHandler:(void (^)(NSError * _Nullable error))completionHandler;
123
132- (void)queueDisconnect:(void (^)(NSError * _Nullable error))completionHandler;
133
138
144- (void)queueReadRssi:(void (^)(NSError * _Nullable error))completionHandler;
145
150
159- (void)queueReadValueForCharacteristic:(CBCharacteristic *)characteristic
160 valueReadHandler:(void (^)(SGBlePeripheralQueue *peripheralQueue, CBCharacteristic *characteristic, NSError *_Nullable error))valueReadHandler;
161
172- (void)queueWriteValue:(NSData *)data
173 forCharacteristic:(CBCharacteristic *)characteristic
174 type:(CBCharacteristicWriteType)type
175 completionHandler:(void (^)(NSError * _Nullable error))completionHandler;
176
187- (void)queueSetNotifyValueForCharacteristic:(CBCharacteristic *)characteristic
188 valueChangedHandler:(void (^ _Nullable)(SGBlePeripheralQueue *peripheralQueue, CBCharacteristic *characteristic, NSError * _Nullable error))valueChangedHandler
189 completionHandler:(void (^)(NSError * _Nullable error))completionHandler;
190
194
198- (void)cancelAll;
199
201
202@end
203
204NS_ASSUME_NONNULL_END
205
206#endif /* SGBlePeripheralQueue_h */
Definition of the SGBleCentralManagerDelegate class.
Internal types for representing a BLE request.
Definition of SGBleConnectionEvent and SGBleConnectionEventReason enumerations.
void(^ SGBleCharacteristicValueEventHandler)(SGBlePeripheralQueue *_Nonnull peripheralQueue, CBCharacteristic *_Nonnull characteristic, NSError *_Nullable error)
Peripheral connection event handler.
Definition SGBleTypes.h:142
Implementation of CBCentralManagerDelegate protocol. Stores and notifies of discovered Bluetooth Low ...
Definition SGBleCentralManagerDelegate.h:29
Implementation of the CBPeripheralDelegate protocol. Queues up operations to be performed with a Blue...
Definition SGBlePeripheralQueue.h:44
int rssi
Gets the last read value of the Received Signal Strength Indicator (RSSI).
Definition SGBlePeripheralQueue.h:87
CBPeripheral * peripheral
Gets the CBPeripheral object for this peripheral.
Definition SGBlePeripheralQueue.h:77
Internal type, represents a Bluetooth operation to be performed on a peripheral. Used by SGBlePeriphe...
Definition SGBleRequest.h:47