Esempio n. 1
0
        public float ReadPressure()
        {
            var status = I2cUtils.Read8(device, C_Status);

            if ((status & 2) == 2)
            {
                Int32 rawData = (Int32)I2cUtils.Read24LE(device, C_PressOutXL + 0x80);
                return(rawData * pressureFactor);
            }
            return(0.0f);
        }
Esempio n. 2
0
        public float ReadTemperature()
        {
            var status = I2cUtils.Read8(device, C_Status);

            if ((status & 1) == 1)
            {
                var rawData = (Int16)I2cUtils.Read16LE(device, C_TempOutL + 0x80);
                return(convertTemperature(rawData));
            }
            // TODO: throw exception or return status code if reading is ready or not?
            return(0.0f);
        }
Esempio n. 3
0
        public float ReadHumidity()
        {
            var status = I2cUtils.Read8(device, C_Status);

            if ((status & 2) == 2)
            {
                var rawData = (Int16)I2cUtils.Read16LE(device, C_HumidityOutL + 0x80);
                return(convertHumidity(rawData));;
            }
            // TODO: throw exception or return status code if reading is ready or not?
            return(0.0f);
        }
Esempio n. 4
0
        private Func <Int16, float> GetHumidityConverter()
        {
            byte h0h2 = I2cUtils.Read8(device, C_H0H2 + 0x80);
            byte h1h2 = I2cUtils.Read8(device, C_H1H2 + 0x80);

            float h0 = h0h2 * 0.5f;
            float h1 = h1h2 * 0.5f;

            Int16 h0t0out = (Int16)I2cUtils.Read16LE(device, C_H0T0Out + 0x80);
            Int16 h1t0out = (Int16)I2cUtils.Read16LE(device, C_H1T0Out + 0x80);

            float m = (h1 - h0) / (h0t0out - h1t0out);
            float b = h0 - (m * h0t0out);

            return(t => t * m + b);
        }
Esempio n. 5
0
        protected override async Task InitAsync()
        {
            device = await I2cUtils.GetDeviceAsync(C_Addr, I2cBusSpeed.FastMode);

            // PD RESERVED BDU ODR1-0
            //  1     0000   1     11
            // active, n/a, non-continous, 12.5Hz for both
            I2cUtils.WriteByte(device, C_Ctrl1, 0x87);

            // RESERVED AVGT2-0 AVGH2-0
            //       00     011     011
            // n/a, average: 16, 32 (temperature, humidity)
            I2cUtils.WriteByte(device, C_AvConf, 0x1B);

            convertTemperature = GetTemperatureConverter();
            convertHumidity    = GetHumidityConverter();
        }
Esempio n. 6
0
        private Func <Int16, float> GetTemperatureConverter()
        {
            byte rawMsb = I2cUtils.Read8(device, C_T1T0 + 0x80);

            byte t0Lsb = I2cUtils.Read8(device, C_T0C8 + 0x80);
            byte t1Lsb = I2cUtils.Read8(device, C_T1C8 + 0x80);

            UInt16 t0c8 = (UInt16)(((UInt16)(rawMsb & 0x03) << 8) | (UInt16)t0Lsb);
            UInt16 t1c8 = (UInt16)(((UInt16)(rawMsb & 0x0C) << 6) | (UInt16)t1Lsb);

            float t0 = t0c8 / 8.0f;
            float t1 = t1c8 / 8.0f;

            Int16 t0out = (Int16)I2cUtils.Read16LE(device, C_T0Out + 0x80);
            Int16 t1out = (Int16)I2cUtils.Read16LE(device, C_T1Out + 0x80);

            float m = (t1 - t0) / (t1out - t0out);
            float b = t0 - (m * t0out);

            return(t => t * m + b);
        }
Esempio n. 7
0
        protected override async Task InitAsync()
        {
            device = await I2cUtils.GetDeviceAsync(C_Addr, I2cBusSpeed.FastMode);

            // PD ODR2-0 DIFF BDU RESET SIM
            //  1    100    0   1     0   0
            // Active mode, 25Hz, default, non-continous, disable, default
            I2cUtils.WriteByte(device, C_Ctrl1, 0xC4);

            // AVGP1-0 AVGT1-0
            //      01      01
            // N. internal average: 32, 16 (pressure, temperature)
            I2cUtils.WriteByte(device, C_ResConf, 0x05);

            // F_MODE2 F_MODE1 F_MODE0
            //       1       1       0
            // FIFO_MEAN_MODE: running average filtered pressure
            I2cUtils.WriteByte(device, C_FifoCtrl, 0xC0);

            // BOOT FIFO_EN WTM_EN FIFO_MEAN I2C_EN SWRESET AUTOZERO ONESHOT
            //    0    1         0         0      0       0        0       0
            // normal, enable, disable, disable, i2c enable, normal, normal, waiting
            I2cUtils.WriteByte(device, C_Ctrl2, 0x40);
        }