Bluetooth
Servo-specific APIs to access Bluetooth devices.
Bluetooth related code is located in bluetooth.rs.
Implementation
Underlying dependency crates:
- Android platform: blurdroid
- Linux platform: blurz
- macOS platform: blurmac
Fakeprefixed structures: blurmock
Empty prefixed structures are located in empty.rs.
Usage
Without the bluetooth-test feature
There are three supported platforms (Android, Linux, macOS), on other platforms we fall back to a default (Empty prefixed) implementation. Each enum (BluetoothAdapter, BluetoothDevice, etc.) will contain only one variant for each targeted platform. See the following BluetoothAdapter example:
Android:
Linux:
macOS:
Unsupported platforms:
You will have a platform specific adapter, e.g. on Android target, BluetoothAdapter::init() will create a BluetoothAdapter::Android enum variant, which wraps an Arc<BluetoothAdapterAndroid>.
On each platform you can call the same functions to reach the same GATT hierarchy elements. The following code can access the same Bluetooth device on all supported platforms:
use ;
With the bluetooth-test feature
Each enum (BluetoothAdapter, BluetoothDevice, etc.) will contain one variant of the three possible default target, and a Mock variant, which wraps a Fake structure.
Android:
Linux:
macOS:
Unsupported platforms:
Beside the platform specific structures, you can create and access mock adapters, devices, services etc. These mock structures implements all the platform specific functions too. To create a mock GATT hierarchy, first you need to call the BluetoothAdapter::init_mock() function, insted of BluetoothAdapter::init().
use ;
use String;
// This function takes a BluetoothAdapter,
// and print the ids of the devices, which the adapter can find.
Calling a test function on a not Mock structure, will result an error with the message: Error! Test functions are not supported on real devices!.