Beispiel #1
0
        /// <summary>
        /// Create a DHT sensor
        /// </summary>
        /// <param name="pin">The pin number (GPIO number)</param>
        /// <param name="dhtType">The DHT Type, either Dht11 or Dht22</param>
        /// <param name="pinNumberingScheme">The GPIO pin numbering scheme</param>
        public DhtSensor(int pin, DhtType dhtType, PinNumberingScheme pinNumberingScheme = PinNumberingScheme.Logical)
        {
            _protocol   = CommunicationProtocol.OneWire;
            _controller = new GpioController(pinNumberingScheme);
            _pin        = pin;
            SetDevice(dhtType);

            _controller.OpenPin(_pin);
            // delay 1s to make sure DHT stable
            Thread.Sleep(1000);
        }
Beispiel #2
0
 /// <summary>
 /// Initialize the DHT Sensor class
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 /// <param name="dhtType">The DHT type</param>
 public DhtSensor(GrovePi grovePi, GrovePort port, DhtType dhtType)
 {
     if (!SupportedPorts.Contains(port))
     {
         throw new ArgumentException($"Grove port {port} not supported.", nameof(port));
     }
     _grovePi = grovePi;
     DhtType  = dhtType;
     _port    = port;
     // Ask for the temperature so we will have one in cache
     _grovePi.WriteCommand(GrovePiCommand.DhtTemp, _port, (byte)DhtType, 0);
 }
Beispiel #3
0
        /// <summary>
        /// Initialise the sensor instance with the corresponding device based on DhtType.
        /// </summary>
        private void SetDevice(DhtType type)
        {
            switch (type)
            {
            case DhtType.Dht11:
                _device = new Dht11Device();
                break;

            case DhtType.Dht12:
            case DhtType.Dht21:
            case DhtType.Dht22:
                _device = new Dht22Device();
                break;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a specific DHT sensor class.
        /// </summary>
        /// <param name="type">The type of DHT sensor to create.</param>
        /// <param name="dataPin">The data pin. Must be a GPIO-only pin on the P1 Header of the Pi.</param>
        /// <returns>The instance of the specific DHT sensor.</returns>
        public static DhtSensor Create(DhtType type, IGpioPin dataPin)
        {
            switch (type)
            {
            case DhtType.Dht12:
                return(new Dht12(dataPin));

            case DhtType.Dht21:
            case DhtType.AM2301:
                return(new Dht21(dataPin));

            case DhtType.Dht22:
            case DhtType.AM2302:
                return(new Dht22(dataPin));

            default:
                return(new Dht11(dataPin));
            }
        }
Beispiel #5
0
 /// <summary>
 /// Creates a specific DHT sensor class.
 /// </summary>
 /// <param name="type">The type of DHT sensor to create.</param>
 /// <param name="dataPin">The data pin. Must be a GPIO-only pin on the P1 Header of the Pi.</param>
 /// <returns>The instance of the specific DHT sensor.</returns>
 public static DhtSensor Create(DhtType type, IGpioPin dataPin) =>
 type switch
 {
Beispiel #6
0
 /// <summary>
 /// Create a DHT sensor
 /// </summary>
 /// <param name="pin">The pin number (GPIO number)</param>
 /// <param name="dhtType">The DHT Type, either Dht11 or Dht22</param>
 public DHTSensor(int pin, DhtType dhtType)
 {
     this._pin     = pin;
     this._dhtType = dhtType;
     _controller.OpenPin(pin);
 }
Beispiel #7
0
 /// <summary>
 /// Create a DHT sensor through I2C (Only DHT12)
 /// </summary>
 /// <param name="sensor">I2C Device, like UnixI2cDevice or Windows10I2cDevice</param>
 public DhtSensor(I2cDevice sensor)
 {
     _protocol = CommunicationProtocol.I2C;
     _sensor   = sensor;
     _dhtType  = DhtType.Dht12;
 }