public WeatherReading GetReading()
        {
            var result = new WeatherReading();

            LPS22HBInit();

            LPS22HBStartOneShot();

            Pi.Timing.SleepMicroseconds(300);

            float pressureData = 0f;
            float tempData     = 0f;

            if ((_device.ReadAddressByte(LPS_STATUS) & 0x01) == 0x01)   // a new pressure data is generated
            {
                byte x0 = _device.ReadAddressByte(LPS_PRESS_OUT_XL);
                byte x1 = _device.ReadAddressByte(LPS_PRESS_OUT_L);
                byte x2 = _device.ReadAddressByte(LPS_PRESS_OUT_H);
                pressureData = (float)((x2 << 16) + (x1 << 8) + x0) / 4096.0f; // hPA Hectopascal Pressure Unit
            }
            if ((_device.ReadAddressByte(LPS_STATUS) & 0x02) == 0x02)          // a new pressure data is generated
            {
                byte x0 = _device.ReadAddressByte(LPS_TEMP_OUT_L);
                byte x1 = _device.ReadAddressByte(LPS_TEMP_OUT_H);
                tempData = (float)((x1 << 8) + x0) / 100.0f; // Celcius
            }

            result.TemperatureC = tempData;
            result.Pressure     = pressureData;

            return(result);
        }
Esempio n. 2
0
        public WeatherReading GetReading()
        {
            var rng    = new Random();
            var result = new WeatherReading()
            {
                TemperatureC = (float)rng.Next(0, 40),
                Pressure     = (float)rng.Next(700, 1300)
            };

            return(result);
        }