-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathDht11Connection.cs
More file actions
57 lines (44 loc) · 1.61 KB
/
Dht11Connection.cs
File metadata and controls
57 lines (44 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#region References
using System;
using UnitsNet;
#endregion
namespace Raspberry.IO.Components.Sensors.Temperature.Dht
{
/// <summary>
/// Represents a connection to a DHT11 sensor.
/// </summary>
public class Dht11Connection : DhtConnection
{
#region Instance Management
/// <summary>
/// Initializes a new instance of the <see cref="DhtConnection" /> class.
/// </summary>
/// <param name="pin">The pin.</param>
/// <param name="autoStart">if set to <c>true</c>, DHT is automatically started. Default value is <c>true</c>.</param>
public Dht11Connection(IInputOutputBinaryPin pin, bool autoStart = true) : base(pin, autoStart) { }
#endregion
#region Protected Methods
protected override TimeSpan DefaultSamplingInterval
{
get { return TimeSpan.FromSeconds(1); }
}
protected override TimeSpan WakeupInterval
{
get { return TimeSpan.FromMilliseconds(18); }
}
protected override TimeSpan HostReleaseBusInterval
{
get { throw new ArgumentException("DHT11 sensor does not have the host release time"); }
}
protected override bool HaveHostReleaseBus => false;
protected override DhtData GetDhtData(int temperatureValue, int humidityValue)
{
return new DhtData
{
RelativeHumidity = Ratio.FromPercent(humidityValue/256d),
Temperature = UnitsNet.Temperature.FromDegreesCelsius(temperatureValue/256d)
};
}
#endregion
}
}