setBatteryThreshold method
Sets the battery threshold value of the connected device.
Returns true
if the battery threshold is set successfully, false
otherwise.
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.BAT_THRESHOLD_INVALID) if the battery threshold value is invalid. 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> setBatteryThreshold(int threshold) async {
if (threshold < 0 && threshold > 63)
throw BITalinoException(BITalinoErrorType.BAT_THRESHOLD_INVALID);
if (!connected)
throw BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED);
if (recording)
throw BITalinoException(BITalinoErrorType.BT_DEVICE_CANNOT_BE_RECORDING);
try {
return await (_channel.invokeMethod("batteryThreshold", <String, dynamic>{
"threshold": threshold
}).timeout(timeout) as FutureOr<bool>);
} on TimeoutException {
throw BITalinoException(BITalinoErrorType.TIMEOUT);
} catch (e) {
throw BITalinoException(BITalinoErrorType.CUSTOM, e.toString());
}
}