Skip to content
This repository was archived by the owner on Apr 10, 2020. It is now read-only.

Update DhtConnection.cs #3

Merged
merged 1 commit into from
Jan 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Raspberry.IO.Components/Sensors/Temperature/Dht/DhtConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class DhtConnection : IDisposable
private bool started;

private static readonly TimeSpan timeout = TimeSpan.FromMilliseconds(100);
private static readonly TimeSpan bitSetUptime = new TimeSpan(10 * (26 +70) / 2); // 26µs for "0", 70µs for "1"
private static readonly TimeSpan bitSetUptime = new TimeSpan(10 * 50); // 26µs -> 50 for "0", 50 -> 70µs for "1"

#endregion

Expand Down Expand Up @@ -157,6 +157,16 @@ public void Close()
protected abstract TimeSpan DefaultSamplingInterval { get; }

protected abstract TimeSpan WakeupInterval { get; }

/// <summary>
/// Time that host use before pull down and wait for response
/// </summary>
protected abstract TimeSpan HostReleaseBusInterval { get; }

/// <summary>
/// If true host have a release bus that use before acquiring data
/// </summary>
protected abstract bool HaveHostReleaseBus { get; }

#endregion

Expand All @@ -180,6 +190,12 @@ private DhtData TryGetData()
pin.Write(false);
HighResolutionTimer.Sleep(WakeupInterval);
pin.Write(true);

if(HaveHostReleaseBus)
{
HighResolutionTimer.Sleep(HostReleaseBusInterval);
pin.Write(false);
}

// Read acknowledgement from DHT
pin.Wait(true, timeout);
Expand Down Expand Up @@ -233,4 +249,4 @@ private DhtData TryGetData()

#endregion
}
}
}