class Tinkerforge::BrickletTemperature
Measures ambient temperature with 0.5°C accuracy
Constants
- CALLBACK_TEMPERATURE
This callback is triggered periodically with the period that is set by
BrickletTemperature#set_temperature_callback_period
. The parameter is the temperature of the sensor.The
CALLBACK_TEMPERATURE
callback is only triggered if the temperature has changed since the last triggering.- CALLBACK_TEMPERATURE_REACHED
This callback is triggered when the threshold as set by
BrickletTemperature#set_temperature_callback_threshold
is reached. The parameter is the temperature of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletTemperature#set_debounce_period
.
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_temperature.rb, line 56 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @response_expected[FUNCTION_GET_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_TEMPERATURE_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_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_TEMPERATURE] = [10, 's'] @callback_formats[CALLBACK_TEMPERATURE_REACHED] = [10, 's'] @ipcon.add_device self end
Public Instance Methods
Returns the debounce period as set by BrickletTemperature#set_debounce_period
.
# File lib/tinkerforge/bricklet_temperature.rb, line 147 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' end
Returns the I2C mode as set by BrickletTemperature#set_i2c_mode
.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_temperature.rb, line 175 def get_i2c_mode check_validity send_request FUNCTION_GET_I2C_MODE, [], '', 9, 'C' end
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_temperature.rb, line 191 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the temperature of the sensor.
If you want to get the temperature periodically, it is recommended to use the CALLBACK_TEMPERATURE
callback and set the period with BrickletTemperature#set_temperature_callback_period
.
# File lib/tinkerforge/bricklet_temperature.rb, line 83 def get_temperature check_validity send_request FUNCTION_GET_TEMPERATURE, [], '', 10, 's' end
Returns the period as set by BrickletTemperature#set_temperature_callback_period
.
# File lib/tinkerforge/bricklet_temperature.rb, line 101 def get_temperature_callback_period check_validity send_request FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletTemperature#set_temperature_callback_threshold
.
# File lib/tinkerforge/bricklet_temperature.rb, line 125 def get_temperature_callback_threshold check_validity send_request FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD, [], '', 13, 'k s s' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_temperature.rb, line 196 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Sets the period with which the threshold callback
is triggered, if the threshold
keeps being reached.
# File lib/tinkerforge/bricklet_temperature.rb, line 140 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end
Sets the I2C mode. Possible modes are:
-
0: Fast (400kHz)
-
1: Slow (100kHz)
If you have problems with obvious outliers in the Temperature 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.1$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_temperature.rb, line 166 def set_i2c_mode(mode) check_validity send_request FUNCTION_SET_I2C_MODE, [mode], 'C', 8, '' end
Sets the period with which the CALLBACK_TEMPERATURE
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_TEMPERATURE
callback is only triggered if the temperature has changed since the last triggering.
# File lib/tinkerforge/bricklet_temperature.rb, line 94 def set_temperature_callback_period(period) check_validity send_request FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_TEMPERATURE_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the temperature is *outside* the min and max values" "'i'", "Callback is triggered when the temperature is *inside* the min and max values" "'<'", "Callback is triggered when the temperature is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the temperature is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_temperature.rb, line 118 def set_temperature_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 8, '' end