Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
cble.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <cstdint>
17#include "bletypes.h"
18
20#ifdef LIBWINRTBLE_EXPORTS
21#define DLL_DECLSPEC __declspec(dllexport)
22#else
23#define DLL_DECLSPEC __declspec(dllimport)
24#endif
29
32
35
38
41
43using characteristic_index_t = std::uint32_t;
44
47
49typedef void (*DiscoveredPeripheralCallback)(const char* advertisementDataJson);
50
53
56
58typedef void (*ValueReadCallback)(const void* data, size_t length, BleRequestStatus status);
59
61typedef void (*ValueChangedCallback)(const void* data, size_t length);
62
63extern "C"
64{
67
DLL_DECLSPEC
77 bool sgBleInitialize(bool apartmentSingleThreaded, BluetoothStateUpdateCallback onCentralStateUpdate);
78
DLL_DECLSPEC
85 void sgBleShutdown();
86
90
DLL_DECLSPEC
105 bool sgBleStartScan(
106 const char* requiredServicesUuids,
107 DiscoveredPeripheralCallback onDiscoveredPeripheral);
108
DLL_DECLSPEC
113 void sgBleStopScan();
114
118
DLL_DECLSPEC
135 bluetooth_address_t address,
136 PeripheralConnectionEventCallback onPeripheralConnectionEvent);
137
DLL_DECLSPEC
145
149
DLL_DECLSPEC
166 const char* requiredServicesUuids,
167 bool autoReconnect,
168 RequestStatusCallback onRequestStatus);
169
DLL_DECLSPEC
180 bluetooth_address_t address,
181 RequestStatusCallback onRequestStatus);
182
187
DLL_DECLSPEC
199 const char* sgBleGetPeripheralName(bluetooth_address_t address);
200
DLL_DECLSPEC
209
214
DLL_DECLSPEC
227
DLL_DECLSPEC
243 bluetooth_address_t address,
244 const char* serviceUuid);
245
250
DLL_DECLSPEC
265 bluetooth_address_t address,
266 const char* serviceUuid,
267 const char* characteristicUuid,
268 characteristic_index_t instanceIndex);
269
DLL_DECLSPEC
287 bluetooth_address_t address,
288 const char* serviceUuid,
289 const char* characteristicUuid,
290 characteristic_index_t instanceIndex,
291 ValueReadCallback onValueRead);
292
DLL_DECLSPEC
312 bluetooth_address_t address,
313 const char* serviceUuid,
314 const char* characteristicUuid,
315 characteristic_index_t instanceIndex,
316 const void* data,
317 const size_t length,
318 bool withoutResponse,
319 RequestStatusCallback onRequestStatus);
320
DLL_DECLSPEC
341 bluetooth_address_t address,
342 const char* serviceUuid,
343 const char* characteristicUuid,
344 characteristic_index_t instanceIndex,
345 ValueChangedCallback onValueChanged,
346 RequestStatusCallback onRequestStatus);
347
351
DLL_DECLSPEC
360 void sgFreeString(char* str);
361
363
364} // extern "C"
std::uint32_t characteristic_index_t
Type for the index of a characteristic instance in a service.
Definition UnityBridge.h:23
Some types used across the Systemic::BluetoothLE library.
bool sgBleStartScan(const char *requiredServicesUuids, DiscoveredPeripheralCallback onDiscoveredPeripheral)
Starts scanning for BLE peripherals advertising the given list of services.
Definition cble.cpp:341
void sgBleConnectPeripheral(bluetooth_address_t address, const char *requiredServicesUuids, bool autoReconnect, RequestStatusCallback onRequestStatus)
Connects to the given peripheral.
Definition cble.cpp:424
void(* RequestStatusCallback)(BleRequestStatus status)
Callback notifying of the status of a BLE request.
Definition cble.h:52
const char * sgBleGetServiceCharacteristics(bluetooth_address_t address, const char *serviceUuid)
Returns the list of discovered characteristics for the given peripheral's service.
Definition cble.cpp:494
void sgBleWriteCharacteristic(bluetooth_address_t address, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex, const void *data, const size_t length, bool withoutResponse, RequestStatusCallback onRequestStatus)
Sends a request to write to the specified service's characteristic for the given peripheral.
Definition cble.cpp:566
void sgBleSetNotifyCharacteristic(bluetooth_address_t address, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex, ValueChangedCallback onValueChanged, RequestStatusCallback onRequestStatus)
Subscribes or unsubscribes for value changes of the specified service's characteristic for the given ...
Definition cble.cpp:596
int sgBleGetPeripheralMtu(bluetooth_address_t address)
Returns the Maximum Transmission Unit (MTU) for the given peripheral.
Definition cble.cpp:464
void sgBleReadCharacteristic(bluetooth_address_t address, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex, ValueReadCallback onValueRead)
Sends a request to read the value of the specified service's characteristic for the given peripheral.
Definition cble.cpp:534
Systemic::BluetoothLE::bluetooth_address_t bluetooth_address_t
Type for a Bluetooth address.
Definition cble.h:28
void(* BluetoothStateUpdateCallback)(Systemic::BluetoothLE::BleAdapterState state)
Callback notifying of a change of the host device Bluetooth state, for example radio turned on or off...
Definition cble.h:46
bool sgBleInitialize(bool apartmentSingleThreaded, BluetoothStateUpdateCallback onCentralStateUpdate)
Initializes the library for accessing BLE peripherals.
Definition cble.cpp:280
void(* DiscoveredPeripheralCallback)(const char *advertisementDataJson)
Callback notifying of the discovery of a BLE peripheral, with its advertisement data as a JSON string...
Definition cble.h:49
bool sgBleCreatePeripheral(bluetooth_address_t address, PeripheralConnectionEventCallback onPeripheralConnectionEvent)
Creates a Peripheral for the BLE peripheral with the given Bluetooth address.
Definition cble.cpp:374
void sgBleReleasePeripheral(bluetooth_address_t address)
Releases the Peripheral object associated with the given Bluetooth address.
Definition cble.cpp:409
void sgFreeString(char *str)
Deallocates a string returned by any of the sgBle* methods.
Definition cble.cpp:628
int sgBleGetCharacteristicProperties(bluetooth_address_t address, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex)
Returns the standard BLE properties of the specified service's characteristic for the given periphera...
Definition cble.cpp:519
void sgBleStopScan()
Stops an on-going BLE scan.
Definition UnityBridge.mm:122
void(* PeripheralConnectionEventCallback)(bluetooth_address_t address, ConnectionEvent connectionEvent, ConnectionEventReason reason)
Callback notifying of a change connection state of a peripheral, with the reason for the change.
Definition cble.h:55
const char * sgBleGetPeripheralName(bluetooth_address_t address)
Returns the name of the given peripheral.
Definition cble.cpp:457
const char * sgBleGetDiscoveredServices(bluetooth_address_t address)
Returns the list of discovered services for the given peripheral.
Definition cble.cpp:473
void sgBleDisconnectPeripheral(bluetooth_address_t address, RequestStatusCallback onRequestStatus)
Immediately disconnects the given peripheral.
Definition cble.cpp:442
void sgBleShutdown()
Shuts down the library.
Definition UnityBridge.mm:68
void(* ValueChangedCallback)(const void *data, size_t length)
Callback notifying of a value change for a peripheral's characteristic.
Definition cble.h:61
void(* ValueReadCallback)(const void *data, size_t length, BleRequestStatus status)
Callback notifying of the value read from a peripheral's characteristic.
Definition cble.h:58
BleAdapterState
Bluetooth adapter states.
Definition bletypes.h:39
std::uint64_t bluetooth_address_t
Type for a Bluetooth address.
Definition bletypes.h:54
BleRequestStatus
Peripheral requests statuses.
Definition bletypes.h:58
CharacteristicProperties
Standard BLE values for characteristic properties, those are flags that can be combined.
Definition bletypes.h:151
ConnectionEvent
Peripheral connection events.
Definition bletypes.h:101
ConnectionEventReason
Peripheral connection event reasons.
Definition bletypes.h:123