@@ -29,7 +29,6 @@ public sealed class GpioPin : IDisposable
2929 private readonly PinMode _pinMode = PinMode . Input ;
3030 private TimeSpan _debounceTimeout = TimeSpan . Zero ;
3131 private PinValueChangedEventHandler _callbacks = null ;
32- private PinValue _lastOutputValue = PinValue . Low ;
3332
3433#pragma warning disable 0414
3534 // this field is used in native so it must be kept here despite "not being used"
@@ -170,26 +169,11 @@ public void Write(PinValue value)
170169 // check if pin has been disposed
171170 if ( _disposedValue ) { throw new ObjectDisposedException ( ) ; }
172171
173- if ( _lastOutputValue != value )
174- {
175- // value has changed
176- // native write
177- WriteNative ( value ) ;
178-
179- // trigger the pin value changed event, if any is set
180- PinValueChangedEventHandler callbacks = _callbacks ;
181-
182- if ( _lastOutputValue == PinValue . Low )
183- {
184- // last value is now LOW, so it was HIGH
185- callbacks ? . Invoke ( this , new PinValueChangedEventArgs ( PinEventTypes . Falling , _pinNumber ) ) ;
186- }
187- else
188- {
189- // last value is now HIGH, so it was LOW
190- callbacks ? . Invoke ( this , new PinValueChangedEventArgs ( PinEventTypes . Rising , _pinNumber ) ) ;
191- }
192- }
172+ // the native call takes care of:
173+ // 1) validating if the requested pin mode is supported
174+ // 2) throwing ArgumentException otherwise
175+ // 3) firing the event for pin value changed if there are any registered callbacks
176+ WriteNative ( value ) ;
193177 }
194178 }
195179
0 commit comments