/// <inheritdoc/> public void Dispose() { if (_shouldDispose) { _i2cBus?.Dispose(); } else { _ledMatrix?.Dispose(); _ledMatrix = null !; _joystick?.Dispose(); _joystick = null !; _gyro?.Dispose(); _gyro = null !; _mag?.Dispose(); _mag = null !; _temp?.Dispose(); _temp = null !; _press?.Dispose(); _press = null !; } _i2cBus = null !; }
/// <summary> /// Constructs SenseHat instance /// </summary> public SenseHat() { _ledMatrix = new SenseHatLedMatrixI2c(); _joystick = new SenseHatJoystick(); _gyro = new SenseHatAccelerometerAndGyroscope(); _mag = new SenseHatMagnetometer(); _temp = new SenseHatTemperatureAndHumidity(); _press = new SenseHatPressureAndTemperature(); }
/// <summary> /// Constructs SenseHat instance /// </summary> public SenseHat(I2cBus?i2cBus = null, bool shouldDispose = false) { _shouldDispose = shouldDispose || i2cBus == null; _i2cBus = i2cBus ?? I2cBus.Create(DefaultI2cBusId); Debug.Assert(SenseHatLedMatrixI2c.I2cAddress == SenseHatJoystick.I2cAddress, $"Default addresses for {nameof(SenseHatLedMatrixI2c)} and {nameof(SenseHatJoystick)} were expected to be the same"); I2cDevice joystickAndLedMatrixI2cDevice = _i2cBus.CreateDevice(SenseHatLedMatrixI2c.I2cAddress); _ledMatrix = new SenseHatLedMatrixI2c(joystickAndLedMatrixI2cDevice); _joystick = new SenseHatJoystick(joystickAndLedMatrixI2cDevice); _gyro = new SenseHatAccelerometerAndGyroscope(_i2cBus.CreateDevice(SenseHatAccelerometerAndGyroscope.I2cAddress)); _mag = new SenseHatMagnetometer(_i2cBus.CreateDevice(SenseHatMagnetometer.I2cAddress)); _temp = new SenseHatTemperatureAndHumidity(_i2cBus.CreateDevice(SenseHatTemperatureAndHumidity.I2cAddress)); _press = new SenseHatPressureAndTemperature(_i2cBus.CreateDevice(SenseHatPressureAndTemperature.I2cAddress)); }
/// <inheritdoc/> public void Dispose() { _ledMatrix?.Dispose(); _ledMatrix = null; _joystick?.Dispose(); _joystick = null; _gyro?.Dispose(); _gyro = null; _mag?.Dispose(); _mag = null; _temp?.Dispose(); _temp = null; _press?.Dispose(); _press = null; }