-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathDht22Connection.cs
More file actions
56 lines (44 loc) · 1.56 KB
/
Copy pathDht22Connection.cs
File metadata and controls
56 lines (44 loc) · 1.56 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
#region References
using System;
using UnitsNet;
#endregion
namespace Raspberry.IO.Components.Sensors.Temperature.Dht
{
/// <summary>
/// Represents a connection to a DHT22 sensor.
/// </summary>
public class Dht22Connection : 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 Dht22Connection(IInputOutputBinaryPin pin, bool autoStart = true) : base(pin, autoStart) { }
#endregion
#region Protected Methods
protected override TimeSpan DefaultSamplingInterval
{
get { return TimeSpan.FromSeconds(2); }
}
protected override TimeSpan WakeupInterval
{
get { return TimeSpan.FromMilliseconds(1); }
}
protected override TimeSpan HostReleaseBusInterval
{
get { return new TimeSpan(10 * 20); }
}
protected override bool HaveHostReleaseBus => true;
protected override DhtData GetDhtData(int temperatureValue, int humidityValue)
{
return new DhtData
{
RelativeHumidity = Ratio.FromPercent(humidityValue/10d),
Temperature = UnitsNet.Temperature.FromDegreesCelsius(temperatureValue/10d)
};
}
#endregion
}
}