Class: Tinkerforge::BrickletBarometer

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_barometer.rb

Overview

Measures air pressure and altitude changes

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

221
DEVICE_DISPLAY_NAME =

:nodoc:

'Barometer Bricklet'
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.

15
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.

16
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.

17
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.

18
FUNCTION_GET_AIR_PRESSURE =

:nodoc:

1
FUNCTION_GET_ALTITUDE =

:nodoc:

2
FUNCTION_SET_AIR_PRESSURE_CALLBACK_PERIOD =

:nodoc:

3
FUNCTION_GET_AIR_PRESSURE_CALLBACK_PERIOD =

:nodoc:

4
FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD =

:nodoc:

5
FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD =

:nodoc:

6
FUNCTION_SET_AIR_PRESSURE_CALLBACK_THRESHOLD =

:nodoc:

7
FUNCTION_GET_AIR_PRESSURE_CALLBACK_THRESHOLD =

:nodoc:

8
FUNCTION_SET_ALTITUDE_CALLBACK_THRESHOLD =

:nodoc:

9
FUNCTION_GET_ALTITUDE_CALLBACK_THRESHOLD =

:nodoc:

10
FUNCTION_SET_DEBOUNCE_PERIOD =

:nodoc:

11
FUNCTION_GET_DEBOUNCE_PERIOD =

:nodoc:

12
FUNCTION_SET_REFERENCE_AIR_PRESSURE =

:nodoc:

13
FUNCTION_GET_CHIP_TEMPERATURE =

:nodoc:

14
FUNCTION_GET_REFERENCE_AIR_PRESSURE =

:nodoc:

19
FUNCTION_SET_AVERAGING =

:nodoc:

20
FUNCTION_GET_AVERAGING =

:nodoc:

21
FUNCTION_SET_I2C_MODE =

:nodoc:

22
FUNCTION_GET_I2C_MODE =

:nodoc:

23
FUNCTION_GET_IDENTITY =

:nodoc:

255
THRESHOLD_OPTION_OFF =

:nodoc:

'x'
THRESHOLD_OPTION_OUTSIDE =

:nodoc:

'o'
THRESHOLD_OPTION_INSIDE =

:nodoc:

'i'
THRESHOLD_OPTION_SMALLER =

:nodoc:

'<'
THRESHOLD_OPTION_GREATER =

:nodoc:

'>'
I2C_MODE_FAST =

:nodoc:

0
I2C_MODE_SLOW =

:nodoc:

1

Constants inherited from Device

Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid

Instance Method Summary collapse

Methods inherited from Device

#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletBarometer

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/tinkerforge/bricklet_barometer.rb', line 83

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

Instance Method Details

#get_air_pressureObject

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.



122
123
124
125
126
# File 'lib/tinkerforge/bricklet_barometer.rb', line 122

def get_air_pressure
  check_validity

  send_request FUNCTION_GET_AIR_PRESSURE, [], '', 12, 'l'
end

#get_air_pressure_callback_periodObject

Returns the period as set by BrickletBarometer#set_air_pressure_callback_period.



153
154
155
156
157
# File 'lib/tinkerforge/bricklet_barometer.rb', line 153

def get_air_pressure_callback_period
  check_validity

  send_request FUNCTION_GET_AIR_PRESSURE_CALLBACK_PERIOD, [], '', 12, 'L'
end

#get_air_pressure_callback_thresholdObject

Returns the threshold as set by BrickletBarometer#set_air_pressure_callback_threshold.



195
196
197
198
199
# File 'lib/tinkerforge/bricklet_barometer.rb', line 195

def get_air_pressure_callback_threshold
  check_validity

  send_request FUNCTION_GET_AIR_PRESSURE_CALLBACK_THRESHOLD, [], '', 17, 'k l l'
end

#get_altitudeObject

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.



135
136
137
138
139
# File 'lib/tinkerforge/bricklet_barometer.rb', line 135

def get_altitude
  check_validity

  send_request FUNCTION_GET_ALTITUDE, [], '', 12, 'l'
end

#get_altitude_callback_periodObject

Returns the period as set by BrickletBarometer#set_altitude_callback_period.



171
172
173
174
175
# File 'lib/tinkerforge/bricklet_barometer.rb', line 171

def get_altitude_callback_period
  check_validity

  send_request FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD, [], '', 12, 'L'
end

#get_altitude_callback_thresholdObject

Returns the threshold as set by BrickletBarometer#set_altitude_callback_threshold.



219
220
221
222
223
# File 'lib/tinkerforge/bricklet_barometer.rb', line 219

def get_altitude_callback_threshold
  check_validity

  send_request FUNCTION_GET_ALTITUDE_CALLBACK_THRESHOLD, [], '', 17, 'k l l'
end

#get_averagingObject

Returns the averaging configuration as set by BrickletBarometer#set_averaging.

.. versionadded

2.0.1$nbsp;(Plugin)



305
306
307
308
309
# File 'lib/tinkerforge/bricklet_barometer.rb', line 305

def get_averaging
  check_validity

  send_request FUNCTION_GET_AVERAGING, [], '', 11, 'C C C'
end

#get_chip_temperatureObject

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`.



269
270
271
272
273
# File 'lib/tinkerforge/bricklet_barometer.rb', line 269

def get_chip_temperature
  check_validity

  send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
end

#get_debounce_periodObject

Returns the debounce period as set by BrickletBarometer#set_debounce_period.



243
244
245
246
247
# File 'lib/tinkerforge/bricklet_barometer.rb', line 243

def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end

#get_i2c_modeObject

Returns the I2C mode as set by BrickletBarometer#set_i2c_mode.

.. versionadded

2.0.3$nbsp;(Plugin)



333
334
335
336
337
# File 'lib/tinkerforge/bricklet_barometer.rb', line 333

def get_i2c_mode
  check_validity

  send_request FUNCTION_GET_I2C_MODE, [], '', 9, 'C'
end

#get_identityObject

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|



349
350
351
# File 'lib/tinkerforge/bricklet_barometer.rb', line 349

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#get_reference_air_pressureObject

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



276
277
278
279
280
# File 'lib/tinkerforge/bricklet_barometer.rb', line 276

def get_reference_air_pressure
  check_validity

  send_request FUNCTION_GET_REFERENCE_AIR_PRESSURE, [], '', 12, 'l'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



354
355
356
357
# File 'lib/tinkerforge/bricklet_barometer.rb', line 354

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#set_air_pressure_callback_period(period) ⇒ Object

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.



146
147
148
149
150
# File 'lib/tinkerforge/bricklet_barometer.rb', line 146

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) ⇒ Object

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)"


188
189
190
191
192
# File 'lib/tinkerforge/bricklet_barometer.rb', line 188

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) ⇒ Object

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.



164
165
166
167
168
# File 'lib/tinkerforge/bricklet_barometer.rb', line 164

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) ⇒ Object

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)"


212
213
214
215
216
# File 'lib/tinkerforge/bricklet_barometer.rb', line 212

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) ⇒ Object

Sets the different averaging parameters. It is possible to set the length of a normal averaging for the temperature and pressure, as well as an additional length of a ‘moving average <en.wikipedia.org/wiki/Moving_average>`__ for the pressure. The moving average is calculated from the normal averages. There is no moving average for the temperature.

Setting the all three parameters to 0 will turn the averaging completely off. If the averaging is off, there is lots of noise on the data, but the data is without delay. Thus we recommend to turn the averaging off if the Barometer Bricklet data is to be used for sensor fusion with other sensors.

.. versionadded

2.0.1$nbsp;(Plugin)



296
297
298
299
300
# File 'lib/tinkerforge/bricklet_barometer.rb', line 296

def set_averaging(moving_average_pressure, average_pressure, average_temperature)
  check_validity

  send_request FUNCTION_SET_AVERAGING, [moving_average_pressure, average_pressure, average_temperature], 'C C C', 8, ''
end

#set_debounce_period(debounce) ⇒ Object

Sets the period with which the threshold callbacks

  • CALLBACK_AIR_PRESSURE_REACHED,

  • CALLBACK_ALTITUDE_REACHED

are triggered, if the thresholds

  • BrickletBarometer#set_air_pressure_callback_threshold,

  • BrickletBarometer#set_altitude_callback_threshold

keep being reached.



236
237
238
239
240
# File 'lib/tinkerforge/bricklet_barometer.rb', line 236

def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end

#set_i2c_mode(mode) ⇒ Object

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)



324
325
326
327
328
# File 'lib/tinkerforge/bricklet_barometer.rb', line 324

def set_i2c_mode(mode)
  check_validity

  send_request FUNCTION_SET_I2C_MODE, [mode], 'C', 8, ''
end

#set_reference_air_pressure(air_pressure) ⇒ Object

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/QNH>`__ and `QFE <en.wikipedia.org/wiki/Mean_sea_level_pressure#Mean_sea_level_pressure>`__ used in aviation.



258
259
260
261
262
# File 'lib/tinkerforge/bricklet_barometer.rb', line 258

def set_reference_air_pressure(air_pressure)
  check_validity

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