示例#1
0
        private static byte LireOctet(DHT22SignalBus signalDHT, byte noOctet)
        {
            byte res = 0;

            for (int i = noOctet * 8; i < (noOctet + 1) * 8; i++)
            {
                res <<= 1;
                res  += LireBit(signalDHT, i);
            }
            return(res);
        }
示例#2
0
        private static DHT22Mesure ConvertirValeurs(DHT22SignalBus signalDHT)
        {
            uint humidMSB = LireOctet(signalDHT, 0);
            uint humidLSB = LireOctet(signalDHT, 1);
            uint TempMSB  = LireOctet(signalDHT, 2);
            uint TempLSB  = LireOctet(signalDHT, 3);
            uint chk      = LireOctet(signalDHT, 4);

            if (((humidMSB + humidLSB + TempLSB + TempMSB) & 0xff) != chk)
            {
                return(null);
            }
            else
            {
                return(new DHT22Mesure(humidMSB, humidLSB, TempMSB, TempLSB));
            }
        }
示例#3
0
        public static DHT22SignalBus LireSignal(GpioPin pin)
        {
            DHT22SignalBus res = new DHT22SignalBus();
            GpioPinValue   etatCourant;
            GpioPinValue   etatPrecedent;

            //******** Commande *********
            pin.Write(GpioPinValue.Low);
            pin.SetDriveMode(GpioPinDriveMode.Output);
            res._t1max = Stopwatch.GetTimestamp() + _l1max;
            while (Stopwatch.GetTimestamp() < res._t1max)
            {
            }
            pin.SetDriveMode(GpioPinDriveMode.Input);

            //***** Attente retour ******
            etatPrecedent = pin.Read();
            res._t2max    = Stopwatch.GetTimestamp() + _l2max;
            do
            {
                etatCourant = pin.Read();
                if ((etatCourant != etatPrecedent) && (etatCourant == GpioPinValue.High))
                {
                    break;
                }
                if (Stopwatch.GetTimestamp() > res._t2max)
                {
                    return(res);
                }
            } while (true);

            //****** Acquisitions *******
            res._t3max = Stopwatch.GetTimestamp() + _l3max;
            do
            {
                etatCourant = pin.Read();
                if ((etatPrecedent == GpioPinValue.High) && (etatCourant == GpioPinValue.Low))
                {
                    res.tFe[res.iFe++] = Stopwatch.GetTimestamp();
                }
                etatPrecedent = etatCourant;
            } while ((res.iFe < NB_MAX_FRONTS_DESCENDANTS) && (Stopwatch.GetTimestamp() < res._t3max));
            return(res);
        }
示例#4
0
        public DHT22Mesure Lire(int nbMaxEssais)
        {
            DHT22Mesure res = null;

            if (_pin != null)
            {
                int i = 0;
                while ((i < nbMaxEssais) && (res == null))
                {
                    DHT22SignalBus SignalDHT22 = DHT22SignalBus.LireSignal(_pin);
                    if (SignalDHT22.iFe >= DHT22SignalBus.NB_MAX_FRONTS_DESCENDANTS)
                    {
                        res = ConvertirValeurs(SignalDHT22);
                    }
                    i++;
                }
            }
            SurNouvelleMesure?.Invoke(this, res);
            return(res);
        }
示例#5
0
 private static byte LireBit(DHT22SignalBus signalDHT, int noBit)
 {
     return(((signalDHT.tFe[noBit + 1] - signalDHT.tFe[noBit]) > DHT22SignalBus.SEUIL_BIT) ? (byte)1 : (byte)0);
 }