class Tinkerforge::BrickletBarometer

Measures air pressure and altitude changes

Constants

CALLBACK_AIR_PRESSURE

This callback is triggered periodically with the period that is set by BrickletBarometer#set_air_pressure_callback_period. The parameter is the air pressure of the air pressure sensor.

The CALLBACK_AIR_PRESSURE callback is only triggered if the air pressure has changed since the last triggering.

CALLBACK_AIR_PRESSURE_REACHED

This callback is triggered when the threshold as set by BrickletBarometer#set_air_pressure_callback_threshold is reached. The parameter is the air pressure of the air pressure sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletBarometer#set_debounce_period.

CALLBACK_ALTITUDE

This callback is triggered periodically with the period that is set by BrickletBarometer#set_altitude_callback_period. The parameter is the altitude of the air pressure sensor.

The CALLBACK_ALTITUDE callback is only triggered if the altitude has changed since the last triggering.

CALLBACK_ALTITUDE_REACHED

This callback is triggered when the threshold as set by BrickletBarometer#set_altitude_callback_threshold is reached. The parameter is the altitude of the air pressure sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletBarometer#set_debounce_period.

Public Class Methods

new(uid, ipcon) click to toggle source

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.

Calls superclass method
# File lib/tinkerforge/bricklet_barometer.rb, line 82
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 2]

  @response_expected[FUNCTION_GET_AIR_PRESSURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ALTITUDE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_AIR_PRESSURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_AIR_PRESSURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_AIR_PRESSURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_AIR_PRESSURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ALTITUDE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ALTITUDE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_REFERENCE_AIR_PRESSURE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_REFERENCE_AIR_PRESSURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_AVERAGING] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_AVERAGING] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_I2C_MODE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_I2C_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_AIR_PRESSURE] = [12, 'l']
  @callback_formats[CALLBACK_ALTITUDE] = [12, 'l']
  @callback_formats[CALLBACK_AIR_PRESSURE_REACHED] = [12, 'l']
  @callback_formats[CALLBACK_ALTITUDE_REACHED] = [12, 'l']

  @ipcon.add_device self
end

Public Instance Methods

get_air_pressure() click to toggle source

Returns the air pressure of the air pressure sensor.

If you want to get the air pressure periodically, it is recommended to use the CALLBACK_AIR_PRESSURE callback and set the period with BrickletBarometer#set_air_pressure_callback_period.

# File lib/tinkerforge/bricklet_barometer.rb, line 121
def get_air_pressure
  check_validity

  send_request FUNCTION_GET_AIR_PRESSURE, [], '', 12, 'l'
end
get_air_pressure_callback_period() click to toggle source

Returns the period as set by BrickletBarometer#set_air_pressure_callback_period.

# File lib/tinkerforge/bricklet_barometer.rb, line 152
def get_air_pressure_callback_period
  check_validity

  send_request FUNCTION_GET_AIR_PRESSURE_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_air_pressure_callback_threshold() click to toggle source

Returns the threshold as set by BrickletBarometer#set_air_pressure_callback_threshold.

# File lib/tinkerforge/bricklet_barometer.rb, line 194
def get_air_pressure_callback_threshold
  check_validity

  send_request FUNCTION_GET_AIR_PRESSURE_CALLBACK_THRESHOLD, [], '', 17, 'k l l'
end
get_altitude() click to toggle source

Returns the relative altitude of the air pressure sensor. The value is calculated based on the difference between the current air pressure and the reference air pressure that can be set with BrickletBarometer#set_reference_air_pressure.

If you want to get the altitude periodically, it is recommended to use the CALLBACK_ALTITUDE callback and set the period with BrickletBarometer#set_altitude_callback_period.

# File lib/tinkerforge/bricklet_barometer.rb, line 134
def get_altitude
  check_validity

  send_request FUNCTION_GET_ALTITUDE, [], '', 12, 'l'
end
get_altitude_callback_period() click to toggle source

Returns the period as set by BrickletBarometer#set_altitude_callback_period.

# File lib/tinkerforge/bricklet_barometer.rb, line 170
def get_altitude_callback_period
  check_validity

  send_request FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_altitude_callback_threshold() click to toggle source

Returns the threshold as set by BrickletBarometer#set_altitude_callback_threshold.

# File lib/tinkerforge/bricklet_barometer.rb, line 218
def get_altitude_callback_threshold
  check_validity

  send_request FUNCTION_GET_ALTITUDE_CALLBACK_THRESHOLD, [], '', 17, 'k l l'
end
get_averaging() click to toggle source

Returns the averaging configuration as set by BrickletBarometer#set_averaging.

.. versionadded

2.0.1$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_barometer.rb, line 304
def get_averaging
  check_validity

  send_request FUNCTION_GET_AVERAGING, [], '', 11, 'C C C'
end
get_chip_temperature() click to toggle source

Returns the temperature of the air pressure sensor.

This temperature is used internally for temperature compensation of the air pressure measurement. It is not as accurate as the temperature measured by the :ref: `temperature_bricklet` or the :ref:`temperature_ir_bricklet`.

# File lib/tinkerforge/bricklet_barometer.rb, line 268
def get_chip_temperature
  check_validity

  send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
end
get_debounce_period() click to toggle source

Returns the debounce period as set by BrickletBarometer#set_debounce_period.

# File lib/tinkerforge/bricklet_barometer.rb, line 242
def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end
get_i2c_mode() click to toggle source

Returns the I2C mode as set by BrickletBarometer#set_i2c_mode.

.. versionadded

2.0.3$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_barometer.rb, line 332
def get_i2c_mode
  check_validity

  send_request FUNCTION_GET_I2C_MODE, [], '', 9, 'C'
end
get_identity() click to toggle source

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'.

The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|

# File lib/tinkerforge/bricklet_barometer.rb, line 348
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_reference_air_pressure() click to toggle source

Returns the reference air pressure as set by BrickletBarometer#set_reference_air_pressure.

# File lib/tinkerforge/bricklet_barometer.rb, line 275
def get_reference_air_pressure
  check_validity

  send_request FUNCTION_GET_REFERENCE_AIR_PRESSURE, [], '', 12, 'l'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_barometer.rb, line 353
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
set_air_pressure_callback_period(period) click to toggle source

Sets the period with which the CALLBACK_AIR_PRESSURE callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_AIR_PRESSURE callback is only triggered if the air pressure has changed since the last triggering.

# File lib/tinkerforge/bricklet_barometer.rb, line 145
def set_air_pressure_callback_period(period)
  check_validity

  send_request FUNCTION_SET_AIR_PRESSURE_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_air_pressure_callback_threshold(option, min, max) click to toggle source

Sets the thresholds for the CALLBACK_AIR_PRESSURE_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the air pressure is *outside* the min and max values"
"'i'",    "Callback is triggered when the air pressure is *inside* the min and max values"
"'<'",    "Callback is triggered when the air pressure is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the air pressure is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_barometer.rb, line 187
def set_air_pressure_callback_threshold(option, min, max)
  check_validity

  send_request FUNCTION_SET_AIR_PRESSURE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 8, ''
end
set_altitude_callback_period(period) click to toggle source

Sets the period with which the CALLBACK_ALTITUDE callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_ALTITUDE callback is only triggered if the altitude has changed since the last triggering.

# File lib/tinkerforge/bricklet_barometer.rb, line 163
def set_altitude_callback_period(period)
  check_validity

  send_request FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_altitude_callback_threshold(option, min, max) click to toggle source

Sets the thresholds for the CALLBACK_ALTITUDE_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the altitude is *outside* the min and max values"
"'i'",    "Callback is triggered when the altitude is *inside* the min and max values"
"'<'",    "Callback is triggered when the altitude is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the altitude is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_barometer.rb, line 211
def set_altitude_callback_threshold(option, min, max)
  check_validity

  send_request FUNCTION_SET_ALTITUDE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 8, ''
end
set_averaging(moving_average_pressure, average_pressure, average_temperature) click to toggle source
set_debounce_period(debounce) click to toggle source

Sets the period with which the threshold callbacks

are triggered, if the thresholds

keep being reached.

# File lib/tinkerforge/bricklet_barometer.rb, line 235
def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end
set_i2c_mode(mode) click to toggle source

Sets the I2C mode. Possible modes are:

  • 0: Fast (400kHz)

  • 1: Slow (100kHz)

If you have problems with obvious outliers in the Barometer Bricklet measurements, they may be caused by EMI issues. In this case it may be helpful to lower the I2C speed.

It is however not recommended to lower the I2C speed in applications where a high throughput needs to be achieved.

.. versionadded

2.0.3$nbsp;(Plugin)

# File lib/tinkerforge/bricklet_barometer.rb, line 323
def set_i2c_mode(mode)
  check_validity

  send_request FUNCTION_SET_I2C_MODE, [mode], 'C', 8, ''
end
set_reference_air_pressure(air_pressure) click to toggle source

Sets the reference air pressure for the altitude calculation. Setting the reference to the current air pressure results in a calculated altitude of 0cm. Passing 0 is a shortcut for passing the current air pressure as reference.

Well known reference values are the Q codes `QNH <`__”>en.wikipedia.org/wiki/Mean_sea_level_pressure#Mean_sea_level_pressure>`__ used in aviation.

# File lib/tinkerforge/bricklet_barometer.rb, line 257
def set_reference_air_pressure(air_pressure)
  check_validity

  send_request FUNCTION_SET_REFERENCE_AIR_PRESSURE, [air_pressure], 'l', 8, ''
end