setDigitalOutputs method
Assigns the digital output states.
Returns true
if the command is sent successfully, false
otherwise.
An array with the digital channels to enable set as 1, and the digital channels to disable set as 0.
Throws BITalinoException(BITalinoErrorType.INVALID_DIGITAL_CHANNELS) if the digital channels array is invalid. Throws BITalinoException(BITalinoErrorType.TIMEOUT) if the timeout limit is reached. Throws BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED) if a device is not connected. Throws BITalinoException(BITalinoErrorType.BT_DEVICE_CANNOT_BE_RECORDING) if the device is recording. Throws BITalinoException(BITalinoErrorType.CUSTOM) if a native exception was raised.
Implementation
Future<bool> setDigitalOutputs(List<int> digitalChannels) async {
if (digitalChannels.length > 4)
throw BITalinoException(BITalinoErrorType.INVALID_DIGITAL_CHANNELS);
if (digitalChannels.length != 4 &&
!(digitalChannels.length == 2 &&
Platform.isAndroid &&
await isBITalino2()))
throw BITalinoException(BITalinoErrorType.INVALID_DIGITAL_CHANNELS);
if (!connected)
throw BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED);
if (recording)
throw BITalinoException(BITalinoErrorType.BT_DEVICE_CANNOT_BE_RECORDING);
try {
return await (_channel.invokeMethod("trigger", <String, dynamic>{
"digitalChannels": serializeChannels(digitalChannels),
}).timeout(timeout) as FutureOr<bool>);
} on TimeoutException {
throw BITalinoException(BITalinoErrorType.TIMEOUT);
} catch (e) {
throw BITalinoException(BITalinoErrorType.CUSTOM, e.toString());
}
}