private Func <Int16, double> GetTemperatureConversionFunc()
        {
            byte tempRawMsb = I2CSupport.Read8Bits(_i2CDevice, HTS221Defines.T1_T0 + 0x80, "Failed to read HTS221 T1_T0");

            byte temp0Lsb = I2CSupport.Read8Bits(_i2CDevice, HTS221Defines.T0_C_8 + 0x80, "Failed to read HTS221 T0_C_8");

            UInt16 T0_C_8 = (UInt16)((((UInt16)tempRawMsb & 0x03) << 8) | (UInt16)temp0Lsb);
            double T0     = T0_C_8 / 8.0;

            byte temp1Lsb = I2CSupport.Read8Bits(_i2CDevice, HTS221Defines.T1_C_8 + 0x80, "Failed to read HTS221 T1_C_8");

            UInt16 T1_C_8 = (UInt16)(((UInt16)(tempRawMsb & 0x0C) << 6) | (UInt16)temp1Lsb);
            double T1     = T1_C_8 / 8.0;

            Int16 T0_OUT = (Int16)I2CSupport.Read16Bits(_i2CDevice, HTS221Defines.T0_OUT + 0x80, ByteOrder.LittleEndian, "Failed to read HTS221 T0_OUT");

            Int16 T1_OUT = (Int16)I2CSupport.Read16Bits(_i2CDevice, HTS221Defines.T1_OUT + 0x80, ByteOrder.LittleEndian, "Failed to read HTS221 T1_OUT");

            // Temperature calibration slope
            double m = (T1 - T0) / (T1_OUT - T0_OUT);

            // Temperature calibration y intercept
            double b = T0 - (m * T0_OUT);

            return(rawTemperature => rawTemperature * m + b);
        }
        /// <summary>
        /// Tries to update the readings.
        /// Returns true if new readings are available, otherwise false.
        /// An exception is thrown if something goes wrong.
        /// </summary>
        public override bool Update()
        {
            var readings = new SensorReadings
            {
                Timestamp = DateTime.Now
            };

            byte status = I2CSupport.Read8Bits(_i2CDevice, HTS221Defines.STATUS, "Failed to read HTS221 status");

            if ((status & 0x02) == 0x02)
            {
                Int16 rawHumidity = (Int16)I2CSupport.Read16Bits(_i2CDevice, HTS221Defines.HUMIDITY_OUT_L + 0x80, ByteOrder.LittleEndian, "Failed to read HTS221 humidity");
                readings.Humidity      = _humidityConversionFunc(rawHumidity);
                readings.HumidityValid = true;
            }

            if ((status & 0x01) == 0x01)
            {
                Int16 rawTemperature = (Int16)I2CSupport.Read16Bits(_i2CDevice, HTS221Defines.TEMP_OUT_L + 0x80, ByteOrder.LittleEndian, "Failed to read HTS221 temperature");
                readings.Temperature      = _temperatureConversionFunc(rawTemperature);
                readings.TemperatureValid = true;
            }

            if (readings.HumidityValid || readings.TemperatureValid)
            {
                AssignNewReadings(readings);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Tries to update the readings.
        /// Returns true if new readings are available, otherwise false.
        /// An exception is thrown if something goes wrong.
        /// </summary>
        public override bool Update()
        {
            byte status = I2CSupport.Read8Bits(_i2CDevice, LPS25HDefines.STATUS_REG, "Failed to read LPS25H status");

            var readings = new SensorReadings
            {
                Timestamp = DateTime.Now
            };

            if ((status & 0x02) == 0x02)
            {
                Int32 rawPressure = (Int32)I2CSupport.Read24Bits(_i2CDevice, LPS25HDefines.PRESS_OUT_XL + 0x80, ByteOrder.LittleEndian, "Failed to read LPS25H pressure");

                readings.Pressure      = rawPressure / 4096.0;
                readings.PressureValid = true;
            }

            if ((status & 0x01) == 0x01)
            {
                Int16 rawTemperature = (Int16)I2CSupport.Read16Bits(_i2CDevice, LPS25HDefines.TEMP_OUT_L + 0x80, ByteOrder.LittleEndian, "Failed to read LPS25H temperature");

                readings.Temperature      = rawTemperature / 480.0 + 42.5;
                readings.TemperatureValid = true;
            }

            if (readings.PressureValid || readings.TemperatureValid)
            {
                AssignNewReadings(readings);
                return(true);
            }

            return(false);
        }
        private Func <Int16, double> GetHumidityConversionFunc()
        {
            byte   H0_H_2 = I2CSupport.Read8Bits(_i2CDevice, HTS221Defines.H0_H_2 + 0x80, "Failed to read HTS221 H0_H_2");
            double H0     = H0_H_2 / 2.0;

            byte   H1_H_2 = I2CSupport.Read8Bits(_i2CDevice, HTS221Defines.H1_H_2 + 0x80, "Failed to read HTS221 H1_H_2");
            double H1     = H1_H_2 / 2.0;

            Int16 H0_T0_OUT = (Int16)I2CSupport.Read16Bits(_i2CDevice, HTS221Defines.H0_T0_OUT + 0x80, ByteOrder.LittleEndian, "Failed to read HTS221 H0_T_OUT");

            Int16 H1_T0_OUT = (Int16)I2CSupport.Read16Bits(_i2CDevice, HTS221Defines.H1_T0_OUT + 0x80, ByteOrder.LittleEndian, "Failed to read HTS221 H1_T_OUT");

            // Humidity calibration slope
            double m = (H1 - H0) / (H1_T0_OUT - H0_T0_OUT);

            // Humidity calibration y intercept
            double b = H0 - (m * H0_T0_OUT);

            return(rawHumidity => rawHumidity * m + b);
        }