start method

Future<bool> start(
  1. List<int> analogChannels,
  2. Frequency sampleRate, {
  3. int numberOfSamples = 50,
  4. OnBITalinoDataAvailable? onDataAvailable,
})

Starts recording on the connected bluetooth device. Returns true if the acquisition started successfully, false otherwise.

analogChannels is a List<int> of the active analog channels. While recording, the OnBITalinoDataAvailable callback is called. On IOS, the numberOfSamples per chunk of data received must be provided.

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.CUSTOM) if a native exception was raised. Throws BITalinoException(BITalinoErrorType.BT_DEVICE_ALREADY_RECORDING) if the connected bluetooth device is already recording. Throws BITalinoException(BITalinoErrorType.BT_DEVICE_BTH) if CommunicationType.BTH is not selected.

Implementation

Future<bool> start(List<int> analogChannels, Frequency sampleRate,
    {int numberOfSamples = 50,
    OnBITalinoDataAvailable? onDataAvailable}) async {
  if (Platform.isIOS && numberOfSamples <= 0)
    throw BITalinoException(BITalinoErrorType.MISSING_PARAMETER);
  if (!connected)
    throw BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED);
  if (recording)
    throw BITalinoException(BITalinoErrorType.BT_DEVICE_ALREADY_RECORDING);

  _onBITalinoDataAvailable = onDataAvailable;
  try {
    if (Platform.isAndroid) {
      recording = await _channel.invokeMethod("start", <String, dynamic>{
        "analogChannels": serializeChannels(analogChannels),
        "sampleRate": serializeFrequency(sampleRate),
      }).timeout(timeout);
    } else if (Platform.isIOS) {
      recording = await _channel.invokeMethod("start", <String, dynamic>{
        "analogChannels": serializeChannels(analogChannels),
        "sampleRate": serializeFrequency(sampleRate),
        "numberOfSamples": numberOfSamples,
      }).timeout(timeout);
    }
    return recording;
  } on TimeoutException {
    throw BITalinoException(BITalinoErrorType.TIMEOUT);
  } catch (e) {
    throw BITalinoException(BITalinoErrorType.CUSTOM, e.toString());
  }
}