start method

Future<void> start(
  1. int sampleRate,
  2. List<int> channels, {
  3. bool simulated = false,
})

Starts a signal acquisition from the device.

Parameters

sample_rate : int Sampling rate in Hz. Accepted values are 1, 10, 100 or 1000 Hz. channels : List<int> Set of channels to acquire. Accepted channels are 1...6 for inputs A1...A6. file_name : String Name of the file where the live mode data will be written into. simulated : bool If true, start in simulated mode. Otherwise start in live mode. Default is to start in live mode. api : int The API mode, this API supports the ScientISST and JSON APIs.

Returns

void

Exceptions

DEVICE_NOT_IDLE : if the device is already in acquisition mode. INVALID_PARAMETER : if no valid API value is chosen or an incorrect array of channels is provided.

Implementation

Future<void> start(int sampleRate, List<int> channels,
    {bool simulated = false}) async {
  if (_numChs != 0) throw SenseException(SenseErrorType.DEVICE_NOT_IDLE);

  _sampleRate = sampleRate;
  _numChs = 0;

  // Set API mode
  await _changeAPI(this._apiMode);

  // Sample rate
  int sr = int.parse("01000011", radix: 2);
  sr |= _sampleRate << 8;
  await _send(sr, 4);

  int chMask;
  if (channels.isEmpty) {
    // all 8 analog channels
    chMask = 0xFF;
  } else {
    chMask = 0;
    for (int ch in channels) {
      if (ch <= 0 || ch > 8)
        throw SenseException(SenseErrorType.INVALID_PARAMETER);

      // fill chs vector
      _chs[_numChs] = ch;

      final mask = 1 << (ch - 1);
      if (chMask & mask == 1)
        throw SenseException(SenseErrorType.INVALID_PARAMETER);
      chMask |= mask;
      _numChs++;
    }
  }

  // cleanup existing data in bluetooth buffer
  _clear();

  int cmd;

  if (simulated)
    cmd = 0x02;
  else
    cmd = 0x01;

  cmd |= chMask << 8;

  await _send(cmd);

  _packetSize = await _getPacketSize();
  acquiring = true;
}