diff --git a/src/devices/Ads1115/Ads1115.cs b/src/devices/Ads1115/Ads1115.cs index d102a4d5f5..46b9301c12 100644 --- a/src/devices/Ads1115/Ads1115.cs +++ b/src/devices/Ads1115/Ads1115.cs @@ -641,8 +641,9 @@ public void Dispose() if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null; } + + _gpioController = null; } } } diff --git a/src/devices/Ak8963/Ak8963.cs b/src/devices/Ak8963/Ak8963.cs index 74f62f7cee..ced9e46935 100644 --- a/src/devices/Ak8963/Ak8963.cs +++ b/src/devices/Ak8963/Ak8963.cs @@ -345,8 +345,9 @@ public void Dispose() if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } } } diff --git a/src/devices/Blinkt/Blinkt.cs b/src/devices/Blinkt/Blinkt.cs index 3df9f2dc6e..13fdeafb32 100644 --- a/src/devices/Blinkt/Blinkt.cs +++ b/src/devices/Blinkt/Blinkt.cs @@ -73,8 +73,9 @@ public void Dispose() if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null!; } + + _gpioController = null!; } /// diff --git a/src/devices/Bmm150/Bmm150.cs b/src/devices/Bmm150/Bmm150.cs index b19f770a99..b413d61715 100644 --- a/src/devices/Bmm150/Bmm150.cs +++ b/src/devices/Bmm150/Bmm150.cs @@ -266,8 +266,9 @@ public void Dispose() if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } } } diff --git a/src/devices/Bno055/Bno055Sensor.cs b/src/devices/Bno055/Bno055Sensor.cs index 228105134f..5b64583b68 100644 --- a/src/devices/Bno055/Bno055Sensor.cs +++ b/src/devices/Bno055/Bno055Sensor.cs @@ -563,8 +563,9 @@ public void Dispose() if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } private void WriteReg(Registers reg, byte param) => _i2cDevice.Write(new byte[] { (byte)reg, param }); diff --git a/src/devices/Button/GpioButton.cs b/src/devices/Button/GpioButton.cs index 7325e2ef7e..d234fe2c53 100644 --- a/src/devices/Button/GpioButton.cs +++ b/src/devices/Button/GpioButton.cs @@ -152,12 +152,13 @@ protected override void Dispose(bool disposing) if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null!; } else { _gpioController.ClosePin(_buttonPin); } + + _gpioController = null!; } base.Dispose(disposing); diff --git a/src/devices/Ccs811/Ccs811Sensor.cs b/src/devices/Ccs811/Ccs811Sensor.cs index e9acda903a..bd05260f0d 100644 --- a/src/devices/Ccs811/Ccs811Sensor.cs +++ b/src/devices/Ccs811/Ccs811Sensor.cs @@ -460,7 +460,6 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null; } else if (_controller is object) { @@ -479,6 +478,8 @@ public void Dispose() _controller.ClosePin(_pinWake); } } + + _controller = null; } #region I2C operations diff --git a/src/devices/CharacterLcd/LcdInterface.Gpio.cs b/src/devices/CharacterLcd/LcdInterface.Gpio.cs index 396f341938..5ef4e73bda 100644 --- a/src/devices/CharacterLcd/LcdInterface.Gpio.cs +++ b/src/devices/CharacterLcd/LcdInterface.Gpio.cs @@ -252,9 +252,10 @@ protected override void Dispose(bool disposing) if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + _controller = null!; + base.Dispose(disposing); } } diff --git a/src/devices/Charlieplex/CharlieplexSegment.cs b/src/devices/Charlieplex/CharlieplexSegment.cs index c8dca2c3fa..992a6102a2 100644 --- a/src/devices/Charlieplex/CharlieplexSegment.cs +++ b/src/devices/Charlieplex/CharlieplexSegment.cs @@ -214,8 +214,9 @@ public void Dispose() if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null!; } + + _gpioController = null!; } // IOutputSegment Implementation diff --git a/src/devices/Common/Iot/Device/Multiplexing/GpioOutputSegment.cs b/src/devices/Common/Iot/Device/Multiplexing/GpioOutputSegment.cs index aa3d2ccd00..a808ef59b1 100644 --- a/src/devices/Common/Iot/Device/Multiplexing/GpioOutputSegment.cs +++ b/src/devices/Common/Iot/Device/Multiplexing/GpioOutputSegment.cs @@ -130,8 +130,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } } } diff --git a/src/devices/DCMotor/DCMotor.cs b/src/devices/DCMotor/DCMotor.cs index 27abf018b9..1b9c1e6eaa 100644 --- a/src/devices/DCMotor/DCMotor.cs +++ b/src/devices/DCMotor/DCMotor.cs @@ -266,8 +266,9 @@ public virtual void Dispose() if (_shouldDispose) { Controller?.Dispose(); - Controller = null!; } + + Controller = null!; } } } diff --git a/src/devices/Dhtxx/DhtBase.cs b/src/devices/Dhtxx/DhtBase.cs index 5b0a5b1cf0..defcff6f1f 100644 --- a/src/devices/Dhtxx/DhtBase.cs +++ b/src/devices/Dhtxx/DhtBase.cs @@ -385,13 +385,13 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null; } else if (_controller?.IsPinOpen(_pin) ?? false) { _controller.ClosePin(_pin); } + _controller = null; _i2cDevice?.Dispose(); _i2cDevice = null; } diff --git a/src/devices/ExplorerHat/ExplorerHat.cs b/src/devices/ExplorerHat/ExplorerHat.cs index dad6c2a77b..87102d2eac 100644 --- a/src/devices/ExplorerHat/ExplorerHat.cs +++ b/src/devices/ExplorerHat/ExplorerHat.cs @@ -47,8 +47,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } } } diff --git a/src/devices/ExplorerHat/Led.cs b/src/devices/ExplorerHat/Led.cs index f975b0f9e1..e08260649f 100644 --- a/src/devices/ExplorerHat/Led.cs +++ b/src/devices/ExplorerHat/Led.cs @@ -75,8 +75,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } } } diff --git a/src/devices/ExplorerHat/Lights.cs b/src/devices/ExplorerHat/Lights.cs index d06f839516..759a139f80 100644 --- a/src/devices/ExplorerHat/Lights.cs +++ b/src/devices/ExplorerHat/Lights.cs @@ -114,8 +114,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } /// diff --git a/src/devices/ExplorerHat/Motors.cs b/src/devices/ExplorerHat/Motors.cs index acc7d750ca..1607e4d7ad 100644 --- a/src/devices/ExplorerHat/Motors.cs +++ b/src/devices/ExplorerHat/Motors.cs @@ -91,8 +91,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } } } diff --git a/src/devices/GrovePi/GrovePi.cs b/src/devices/GrovePi/GrovePi.cs index 467bdd05e1..fac9e56969 100644 --- a/src/devices/GrovePi/GrovePi.cs +++ b/src/devices/GrovePi/GrovePi.cs @@ -54,8 +54,9 @@ public void Dispose() if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } /// diff --git a/src/devices/Hcsr04/Hcsr04.cs b/src/devices/Hcsr04/Hcsr04.cs index 2da29f38dc..65ec9e209a 100644 --- a/src/devices/Hcsr04/Hcsr04.cs +++ b/src/devices/Hcsr04/Hcsr04.cs @@ -159,8 +159,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } } } diff --git a/src/devices/Hcsr501/Hcsr501.cs b/src/devices/Hcsr501/Hcsr501.cs index 4629dd2400..466d86a026 100644 --- a/src/devices/Hcsr501/Hcsr501.cs +++ b/src/devices/Hcsr501/Hcsr501.cs @@ -48,8 +48,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } /// diff --git a/src/devices/Ht1632/Ht1632.cs b/src/devices/Ht1632/Ht1632.cs index aa869f241a..2cc1daaf36 100644 --- a/src/devices/Ht1632/Ht1632.cs +++ b/src/devices/Ht1632/Ht1632.cs @@ -135,8 +135,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null; } + + _controller = null; } private void SetupPins() diff --git a/src/devices/KeyMatrix/KeyMatrix.cs b/src/devices/KeyMatrix/KeyMatrix.cs index 27f13340e8..ed431eca0e 100644 --- a/src/devices/KeyMatrix/KeyMatrix.cs +++ b/src/devices/KeyMatrix/KeyMatrix.cs @@ -216,7 +216,6 @@ public void Dispose() if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null; } else { @@ -225,6 +224,8 @@ public void Dispose() ClosePins(); } } + + _gpioController = null; } private void OpenPins() diff --git a/src/devices/LidarLiteV3/LidarLiteV3.cs b/src/devices/LidarLiteV3/LidarLiteV3.cs index f0924998a1..d5a237aded 100644 --- a/src/devices/LidarLiteV3/LidarLiteV3.cs +++ b/src/devices/LidarLiteV3/LidarLiteV3.cs @@ -354,9 +354,10 @@ public void Dispose() if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null; } + _gpioController = null; + _i2cDevice?.Dispose(); _i2cDevice = null!; } diff --git a/src/devices/LiquidLevel/LiquidLevelSwitch.cs b/src/devices/LiquidLevel/LiquidLevelSwitch.cs index c02fd5c15b..429de817bc 100644 --- a/src/devices/LiquidLevel/LiquidLevelSwitch.cs +++ b/src/devices/LiquidLevel/LiquidLevelSwitch.cs @@ -50,8 +50,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } } } diff --git a/src/devices/Mcp23xxx/Mcp23xxx.cs b/src/devices/Mcp23xxx/Mcp23xxx.cs index f6ef05630a..776827b9cc 100644 --- a/src/devices/Mcp23xxx/Mcp23xxx.cs +++ b/src/devices/Mcp23xxx/Mcp23xxx.cs @@ -253,13 +253,14 @@ protected override void Dispose(bool disposing) if (_shouldDispose) { _controller?.Dispose(); - _controller = null; _pinValues.Clear(); _bus?.Dispose(); - _bus = null!; } + _controller = null; + _bus = null!; + base.Dispose(disposing); } diff --git a/src/devices/Mcp25xxx/Mcp25xxx.cs b/src/devices/Mcp25xxx/Mcp25xxx.cs index 107ce940c4..b1ec3e9566 100644 --- a/src/devices/Mcp25xxx/Mcp25xxx.cs +++ b/src/devices/Mcp25xxx/Mcp25xxx.cs @@ -676,9 +676,10 @@ public void Dispose() if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null; } + _gpioController = null; + _spiDevice?.Dispose(); _spiDevice = null!; } diff --git a/src/devices/Mfrc522/Mfrc522.cs b/src/devices/Mfrc522/Mfrc522.cs index fedc1247b9..17f098bc0d 100644 --- a/src/devices/Mfrc522/Mfrc522.cs +++ b/src/devices/Mfrc522/Mfrc522.cs @@ -865,8 +865,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null; } + + _controller = null; } /// diff --git a/src/devices/Mhz19b/Mhz19b.cs b/src/devices/Mhz19b/Mhz19b.cs index b6ed48e6f1..d1830c3f11 100644 --- a/src/devices/Mhz19b/Mhz19b.cs +++ b/src/devices/Mhz19b/Mhz19b.cs @@ -206,9 +206,10 @@ public void Dispose() if (_shouldDispose) { _serialPortStream?.Dispose(); - _serialPortStream = null!; } + _serialPortStream = null!; + if (_serialPort?.IsOpen ?? false) { _serialPort.Close(); diff --git a/src/devices/Mpu6xxx9xxx/Mpu9250.cs b/src/devices/Mpu6xxx9xxx/Mpu9250.cs index 6b2eb7e0cf..f5657daefb 100644 --- a/src/devices/Mpu6xxx9xxx/Mpu9250.cs +++ b/src/devices/Mpu6xxx9xxx/Mpu9250.cs @@ -277,8 +277,9 @@ public Mpu9250(I2cDevice i2cDevice, bool shouldDispose = true, I2cDevice? i2CDev if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } } diff --git a/src/devices/Nrf24l01/Nrf24l01.cs b/src/devices/Nrf24l01/Nrf24l01.cs index 10068c9e91..0851766317 100644 --- a/src/devices/Nrf24l01/Nrf24l01.cs +++ b/src/devices/Nrf24l01/Nrf24l01.cs @@ -229,8 +229,9 @@ public void Dispose() if (_shouldDispose) { _gpio?.Dispose(); - _gpio = null!; } + + _gpio = null!; } /// diff --git a/src/devices/Pca95x4/Pca95x4.cs b/src/devices/Pca95x4/Pca95x4.cs index 7bf9192eba..807dc6646a 100644 --- a/src/devices/Pca95x4/Pca95x4.cs +++ b/src/devices/Pca95x4/Pca95x4.cs @@ -171,8 +171,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null; } + + _controller = null; } } } diff --git a/src/devices/Pcd8544/Pcd8544.cs b/src/devices/Pcd8544/Pcd8544.cs index 33f84a9d56..405ff2966f 100644 --- a/src/devices/Pcd8544/Pcd8544.cs +++ b/src/devices/Pcd8544/Pcd8544.cs @@ -778,7 +778,6 @@ protected override void Dispose(bool disposing) if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } else { @@ -801,6 +800,7 @@ protected override void Dispose(bool disposing) } } + _controller = null!; _spiDevice?.Dispose(); _spiDevice = null!; _pwmBacklight?.Dispose(); diff --git a/src/devices/PiJuice/PiJuice.cs b/src/devices/PiJuice/PiJuice.cs index 8fe513d294..fc5350f56a 100644 --- a/src/devices/PiJuice/PiJuice.cs +++ b/src/devices/PiJuice/PiJuice.cs @@ -49,8 +49,9 @@ public void Dispose() if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } /// diff --git a/src/devices/ShiftRegister/ShiftRegister.cs b/src/devices/ShiftRegister/ShiftRegister.cs index 1225bcd1da..8ecfa9cca6 100644 --- a/src/devices/ShiftRegister/ShiftRegister.cs +++ b/src/devices/ShiftRegister/ShiftRegister.cs @@ -208,9 +208,10 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null; } + _controller = null; + // SPI devices are always disposed _spiDevice?.Dispose(); _spiDevice = null; diff --git a/src/devices/SoftPwm/SoftwarePwmChannel.cs b/src/devices/SoftPwm/SoftwarePwmChannel.cs index ca33393460..860d319204 100644 --- a/src/devices/SoftPwm/SoftwarePwmChannel.cs +++ b/src/devices/SoftPwm/SoftwarePwmChannel.cs @@ -172,9 +172,10 @@ protected override void Dispose(bool disposing) if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + _controller = null!; + base.Dispose(disposing); } diff --git a/src/devices/SoftwareSpi/SoftwareSpi.cs b/src/devices/SoftwareSpi/SoftwareSpi.cs index 11a6cc2e16..782392aa22 100644 --- a/src/devices/SoftwareSpi/SoftwareSpi.cs +++ b/src/devices/SoftwareSpi/SoftwareSpi.cs @@ -226,9 +226,10 @@ protected override void Dispose(bool disposing) if (_shouldDispose) { _gpioController?.Dispose(); - _gpioController = null!; } + _gpioController = null!; + base.Dispose(disposing); } diff --git a/src/devices/Ssd1351/Ssd1351.cs b/src/devices/Ssd1351/Ssd1351.cs index 6b512bb3be..f033be0b0c 100644 --- a/src/devices/Ssd1351/Ssd1351.cs +++ b/src/devices/Ssd1351/Ssd1351.cs @@ -281,9 +281,10 @@ public void Dispose() if (_shouldDispose) { _gpioDevice?.Dispose(); - _gpioDevice = null!; } + _gpioDevice = null!; + _spiDevice?.Dispose(); _spiDevice = null!; } diff --git a/src/devices/Tca955x/Tca955x.cs b/src/devices/Tca955x/Tca955x.cs index a45524b570..53978f53ad 100644 --- a/src/devices/Tca955x/Tca955x.cs +++ b/src/devices/Tca955x/Tca955x.cs @@ -657,9 +657,10 @@ protected override void Dispose(bool disposing) if (_shouldDispose) { _controller?.Dispose(); - _controller = null; } + _controller = null; + _busDevice?.Dispose(); base.Dispose(true); diff --git a/src/devices/Tcs3472x/Tcs3472x.cs b/src/devices/Tcs3472x/Tcs3472x.cs index 54ba4f0687..141f65146a 100644 --- a/src/devices/Tcs3472x/Tcs3472x.cs +++ b/src/devices/Tcs3472x/Tcs3472x.cs @@ -254,8 +254,9 @@ public void Dispose() if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } } } diff --git a/src/devices/Uln2003/Uln2003.cs b/src/devices/Uln2003/Uln2003.cs index c72d8c7026..def7c83f38 100644 --- a/src/devices/Uln2003/Uln2003.cs +++ b/src/devices/Uln2003/Uln2003.cs @@ -193,8 +193,9 @@ public void Dispose() if (_shouldDispose) { _controller?.Dispose(); - _controller = null!; } + + _controller = null!; } } } diff --git a/src/devices/Vl53L0X/Vl53L0X.cs b/src/devices/Vl53L0X/Vl53L0X.cs index a248f877b5..7f25b1b2bf 100644 --- a/src/devices/Vl53L0X/Vl53L0X.cs +++ b/src/devices/Vl53L0X/Vl53L0X.cs @@ -1169,8 +1169,9 @@ public void Dispose() if (_shouldDispose) { _i2cDevice?.Dispose(); - _i2cDevice = null!; } + + _i2cDevice = null!; } private void WriteRegister(byte reg, byte param)