class Tinkerforge::BrickletUVLight
Measures UV light
Constants
- CALLBACK_UV_LIGHT
This callback is triggered periodically with the period that is set by
BrickletUVLight#set_uv_light_callback_period
. The parameter is the UV Light intensity of the sensor.The
CALLBACK_UV_LIGHT
callback is only triggered if the intensity has changed since the last triggering.- CALLBACK_UV_LIGHT_REACHED
This callback is triggered when the threshold as set by
BrickletUVLight#set_uv_light_callback_threshold
is reached. The parameter is the UV Light intensity of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletUVLight#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_uv_light.rb, line 52 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 0] @response_expected[FUNCTION_GET_UV_LIGHT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_UV_LIGHT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_UV_LIGHT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_UV_LIGHT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_UV_LIGHT_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_UV_LIGHT] = [12, 'L'] @callback_formats[CALLBACK_UV_LIGHT_REACHED] = [12, 'L'] @ipcon.add_device self end
Public Instance Methods
Returns the debounce period as set by BrickletUVLight#set_debounce_period
.
# File lib/tinkerforge/bricklet_uv_light.rb, line 146 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' 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_uv_light.rb, line 162 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the UV light intensity of the sensor. The sensor has already weighted the intensity with the erythemal action spectrum to get the skin-affecting irradiation.
To get UV index you just have to divide the value by 250. For example, a UV light intensity of 500 is equivalent to an UV index of 2.
If you want to get the intensity periodically, it is recommended to use the CALLBACK_UV_LIGHT
callback and set the period with BrickletUVLight#set_uv_light_callback_period
.
# File lib/tinkerforge/bricklet_uv_light.rb, line 82 def get_uv_light check_validity send_request FUNCTION_GET_UV_LIGHT, [], '', 12, 'L' end
Returns the period as set by BrickletUVLight#set_uv_light_callback_period
.
# File lib/tinkerforge/bricklet_uv_light.rb, line 100 def get_uv_light_callback_period check_validity send_request FUNCTION_GET_UV_LIGHT_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletUVLight#set_uv_light_callback_threshold
.
# File lib/tinkerforge/bricklet_uv_light.rb, line 124 def get_uv_light_callback_threshold check_validity send_request FUNCTION_GET_UV_LIGHT_CALLBACK_THRESHOLD, [], '', 17, 'k L L' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_uv_light.rb, line 167 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Sets the period with which the threshold callbacks
are triggered, if the thresholds
keep being reached.
# File lib/tinkerforge/bricklet_uv_light.rb, line 139 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end
Sets the period with which the CALLBACK_UV_LIGHT
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_UV_LIGHT
callback is only triggered if the intensity has changed since the last triggering.
# File lib/tinkerforge/bricklet_uv_light.rb, line 93 def set_uv_light_callback_period(period) check_validity send_request FUNCTION_SET_UV_LIGHT_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_UV_LIGHT_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the intensity is *outside* the min and max values" "'i'", "Callback is triggered when the intensity is *inside* the min and max values" "'<'", "Callback is triggered when the intensity is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the intensity is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_uv_light.rb, line 117 def set_uv_light_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_UV_LIGHT_CALLBACK_THRESHOLD, [option, min, max], 'k L L', 8, '' end