class Tinkerforge::BrickletHumidity
Measures relative humidity
Constants
- CALLBACK_ANALOG_VALUE
This callback is triggered periodically with the period that is set by
BrickletHumidity#set_analog_value_callback_period
. The parameter is the analog value of the sensor.The
CALLBACK_ANALOG_VALUE
callback is only triggered if the humidity has changed since the last triggering.- CALLBACK_ANALOG_VALUE_REACHED
This callback is triggered when the threshold as set by
BrickletHumidity#set_analog_value_callback_threshold
is reached. The parameter is the analog value of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletHumidity#set_debounce_period
.- CALLBACK_HUMIDITY
This callback is triggered periodically with the period that is set by
BrickletHumidity#set_humidity_callback_period
. The parameter is the humidity of the sensor.The
CALLBACK_HUMIDITY
callback is only triggered if the humidity has changed since the last triggering.- CALLBACK_HUMIDITY_REACHED
This callback is triggered when the threshold as set by
BrickletHumidity#set_humidity_callback_threshold
is reached. The parameter is the humidity of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletHumidity#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_humidity.rb, line 73 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @response_expected[FUNCTION_GET_HUMIDITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_ANALOG_VALUE_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_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_HUMIDITY] = [10, 'S'] @callback_formats[CALLBACK_ANALOG_VALUE] = [10, 'S'] @callback_formats[CALLBACK_HUMIDITY_REACHED] = [10, 'S'] @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = [10, 'S'] @ipcon.add_device self end
Public Instance Methods
Returns the value as read by a 12-bit analog-to-digital converter.
- .. note
-
The value returned by
BrickletHumidity#get_humidity
is averaged over several samples to yield less noise, whileBrickletHumidity#get_analog_value
gives back raw unfiltered analog values. The returned humidity value is calibrated for room temperatures, if you use the sensor in extreme cold or extreme warm environments, you might want to calculate the humidity from the analog value yourself. See the `HIH 5030 datasheet <CALLBACK_ANALOG_VALUE
callback and set the period withBrickletHumidity#set_analog_value_callback_period
.# File lib/tinkerforge/bricklet_humidity.rb, line 125 def get_analog_value check_validity send_request FUNCTION_GET_ANALOG_VALUE, [], '', 10, 'S' end
Returns the period as set by BrickletHumidity#set_analog_value_callback_period
.
# File lib/tinkerforge/bricklet_humidity.rb, line 161 def get_analog_value_callback_period check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletHumidity#set_analog_value_callback_threshold
.
# File lib/tinkerforge/bricklet_humidity.rb, line 209 def get_analog_value_callback_threshold check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end
Returns the debounce period as set by BrickletHumidity#set_debounce_period
.
# File lib/tinkerforge/bricklet_humidity.rb, line 233 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' end
Returns the humidity of the sensor.
If you want to get the humidity periodically, it is recommended to use the CALLBACK_HUMIDITY
callback and set the period with BrickletHumidity#set_humidity_callback_period
.
# File lib/tinkerforge/bricklet_humidity.rb, line 105 def get_humidity check_validity send_request FUNCTION_GET_HUMIDITY, [], '', 10, 'S' end
Returns the period as set by BrickletHumidity#set_humidity_callback_period
.
# File lib/tinkerforge/bricklet_humidity.rb, line 143 def get_humidity_callback_period check_validity send_request FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletHumidity#set_humidity_callback_threshold
.
# File lib/tinkerforge/bricklet_humidity.rb, line 185 def get_humidity_callback_threshold check_validity send_request FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD, [], '', 13, 'k S S' 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_humidity.rb, line 249 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_humidity.rb, line 254 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Sets the period with which the CALLBACK_ANALOG_VALUE
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_ANALOG_VALUE
callback is only triggered if the analog value has changed since the last triggering.
# File lib/tinkerforge/bricklet_humidity.rb, line 154 def set_analog_value_callback_period(period) check_validity send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the analog value is *outside* the min and max values" "'i'", "Callback is triggered when the analog value is *inside* the min and max values" "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_humidity.rb, line 202 def set_analog_value_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, '' end
Sets the period with which the threshold callbacks
are triggered, if the thresholds
keep being reached.
# File lib/tinkerforge/bricklet_humidity.rb, line 226 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end
Sets the period with which the CALLBACK_HUMIDITY
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_HUMIDITY
callback is only triggered if the humidity has changed since the last triggering.
# File lib/tinkerforge/bricklet_humidity.rb, line 136 def set_humidity_callback_period(period) check_validity send_request FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_HUMIDITY_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the humidity is *outside* the min and max values" "'i'", "Callback is triggered when the humidity is *inside* the min and max values" "'<'", "Callback is triggered when the humidity is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the humidity is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_humidity.rb, line 178 def set_humidity_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, '' end