Pixels Plugin for Unity
Enable communications with Pixels dice using Bluetooth Low Energy.
|
C library for discovering, connecting to, and interacting with Bluetooth Low Energy (BLE) peripherals on iOS. More...
Functions | |
Library life cycle | |
bool | sgBleInitialize (BluetoothStateUpdateCallback onBluetoothEvent) |
Initializes the library for accessing BLE peripherals. | |
void | sgBleShutdown () |
Shuts down the library. | |
Peripherals scanning | |
bool | sgBleStartScan (const char *servicesUuids, bool allowDuplicates, DiscoveredPeripheralCallback onDiscoveredPeripheral) |
Starts scanning for BLE peripherals advertising the given list of services. | |
void | sgBleStopScan () |
Stops an on-going BLE scan. | |
Peripherals life cycle | |
bool | sgBleCreatePeripheral (peripheral_id_t peripheralId, PeripheralConnectionEventCallback onPeripheralConnectionEvent, request_index_t requestIndex) |
Creates a Peripheral for the BLE peripheral with the given Bluetooth address. | |
void | sgBleReleasePeripheral (peripheral_id_t peripheralId) |
Releases the Peripheral object associated with the given peripheral id. | |
Peripheral connection and disconnection | |
void | sgBleConnectPeripheral (peripheral_id_t peripheralId, const char *requiredServicesUuids, RequestStatusCallback onRequestStatus, request_index_t requestIndex) |
Connects to the given peripheral. | |
void | sgBleDisconnectPeripheral (peripheral_id_t peripheralId, RequestStatusCallback onRequestStatus, request_index_t requestIndex) |
Disconnects the given peripheral. | |
Peripheral operations | |
Valid only for connected peripherals. | |
const char * | sgBleGetPeripheralName (peripheral_id_t peripheralId) |
Gets the name of the given peripheral. | |
int | sgBleGetPeripheralMtu (peripheral_id_t peripheralId) |
Gets the Maximum Transmission Unit (MTU) for the given peripheral. | |
void | sgBleReadPeripheralRssi (peripheral_id_t peripheralId, RssiReadCallback onRssiRead, request_index_t requestIndex) |
Reads the Received Signal Strength Indicator (RSSI) of the given peripheral. | |
Services operations | |
Valid only for ready peripherals. | |
const char * | sgBleGetDiscoveredServices (peripheral_id_t peripheralId) |
Gets the list of discovered services for the given peripheral. | |
const char * | sgBleGetServiceCharacteristics (peripheral_id_t peripheralId, const char *serviceUuid) |
Gets the list of discovered characteristics for the given peripheral's service. | |
Characteristics operations | |
Valid only for connected peripherals. | |
characteristic_property_t | sgBleGetCharacteristicProperties (peripheral_id_t peripheralId, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex) |
Gets the standard BLE properties of the specified service's characteristic for the given peripheral. | |
void | sgBleReadCharacteristic (peripheral_id_t peripheralId, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex, ValueReadCallback onValueRead, request_index_t requestIndex) |
Sends a request to read the value of the specified service's characteristic for the given peripheral. | |
void | sgBleWriteCharacteristic (peripheral_id_t peripheralId, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex, const void *data, const size_t length, bool withoutResponse, RequestStatusCallback onRequestStatus, request_index_t requestIndex) |
Sends a request to write to the specified service's characteristic for the given peripheral. | |
void | sgBleSetNotifyCharacteristic (peripheral_id_t peripheralId, const char *serviceUuid, const char *characteristicUuid, characteristic_index_t instanceIndex, ValueReadCallback onValueChanged, RequestStatusCallback onRequestStatus, request_index_t requestIndex) |
Subscribes or unsubscribes for value changes of the specified service's characteristic for the given peripheral. | |
C library for discovering, connecting to, and interacting with Bluetooth Low Energy (BLE) peripherals on iOS.
void sgBleConnectPeripheral | ( | peripheral_id_t | peripheralId, |
const char * | requiredServicesUuids, | ||
RequestStatusCallback | onRequestStatus, | ||
request_index_t | requestIndex | ||
) |
Connects to the given peripheral.
This request never timeouts.
peripheralId | The UUID assigned by the system for the peripheral. |
requiredServicesUuids | Comma separated list of services UUIDs that the peripheral should support, may be null or empty. |
onRequestStatus | Called when the request has completed (successfully or not). |
requestIndex | The index of this request, passed back when calling onRequestStatus . |
bool sgBleCreatePeripheral | ( | peripheral_id_t | peripheralId, |
PeripheralConnectionEventCallback | onPeripheralConnectionEvent, | ||
request_index_t | requestIndex | ||
) |
Creates a Peripheral for the BLE peripheral with the given Bluetooth address.
The underlying object is not returned, instead the peripheral must be referenced by its peripheral id. Call sgBleReleasePeripheral() to destroy the object.
A scan must first be run to discover available BLE peripherals through their advertisement data. The later includes the peripheral system id, a UUID assigned by the system.
peripheralId | The UUID assigned by the system for the peripheral. |
onPeripheralConnectionEvent | Called when the peripheral connection state changes. The callback must stay valid until the peripheral is released. |
requestIndex | The index of this request, passed back when calling onPeripheralConnectionEvent . |
void sgBleDisconnectPeripheral | ( | peripheral_id_t | peripheralId, |
RequestStatusCallback | onRequestStatus, | ||
request_index_t | requestIndex | ||
) |
Disconnects the given peripheral.
peripheralId | The UUID assigned by the system for the peripheral. |
onRequestStatus | Called when the request has completed (successfully or not). |
requestIndex | The index of this request, passed back when calling onRequestStatus . |
characteristic_property_t sgBleGetCharacteristicProperties | ( | peripheral_id_t | peripheralId, |
const char * | serviceUuid, | ||
const char * | characteristicUuid, | ||
characteristic_index_t | instanceIndex | ||
) |
Gets the standard BLE properties of the specified service's characteristic for the given peripheral.
peripheralId | The UUID assigned by the system for the peripheral. |
serviceUuid | The service UUID. |
characteristicUuid | The characteristic UUID. |
instanceIndex | The instance index of the characteristic if listed more than once for the service, otherwise zero. |
const char * sgBleGetDiscoveredServices | ( | peripheral_id_t | peripheralId | ) |
Gets the list of discovered services for the given peripheral.
peripheralId | The UUID assigned by the system for the peripheral. |
int sgBleGetPeripheralMtu | ( | peripheral_id_t | peripheralId | ) |
Gets the Maximum Transmission Unit (MTU) for the given peripheral.
peripheralId | The UUID assigned by the system for the peripheral. |
const char * sgBleGetPeripheralName | ( | peripheral_id_t | peripheralId | ) |
Gets the name of the given peripheral.
peripheralId | The UUID assigned by the system for the peripheral. |
const char * sgBleGetServiceCharacteristics | ( | peripheral_id_t | peripheralId, |
const char * | serviceUuid | ||
) |
Gets the list of discovered characteristics for the given peripheral's service.
The same characteristic may be listed several times according to the peripheral's configuration.
peripheralId | The UUID assigned by the system for the peripheral. |
serviceUuid | The service UUID for which to retrieve the characteristics. |
bool sgBleInitialize | ( | BluetoothStateUpdateCallback | onBluetoothEvent | ) |
Initializes the library for accessing BLE peripherals.
onBluetoothEvent | Called when the host device Bluetooth state changes. |
void sgBleReadCharacteristic | ( | peripheral_id_t | peripheralId, |
const char * | serviceUuid, | ||
const char * | characteristicUuid, | ||
characteristic_index_t | instanceIndex, | ||
ValueReadCallback | onValueRead, | ||
request_index_t | requestIndex | ||
) |
Sends a request to read the value of the specified service's characteristic for the given peripheral.
The call fails if the characteristic is not readable.
peripheralId | The UUID assigned by the system for the peripheral. |
serviceUuid | The service UUID. |
characteristicUuid | The characteristic UUID. |
instanceIndex | The instance index of the characteristic if listed more than once for the service, otherwise zero. |
onValueRead | Called when the request has completed (successfully or not) and with the data read from the characteristic. |
requestIndex | The index of this request, passed back when calling onRequestStatus . |
void sgBleReadPeripheralRssi | ( | peripheral_id_t | peripheralId, |
RssiReadCallback | onRssiRead, | ||
request_index_t | requestIndex | ||
) |
Reads the Received Signal Strength Indicator (RSSI) of the given peripheral.
peripheralId | The UUID assigned by the system for the peripheral. |
onRssiRead | Called with the read RSSI. |
requestIndex | The index of this request, passed back when calling onRssiRead . |
void sgBleReleasePeripheral | ( | peripheral_id_t | peripheralId | ) |
Releases the Peripheral object associated with the given peripheral id.
peripheralId | The UUID assigned by the system for the peripheral. |
void sgBleSetNotifyCharacteristic | ( | peripheral_id_t | peripheralId, |
const char * | serviceUuid, | ||
const char * | characteristicUuid, | ||
characteristic_index_t | instanceIndex, | ||
ValueReadCallback | onValueChanged, | ||
RequestStatusCallback | onRequestStatus, | ||
request_index_t | requestIndex | ||
) |
Subscribes or unsubscribes for value changes of the specified service's characteristic for the given peripheral.
Replaces a previously registered value change handler for the same characteristic. The call fails if the characteristic doesn't support notifications.
peripheralId | The UUID assigned by the system for the peripheral. |
serviceUuid | The service UUID. |
characteristicUuid | The characteristic UUID. |
instanceIndex | The instance index of the characteristic if listed more than once for the service, otherwise zero. |
onValueChanged | Called when the value of the characteristic changes. Pass null to unsubscribe. The callback must stay valid until the characteristic is unsubscribed or the peripheral is released. |
onRequestStatus | Called when the request has completed (successfully or not). |
requestIndex | The index of this request, passed back when calling onRequestStatus . |
void sgBleShutdown | ( | ) |
Shuts down the library.
Scanning is stopped and all peripherals are disconnected and removed.
bool sgBleStartScan | ( | const char * | servicesUuids, |
bool | allowDuplicates, | ||
DiscoveredPeripheralCallback | onDiscoveredPeripheral | ||
) |
Starts scanning for BLE peripherals advertising the given list of services.
If a scan is already running, it is updated to run with the new parameters.
servicesUuids | Comma separated list of services UUIDs. Peripherals advertising at least one of the services will be reported. Notify for all peripherals if the list is null or empty. |
allowDuplicates | If false , let the system coalesces multiple discoveries of the same peripheral into a single discovery event which preserves battery life. If true , generates a discovery event each time it receives an advertising packet from the peripheral |
onDiscoveredPeripheral | Called every time an advertisement packet with the required services is received. The advertisement data is passed as a JSON string. The callback must stay valid until the scan is stopped. |
void sgBleWriteCharacteristic | ( | peripheral_id_t | peripheralId, |
const char * | serviceUuid, | ||
const char * | characteristicUuid, | ||
characteristic_index_t | instanceIndex, | ||
const void * | data, | ||
const size_t | length, | ||
bool | withoutResponse, | ||
RequestStatusCallback | onRequestStatus, | ||
request_index_t | requestIndex | ||
) |
Sends a request to write to the specified service's characteristic for the given peripheral.
The call fails if the characteristic is not writable.
peripheralId | The UUID assigned by the system for the peripheral. |
serviceUuid | The service UUID. |
characteristicUuid | The characteristic UUID. |
instanceIndex | The instance index of the characteristic if listed more than once for the service, otherwise zero. |
data | A pointer to the data to write to the characteristic (may be null if length is zero). |
length | The size in bytes of the data. |
withoutResponse | Whether to wait for the peripheral to respond. |
onRequestStatus | Called when the request has completed (successfully or not). |
requestIndex | The index of this request, passed back when calling onRequestStatus . |