Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Rework GpioChangeCounter Read (#123)
Browse files Browse the repository at this point in the history
***PUBLISH_RELEASE***
  • Loading branch information
josesimoes authored Apr 28, 2020
1 parent 6a40799 commit 9dd1e48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
17 changes: 6 additions & 11 deletions source/Windows.Devices.Gpio/Gpio​Change​Counter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public sealed class Gpio​Change​Counter : IDisposable
private bool _inputMode;
private GpioChangePolarity _polarity = GpioChangePolarity.Falling;
private bool _countActive = false;
private TimeSpan _readTime;

// this is used as the lock object
// a lock is required because multiple threads can access the Gpio​Change​Counter
Expand All @@ -51,10 +50,10 @@ public sealed class Gpio​Change​Counter : IDisposable
{
if ( pin.SharingMode != GpioSharingMode.Exclusive )
{
throw new ArgumentException(); }
throw new ArgumentException();
}

_pinNumber = pin.PinNumber;
_readTime = new TimeSpan(0);

_inputMode = (pin.GetDriveMode() < GpioPinDriveMode.Output );

Expand Down Expand Up @@ -114,21 +113,17 @@ public GpioChangeCount Read()

internal GpioChangeCount ReadInternal(bool reset)
{
GpioChangeCount ChangeCount = new GpioChangeCount();
GpioChangeCount changeCount;

lock (_syncLock)
{
if (_disposedValue) { throw new ObjectDisposedException(); }

ChangeCount.Count = NativeRead(reset);

// _readTime is filled by the NativeRead()
ChangeCount.RelativeTime = _readTime;
changeCount = NativeRead(reset);
}
return ChangeCount;
return changeCount;
}


/// <summary>
/// Resets the count to 0 and returns the previous count.
/// </summary>
Expand Down Expand Up @@ -249,7 +244,7 @@ public void Dispose()
private extern void NativeInit();

[MethodImpl(MethodImplOptions.InternalCall)]
private extern ulong NativeRead(bool Reset);
private extern GpioChangeCount NativeRead(bool Reset);

[MethodImpl(MethodImplOptions.InternalCall)]
private extern void NativeStart();
Expand Down
2 changes: 1 addition & 1 deletion source/Windows.Devices.Gpio/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

////////////////////////////////////////////////////////////////
// update this whenever the native assembly signature changes //
[assembly: AssemblyNativeVersion("100.1.2.1")]
[assembly: AssemblyNativeVersion("100.1.2.2")]
////////////////////////////////////////////////////////////////

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
2 changes: 1 addition & 1 deletion source/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.4.1-preview.{height}",
"version": "1.4.2-preview.{height}",
"assemblyVersion": {
"precision": "revision"
},
Expand Down

0 comments on commit 9dd1e48

Please sign in to comment.