API Topic
API
A more complete example can be found in the example subdirectory. A quick overview is provided below.
Getting Started
Using this library involves a few steps.
- Initialize the IHubScanner
The factory method abstracts any platform dependent backend from your code. Currently it only supports iOS and Android.
final IHubScanner scanner = IHubScanner.factory();
- Register for Hub Notifications
This is the mechanism to get notified when a hub is added or removed from the hubList.
scanner.stream.listen((HubList hubList) async {
if (hubList.length < 0) {
return;
}
bool success = await hub[0].connect();
// implemented a bit further down.
newHubFound(hub);
- Start Scanning for Hubs
You'll need to tell the library to actually start looking for hubs.
_scanner.startScanning();
- Implement newHubFound(hub)
Discover all the peripherals on the hub.
void newHubFound(Hub hub) {
hub.hubStateStream.listen((HubState state) async {
print(state.peripherals);
// do something with these peripherals!
});
}
- Perform an operation on peripheral
Once you have your peripherals you can make them do something!
(state.peripherals[0] as MotorPeripheral).startSpeed(100, 50, MotorAccelerationProfile.None);
Classes
- AccelerationPeripheral API
- AccelerationPeripheral class using AccelerationInput mixin.
- CurrentPeripheral API
- CurrentPeripheral class using CurrentInput mixin.
- GesturePeripheral API
- GesturePeripheral class using GestureInput mixin.
- GyroPeripheral API
- GyroPeripheral class using GyroInput mixin.
- Hub API
- The main hub interaction class.
- HubState API
- HubState contains the state of the hub This includes which peripherals are attached and if the hub is currently connected.
- HubStatusLightPeripheral API
- HubPeripheral class using Led mixin.
- IHubScanner API
- The main class used to discover hubs.
- MotorPeripheral API
- MotorPeripheral class using Motor mixin.
- OrientationPeripheral API
- OrientationPeripheral class using OrientationInput mixin.
- Peripheral API
- Master Peripheral class. [...]
- PeripheralMode API
- Mode container
- PeripheralModeRange API
- Range container.
- RetryException API
- If a transaction has failed and should retry, throw RetryException inside the transaction. The Transaction class will retry Transaction.maxTries number of times.
-
SimpleTransaction<
T> API - Simple transaction provides an easy way to interact with the Hub using the request/response pattern with retries. [...]
- TemperaturePeripheral API
- TemperaturePeripheral class using TemperatureInput mixin.
-
Transaction<
T> API - transactions are used to facilitate communications with the hub. [...]
- VoltagePeripheral API
- VoltagePeripheral class using VoltageInput mixin.
Mixins
- AccelerationInput API
- Acceleration input for Peripherals.
- CurrentInput API
- Current input for Peripherals.
- GestureInput API
- Gesture input for Peripherals.
- GyroInput API
- Gyro input for Peripherals.
- Led API
- LED actions for Peripherals.
- Motor API
- Motor actions for Peripherals.
- OrientationInput API
- Orientation input for Peripherals.
- TemperatureInput API
- Temperature input for Peripherals.
- VoltageInput API
- Voltage input for Peripherals.