Exemplo n.º 1
0
        /// <summary>
        /// Get the status of all leds
        /// </summary>
        /// <returns>Returns all leds status in an int, lower bit is led 0, 1 is on, 0 is off</returns>
        public int GetAllLeds()
        {
            _grovePi.WriteCommand(GrovePiCommand.LetBarGet, _port, 0, 0);
            var ret = _grovePi.ReadCommand(GrovePiCommand.LetBarGet, _port);

            return(ret[1] + (ret[2] >> 8));
        }
Exemplo n.º 2
0
        /// <summary>
        /// You need to read the sensorbefore getting the value
        /// </summary>
        public void Read()
        {
            // Fix for the firmware 1.4.0, you can request a new measurement only if you got data
            // from the previous one
            if (!(double.IsNaN(_lastTemHum[0]) && double.IsNaN(_lastTemHum[1])))
            {
                _grovePi.WriteCommand(GrovePiCommand.DhtTemp, _port, (byte)DhtType, 0);
            }

            // Wait a little bit to read the result
            // Delay from source code, line 90 in the Grove Pi firmware repository
            // This is needed for firmware 1.4.0 and also working for prevThread.Sleep(500);
            Thread.Sleep(300);
            var retArray = _grovePi.ReadCommand(GrovePiCommand.DhtTemp, _port);

            var temp = BitConverter.ToSingle(retArray.AsSpan(1, 4));

            if (Single.IsNormal(temp))
            {
                _lastTemHum[0] = temp;
            }

            var humidity = BitConverter.ToSingle(retArray.AsSpan(5, 4));

            if (Single.IsNormal(humidity))
            {
                _lastTemHum[1] = humidity;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// You need to read the sensorbefore getting the value
        /// </summary>
        public void Read()
        {
            _grovePi.WriteCommand(GrovePiCommand.DhtTemp, _port, (byte)DhtType, 0);
            // Wait a little bit to read the result
            Thread.Sleep(50);
            var retArray = _grovePi.ReadCommand(GrovePiCommand.DhtTemp, _port);

            _lastTemHum[0] = BitConverter.ToSingle(retArray.AsSpan(1, 4));
            _lastTemHum[1] = BitConverter.ToSingle(retArray.AsSpan(5, 4));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the status of all leds
        /// </summary>
        /// <returns>Returns all leds status in an int, lower bit is led 0, 1 is on, 0 is off</returns>
        public int GetAllLeds()
        {
            _grovePi.WriteCommand(GrovePiCommand.LetBarGet, _port, 0, 0);
            var ret = _grovePi.ReadCommand(GrovePiCommand.LetBarGet, _port);

            if (ret is object)
            {
                return(ret[1] + (ret[2] >> 8));
            }

            throw new Exception("Cannot find all LEDs");
        }