|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 |
| -using nanoFramework.Hardware.Esp32.Rmt; |
5 | 4 | using System;
|
6 | 5 | using System.Device;
|
7 | 6 | using System.Device.Gpio;
|
8 | 7 | using System.Device.I2c;
|
9 | 8 | using System.Device.Model;
|
10 |
| -using System.Diagnostics; |
11 | 9 | using System.Threading;
|
| 10 | + |
| 11 | +using nanoFramework.Hardware.Esp32.Rmt; |
| 12 | + |
12 | 13 | using UnitsNet;
|
13 | 14 |
|
14 | 15 | namespace Iot.Device.DHTxx.Esp32
|
@@ -104,17 +105,26 @@ public DhtBase(int pinEcho, int pinTrigger, PinNumberingScheme pinNumberingSchem
|
104 | 105 | _shouldDispose = shouldDispose || gpioController is null;
|
105 | 106 | _controller = gpioController ?? new GpioController(pinNumberingScheme);
|
106 | 107 | _pin = pinTrigger;
|
107 |
| - _rxChannel = new ReceiverChannel(pinEcho); |
108 |
| - // 1us clock ( 80Mhz / 80 ) = 1Mhz |
109 |
| - _rxChannel.ClockDivider = 80; |
110 |
| - // no filter |
111 |
| - _rxChannel.EnableFilter(false, 5); |
112 |
| - // max time 1us clock |
113 |
| - _rxChannel.SetIdleThresold(ushort.MaxValue); |
114 |
| - // timeout after 1 second |
115 |
| - _rxChannel.ReceiveTimeout = TimeSpan.FromSeconds(1); |
116 | 108 |
|
| 109 | + var rxChannelSettings = new ReceiverChannelSettings(pinNumber: pinEcho) |
| 110 | + { |
| 111 | + // 1us clock ( 80Mhz / 80 ) = 1Mhz |
| 112 | + ClockDivider = 80, |
| 113 | + |
| 114 | + // no filter |
| 115 | + EnableFilter = false, |
| 116 | + FilterThreshold = 5, |
| 117 | + |
| 118 | + // max time 1us clock |
| 119 | + IdleThreshold = ushort.MaxValue, |
| 120 | + |
| 121 | + // timeout after 1 second |
| 122 | + ReceiveTimeout = TimeSpan.FromSeconds(1) |
| 123 | + }; |
| 124 | + |
| 125 | + _rxChannel = new ReceiverChannel(rxChannelSettings); |
117 | 126 | _controller.OpenPin(_pin, PinMode.Output);
|
| 127 | + |
118 | 128 | // delay 1s to make sure DHT stable
|
119 | 129 | Thread.Sleep(1000);
|
120 | 130 | }
|
|
0 commit comments