Skip to content

Commit 74a317a

Browse files
authored
Remove _lastOutputValue field from GpioPin (#8)
***NO_CI***
1 parent 198f967 commit 74a317a

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

System.Device.Gpio/GpioPin.cs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public sealed class Gpio​Pin : 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

System.Device.Gpio/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
////////////////////////////////////////////////////////////////
1414
// update this whenever the native assembly signature changes //
15-
[assembly: AssemblyNativeVersion("100.1.0.3")]
15+
[assembly: AssemblyNativeVersion("100.1.0.4")]
1616
////////////////////////////////////////////////////////////////
1717

1818
// Setting ComVisible to false makes the types in this assembly not visible

0 commit comments

Comments
 (0)