GestureSensor constructor

GestureSensor(
  1. I2C i2c, [
  2. int gestureReactionTime = _gestureReactionTime,
  3. int gestureQuitTime = _gestureQuitTime
])

Creates a PAJ7620U2 sensor instance that uses i2c bus with the optional parameter gestureReactionTime and gestureQuitTime.

Implementation

GestureSensor(this.i2c,
    [this.gestureReactionTime = _gestureReactionTime,
    this.gestureQuitTime = _gestureQuitTime]) {
  var data0 = 0;

  // At the first access Raspberry PI 3 runs into a timeout - sensor is still sleeping
  try {
    data0 = i2c.readByteReg(paj7620Id, 0);
  } on I2Cexception catch (e) {
    if (e.errorCode == I2CerrorCode.i2cErrorTransfer) {
      sleep(Duration(milliseconds: 10));
      // sensor should be up at this point!
      data0 = i2c.readByteReg(paj7620Id, 0);
    }
  }

  var data1 = i2c.readByteReg(paj7620Id, 1);

  if ((data0 != 0x20) || (data1 != 0x76)) {
    throw GestureSensorException(
        'Bad init data 0x${data0.toRadixString(16)}  != 0x20 and 0x${data1.toRadixString(16)} != 0x76');
  }

  _paj7620SelectBank(Bank.bank0);

  for (var v in initRegisterArray) {
    i2c.writeByteReg(paj7620Id, v >> 8, v & 0xff);
  }

  _paj7620SelectBank(Bank.bank1);
  i2c.writeByteReg(paj7620Id, 0x65, 0x12);
  _paj7620SelectBank(Bank.bank0);
}