Class: Tinkerforge::BrickletHumidity
- Defined in:
- lib/tinkerforge/bricklet_humidity.rb
Overview
Measures relative humidity
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
27- DEVICE_DISPLAY_NAME =
:nodoc:
'Humidity Bricklet'- 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.
CALLBACK_HUMIDITY is only triggered if the humidity has changed since the last triggering.
13- 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.
CALLBACK_ANALOG_VALUE is only triggered if the humidity has changed since the last triggering.
14- 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.
15- 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.
16- FUNCTION_GET_HUMIDITY =
:nodoc:
1- FUNCTION_GET_ANALOG_VALUE =
:nodoc:
2- FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD =
:nodoc:
3- FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD =
:nodoc:
4- FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
5- FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
6- FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD =
:nodoc:
7- FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD =
:nodoc:
8- FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD =
:nodoc:
9- FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD =
:nodoc:
10- FUNCTION_SET_DEBOUNCE_PERIOD =
:nodoc:
11- FUNCTION_GET_DEBOUNCE_PERIOD =
:nodoc:
12- 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:
'>'
Constants inherited from Device
Device::RESPONSE_EXPECTED_ALWAYS_FALSE, 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, #registered_callbacks, #uid
Instance Method Summary collapse
-
#get_analog_value ⇒ Object
Returns the value as read by a 12-bit analog-to-digital converter.
-
#get_analog_value_callback_period ⇒ Object
Returns the period as set by BrickletHumidity#set_analog_value_callback_period.
-
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletHumidity#set_analog_value_callback_threshold.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletHumidity#set_debounce_period.
-
#get_humidity ⇒ Object
Returns the humidity of the sensor.
-
#get_humidity_callback_period ⇒ Object
Returns the period as set by BrickletHumidity#set_humidity_callback_period.
-
#get_humidity_callback_threshold ⇒ Object
Returns the threshold as set by BrickletHumidity#set_humidity_callback_threshold.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#initialize(uid, ipcon) ⇒ BrickletHumidity
constructor
Creates an object with the unique device ID
uidand adds it to the IP Connectionipcon. -
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
idto the blockblock. -
#set_analog_value_callback_period(period) ⇒ Object
Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered periodically.
-
#set_analog_value_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
-
#set_debounce_period(debounce) ⇒ Object
Sets the period in ms with which the threshold callbacks.
-
#set_humidity_callback_period(period) ⇒ Object
Sets the period in ms with which the CALLBACK_HUMIDITY callback is triggered periodically.
-
#set_humidity_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_HUMIDITY_REACHED callback.
Methods inherited from Device
#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletHumidity
Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 72 def initialize(uid, ipcon) super uid, ipcon @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[CALLBACK_HUMIDITY] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_HUMIDITY_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_HUMIDITY] = 'S' @callback_formats[CALLBACK_ANALOG_VALUE] = 'S' @callback_formats[CALLBACK_HUMIDITY_REACHED] = 'S' @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S' end |
Instance Method Details
#get_analog_value ⇒ Object
Returns the value as read by a 12-bit analog-to-digital converter. The value is between 0 and 4095.
- .. note
-
The value returned by BrickletHumidity#get_humidity is averaged over several samples to yield less noise, while BrickletHumidity#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 <github.com/Tinkerforge/humidity-bricklet/raw/master/datasheets/hih-5030.pdf>`__.
If you want the analog value periodically, it is recommended to use the callback CALLBACK_ANALOG_VALUE and set the period with BrickletHumidity#set_analog_value_callback_period.
127 128 129 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 127 def get_analog_value send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S') end |
#get_analog_value_callback_period ⇒ Object
Returns the period as set by BrickletHumidity#set_analog_value_callback_period.
159 160 161 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 159 def get_analog_value_callback_period send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L') end |
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletHumidity#set_analog_value_callback_threshold.
203 204 205 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 203 def get_analog_value_callback_threshold send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S') end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletHumidity#set_debounce_period.
225 226 227 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 225 def get_debounce_period send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L') end |
#get_humidity ⇒ Object
Returns the humidity of the sensor. The value has a range of 0 to 1000 and is given in %RH/10 (Relative Humidity), i.e. a value of 421 means that a humidity of 42.1 %RH is measured.
If you want to get the humidity periodically, it is recommended to use the callback CALLBACK_HUMIDITY and set the period with BrickletHumidity#set_humidity_callback_period.
108 109 110 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 108 def get_humidity send_request(FUNCTION_GET_HUMIDITY, [], '', 2, 'S') end |
#get_humidity_callback_period ⇒ Object
Returns the period as set by BrickletHumidity#set_humidity_callback_period.
143 144 145 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 143 def get_humidity_callback_period send_request(FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD, [], '', 4, 'L') end |
#get_humidity_callback_threshold ⇒ Object
Returns the threshold as set by BrickletHumidity#set_humidity_callback_threshold.
181 182 183 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 181 def get_humidity_callback_threshold send_request(FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD, [], '', 5, 'k S S') end |
#get_identity ⇒ Object
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’ or ‘d’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
237 238 239 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 237 def get_identity send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S') end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id to the block block.
242 243 244 245 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 242 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_analog_value_callback_period(period) ⇒ Object
Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered periodically. A value of 0 turns the callback off.
CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the last triggering.
The default value is 0.
154 155 156 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 154 def set_analog_value_callback_period(period) send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '') end |
#set_analog_value_callback_threshold(option, min, max) ⇒ Object
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)"
The default value is (‘x’, 0, 0).
198 199 200 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 198 def set_analog_value_callback_threshold(option, min, max) send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '') end |
#set_debounce_period(debounce) ⇒ Object
Sets the period in ms with which the threshold callbacks
-
CALLBACK_HUMIDITY_REACHED,
-
CALLBACK_ANALOG_VALUE_REACHED
are triggered, if the thresholds
-
BrickletHumidity#set_humidity_callback_threshold,
-
BrickletHumidity#set_analog_value_callback_threshold
keep being reached.
The default value is 100.
220 221 222 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 220 def set_debounce_period(debounce) send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '') end |
#set_humidity_callback_period(period) ⇒ Object
Sets the period in ms with which the CALLBACK_HUMIDITY callback is triggered periodically. A value of 0 turns the callback off.
CALLBACK_HUMIDITY is only triggered if the humidity has changed since the last triggering.
The default value is 0.
138 139 140 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 138 def set_humidity_callback_period(period) send_request(FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD, [period], 'L', 0, '') end |
#set_humidity_callback_threshold(option, min, max) ⇒ Object
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)"
The default value is (‘x’, 0, 0).
176 177 178 |
# File 'lib/tinkerforge/bricklet_humidity.rb', line 176 def set_humidity_callback_threshold(option, min, max) send_request(FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '') end |