/// <summary> /// Return the pressure as read by the BMP180 module. /// </summary> /// <param name="compensationMode">The <see cref="PressureCompensationModes"/> of the BMP180 module.</param> /// <returns>The pressure as read from the BMP180 module, either uncompensated or Sea Level Compensated in Pascals (Pa)</returns> /// <remarks>One (1) Pascal (Pa) is equivalent to one (100) millibar (mBar).</remarks> /// <remarks>Standard meteorological reporting of Atmospheric pressure is Sea Level compensated.</remarks> /// <example>Example usage to read the Pressure: /// <code language = "C#"> /// Debug.Print("Sea Level Compensated Pressure - " + _bmp180.ReadPressure() + " meters."); /// </code> /// </example> public Single ReadPressure(PressureCompensationModes compensationMode = PressureCompensationModes.SeaLevelCompensated) { Int32 x = (((this as ITemperature).RawData - _ac6) * _ac5) >> 15; Int32 y = (_mc << 11) / (x + _md); Int32 b5 = x + y; Int32 b6 = b5 - 4000; Int32 x1 = (_b2 * ((b6 * b6) >> 12)) >> 11; Int32 x2 = (_ac2 * b6) >> 11; Int32 x3 = x1 + x2; Int32 b3 = (((_ac1 * 4 + x3) << (Byte)OverSamplingSetting) + 2) >> 2; x1 = (_ac3 * b6) >> 13; x2 = (_b1 * ((b6 * b6) >> 12)) >> 16; x3 = (x1 + x2 + 2) >> 2; UInt32 b4 = (UInt32)((_ac4 * (x3 + 32768)) >> 15); UInt32 b7 = (UInt32)(((this as IPressure).RawData - b3) * (50000 >> (Byte)OverSamplingSetting)); Int32 p = (Int32)(b7 < 0x80000000 ? b7 * 2 / b4 : b7 / b4 * 2); x1 = (p >> 8) * (p >> 8); x1 = (x1 * 3038) >> 16; x2 = (-7357 * p) >> 16; Int32 pressure = p + ((x1 + x2 + 3791) >> 4); return(compensationMode == PressureCompensationModes.Uncompensated ? pressure : CalculatePressureAsl(pressure)); }
/// <summary> /// Return the pressure as read by the BMP180 module. /// </summary> /// <param name="compensationMode">The <see cref="PressureCompensationModes"/> of the BMP180 module.</param> /// <returns>The pressure as read from the BMP180 module, either uncompensated or Sea Level Compensated in Pascals (Pa)</returns> /// <remarks>One (1) Pascal (Pa) is equivalent to one (100) millibar (mBar).</remarks> /// <remarks>Standard meteorological reporting of Atmospheric pressure is Sea Level compensated.</remarks> /// <example>Example usage to read the Pressure: /// <code language = "C#"> /// Debug.Print("Sea Level Compensated Pressure - " + _bmp180.ReadPressure() + " meters."); /// </code> /// <code language = "VB"> /// Debug.Print("Sea Level Compensated Pressure - " <![CDATA[&]]> _bmp180.ReadPressure() <![CDATA[&]]> " meters.") /// </code> /// </example> public float ReadPressure(PressureCompensationModes compensationMode = PressureCompensationModes.SeaLevelCompensated) { var x = ((this as ITemperature).RawData - _ac6) * _ac5 >> 15; var y = (_mc << 11) / (x + _md); var b5 = x + y; var b6 = b5 - 4000; var x1 = (_b2 * (b6 * b6 >> 12)) >> 11; var x2 = _ac2 * b6 >> 11; var x3 = x1 + x2; var b3 = (((_ac1 * 4 + x3) << (byte)_overSamplingSetting) + 2) >> 2; x1 = _ac3 * b6 >> 13; x2 = (_b1 * (b6 * b6 >> 12)) >> 16; x3 = ((x1 + x2) + 2) >> 2; var b4 = (uint)(_ac4 * (x3 + 32768) >> 15); var b7 = (uint)(((this as IPressure).RawData - b3) * (50000 >> (byte)_overSamplingSetting)); var p = (int)((b7 < 0x80000000) ? (b7 * 2) / b4 : (b7 / b4) * 2); x1 = (p >> 8) * (p >> 8); x1 = (x1 * 3038) >> 16; x2 = (-7357 * p) >> 16; var pressure = p + ((x1 + x2 + 3791) >> 4); return(compensationMode == PressureCompensationModes.Uncompensated ? pressure : CalculatePressureAsl(pressure)); }
/// <summary> /// Reads the pressure from the sensor. /// </summary> /// <param name="compensationMode">Indicates if the pressure reading returned by the sensor is see-level compensated or not.</param> /// <returns> /// A single representing the pressure read from the source, in hPa (hectoPascal) /// </returns> /// <example> /// <code language="C#"> /// // Reads the actual pressure, in SeaLevelCompensated mode (default) /// Debug.Print ("Current pressure = "+_pres.ReadPressure()+" hPa"); /// </code> /// </example> public Single ReadPressure(PressureCompensationModes compensationMode = PressureCompensationModes.SeaLevelCompensated) { Int32 high = ReadByte(Registers.PRESS_OUT_H); var mid = ReadByte(Registers.PRESS_OUT_L); var low = ReadByte(Registers.PRESS_OUT_XL); high <<= 8; high |= mid; high <<= 8; high |= low; return(high >> 12); }
/// <summary> /// Gets the Uncompensated or Sea Level Compensated Altitude from the AltitudeClick. /// </summary> /// <param name="compensationMode">The compensation mode for Altitude Measurement. See <see cref="PressureCompensationModes"/> for more information.</param> /// <returns>Uncompensated or Sea Level Compensated Altitude in meters (m).</returns> /// <example>Example usage: /// <code language = "C#"> /// var rawAltitude = _altitude.ReadAltitude(PressureCompensationModes.Uncompensated); /// var compensatedAltitude = _altitude.ReadPressure(PressureCompensationModes.SeaLevelCompensated); /// Debug.Print("Raw Altitude - " + rawAltitude + " meters"); /// Debug.Print("Sea Level Compensated Altitude - " + compensatedAltitude + " meters"); /// </code> /// <code language = "VB"> /// Dim rawAltitude = _altitude.ReadAltitude(PressureCompensationModes.Uncompensated) /// Dim compensatedAltitude = _altitude.ReadPressure(PressureCompensationModes.SeaLevelCompensated) /// Debug.Print("Raw Altitude - " <![CDATA[&]]> rawAltitude <![CDATA[&]]> " meters") /// Debug.Print("Sea Level Compensated Altitude - " <![CDATA[&]]> compensatedAltitude <![CDATA[&]]> " meters") /// </code> /// </example> public float ReadAltitude(PressureCompensationModes compensationMode = PressureCompensationModes.SeaLevelCompensated) { var counter = 0; SetModeStandby(); // Sensor must be in StandBy Mode when changing read mode. SetModeAltimeter(); // Set mode to Altimeter SetModeActive(); // Sensor must be active to take readings. ToggleOneShot(); // Force the sensor to take a new reading. while (!PressureDataReady()) { if (counter++ == MaxDataReadyAttempts) { return(-float.MinValue); } Thread.Sleep(1); } // Wait here until new data is available. // Read Altitude int mAltitude = ReadByte(OUT_P_MSB); int cAltitude = ReadByte(OUT_P_CSB); var lAltitude = (ReadByte(OUT_P_LSB) >> 4) / 16.0; var altitude = ((mAltitude << 8) | cAltitude) + lAltitude; if (compensationMode == PressureCompensationModes.Uncompensated) { return((float)altitude); } var tempPressure = ReadPressure(PressureCompensationModes.Uncompensated); if (Math.Abs(tempPressure - (-999.999)) < 0) { return(float.MinValue); } var seaLevelCompensation = 101325 * Math.Pow(((288 - 0.0065 * 143) / 288), 5.256); var tempValue = 101325 + tempPressure - seaLevelCompensation; return((float)(44330 * (1.0 - Math.Pow(tempValue / CalculatePressureAsl(tempValue), 0.1903)))); }
/// <summary> /// Gets the Uncompensated or Sea Level Compensated Pressure from the AltitudeClick. /// </summary> /// <param name="compensationMode">The compensation mode for Pressure Measurement. See <see cref="PressureCompensationModes"/> for more information.</param> /// <returns>The uncompensated or sea level compensated pressure depending on the <para>"compensationMode"</para> parameter passed in Pascals (Pa).</returns> /// <example>Example usage: /// <code language = "C#"> /// var rawPressure = _altitude.ReadPressure(PressureCompensationModes.Uncompensated); /// var compensatedPressure = _altitude.ReadPressure(PressureCompensationModes.SeaLevelCompensated); /// Debug.Print("Raw Pressure - " + PascalsToInches(rawPressure) + " Pa"); /// Debug.Print("Seal Level Compensated Pressure - " + compensatedPressure + " Pa"); /// </code> /// <code language = "VB"> /// Dim rawPressure = _altitude.ReadPressure(PressureCompensationModes.Uncompensated) /// Dim compensatedPressure = _altitude.ReadPressure(PressureCompensationModes.SeaLevelCompensated) /// Debug.Print("Raw Pressure - " <![CDATA[&]]> PascalsToInches(rawPressure) <![CDATA[&]]> " Pa") /// Debug.Print("Seal Level Compensated Pressure - " <![CDATA[&]]> compensatedPressure <![CDATA[&]]> " Pa") /// </code> /// </example> public float ReadPressure(PressureCompensationModes compensationMode = PressureCompensationModes.SeaLevelCompensated) { var counter = 0; SetModeStandby(); // Sensor must be in StandBy Mode when changing read mode. SetModeBarometer(); // Set mode to Barometer. SetModeActive(); // Sensor must be active to take reading. ToggleOneShot(); // Toggle One shot to force sensor to take reading. while (!PressureDataReady()) { Thread.Sleep(1); if (counter++ == MaxDataReadyAttempts) { return(float.MinValue); } } // Wait here until Pressure data is available or return -999.999 if times out. // read the Pressure Int32 mPressure = ReadByte(OUT_P_MSB); var cPressure = ReadByte(OUT_P_CSB); var lPressure = ReadByte(OUT_P_LSB); // Calculate the pressure mPressure <<= 16; mPressure |= cPressure << 8; mPressure |= lPressure; var pressure = mPressure / 64; if (compensationMode == PressureCompensationModes.Uncompensated) { return(pressure); } var seaLevelCompensation = 101325 * Math.Pow(((288 - 0.0065 * 143) / 288), 5.256); return((float)(101325 + pressure - seaLevelCompensation)); }
public Single ReadPressure(PressureCompensationModes compensationMode = PressureCompensationModes.SeaLevelCompensated) { throw new NotImplementedException(); }
/// <inheritdoc cref="IPressure" /> /// <summary> /// Reads the pressure from the altitude3 Click. /// </summary> /// <param name="compensationMode">The <see cref="PressureCompensationModes"/> to report temperature measurements.</param> /// <exception cref="NotImplementedException">A NotImplementedException will be thrown if attempting to read the temperature as this driver does not implement direct reading of temperature. Use the ReadSensor method instead.</exception> /// <example> /// Example usage: /// <code language="C#"> /// // None provided as this driver does not implement direct reading of pressure. Use the <exception cref="ReadSensor"> method instead.</exception> /// </code> /// <code language="VB"> /// ' None provided as this driver does not implement direct reading of pressure. Use the <exception cref="ReadSensor"> method instead.</exception> /// </code> /// </example> public Single ReadPressure(PressureCompensationModes compensationMode = PressureCompensationModes.SeaLevelCompensated) { throw new NotImplementedException("Reading of pressure is not supported in this driver. Use ReadSensor method instead."); }