Max30101 constructor

Max30101(
  1. I2CWrapper wrapper,
  2. bool captureSamples, {
  3. double ledPower = 6.4,
  4. int ledsEnabled = 2,
  5. int sampleRate = 100,
  6. int sampleAverage = 1,
  7. int pulseWidth = 411,
  8. int adcRange = 16384,
  9. bool highResMode = true,
  10. bool debug = true,
})

Check table 8 in datasheet on page 19. You can't just throw in sample rate and pulse width randomly. 100hz + 1600us is max for that resolution device is injectable so you can inject mocks / whatever for testing purposes

Implementation

Max30101(this.wrapper, this.captureSamples,
    {this.ledPower = 6.4,
    this.ledsEnabled = 2,
    this.sampleRate = 100,
    this.sampleAverage = 1,
    this.pulseWidth = 411,
    this.adcRange = 16384,
    this.highResMode = true,
    this.debug = true}) {
  if (captureSamples) {
    captureFile = File('max30101.capture.txt');
  }

  if (ledsEnabled < 2 || ledsEnabled > 3) {
    throw Exception("ledsEnabled must be 2 or 3. Preferably 2 (Red and InfraRed) because we don't do anything with green anyway");
  }

  _setupRegisters();

  setupDevice(
      ledPower: ledPower,
      sampleAverage: sampleAverage,
      ledsEnabled: ledsEnabled,
      sampleRate: sampleRate,
      pulseWidth: pulseWidth,
      adcRange: adcRange,
      timeoutMillis: 500);

  dcFilterIR.w = 0;
  dcFilterIR.result = 0;

  dcFilterRed.w = 0;
  dcFilterRed.result = 0;

  lpbFilterIR.v[0] = 0;
  lpbFilterIR.v[1] = 0;
  lpbFilterIR.result = 0;

  meanDiffIR.index = 0;
  meanDiffIR.sum = 0;
  meanDiffIR.count = 0;

  valuesBPM[0] = 0;
  valuesBPMSum = 0;
  valuesBPMCount = 0;
  bpmIndex = 0;

  irACValueSqSum = 0;
  redACValueSqSum = 0;
  samplesRecorded = 0;
  pulsesDetected = 0;
  currentSaO2Value = 0;

  lastBeatThreshold = 0;
}