class Tinkerforge::BrickletAmbientLightV2
Measures ambient light up to 64000lux
Constants
- CALLBACK_ILLUMINANCE
This callback is triggered periodically with the period that is set by
BrickletAmbientLightV2#set_illuminance_callback_period
. The parameter is the illuminance of the ambient light sensor.The
CALLBACK_ILLUMINANCE
callback is only triggered if the illuminance has changed since the last triggering.- CALLBACK_ILLUMINANCE_REACHED
This callback is triggered when the threshold as set by
BrickletAmbientLightV2#set_illuminance_callback_threshold
is reached. The parameter is the illuminance of the ambient light sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletAmbientLightV2#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_ambient_light_v2.rb, line 69 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @response_expected[FUNCTION_GET_ILLUMINANCE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ILLUMINANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_ILLUMINANCE_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_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_ILLUMINANCE] = [12, 'L'] @callback_formats[CALLBACK_ILLUMINANCE_REACHED] = [12, 'L'] @ipcon.add_device self end
Public Instance Methods
Returns the configuration as set by BrickletAmbientLightV2#set_configuration
.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 204 def get_configuration check_validity send_request FUNCTION_GET_CONFIGURATION, [], '', 10, 'C C' end
Returns the debounce period as set by BrickletAmbientLightV2#set_debounce_period
.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 168 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_ambient_light_v2.rb, line 220 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the illuminance of the ambient light sensor. The measurement range goes up to about 100000lux, but above 64000lux the precision starts to drop.
- .. versionchanged
-
2.0.2$nbsp;(Plugin)
An illuminance of 0lux indicates an error condition where the sensor cannot perform a reasonable measurement. This can happen with very dim or very bright light conditions. In bright light conditions this might indicate that the sensor is saturated and the configuration should be modified (BrickletAmbientLightV2#set_configuration) to better match the light conditions.
If you want to get the illuminance periodically, it is recommended to use the CALLBACK_ILLUMINANCE
callback and set the period with BrickletAmbientLightV2#set_illuminance_callback_period
.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 104 def get_illuminance check_validity send_request FUNCTION_GET_ILLUMINANCE, [], '', 12, 'L' end
Returns the period as set by BrickletAmbientLightV2#set_illuminance_callback_period
.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 122 def get_illuminance_callback_period check_validity send_request FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletAmbientLightV2#set_illuminance_callback_threshold
.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 146 def get_illuminance_callback_threshold check_validity send_request FUNCTION_GET_ILLUMINANCE_CALLBACK_THRESHOLD, [], '', 17, 'k L L' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 225 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Sets the configuration. It is possible to configure an illuminance range between 0-600lux and 0-64000lux and an integration time between 50ms and 400ms.
- .. versionadded
-
2.0.2$nbsp;(Plugin)
The unlimited illuminance range allows to measure up to about 100000lux, but above 64000lux the precision starts to drop.
A smaller illuminance range increases the resolution of the data. A longer integration time will result in less noise on the data.
- .. versionchanged
-
2.0.2$nbsp;(Plugin)
If the actual measure illuminance is out-of-range then the current illuminance range maximum +0.01lux is reported by BrickletAmbientLightV2#get_illuminance and the CALLBACK_ILLUMINANCE callback. For example, 800001 for the 0-8000lux range.
- .. versionchanged
-
2.0.2$nbsp;(Plugin)
With a long integration time the sensor might be saturated before the measured value reaches the maximum of the selected illuminance range. In this case 0lux is reported by BrickletAmbientLightV2#get_illuminance and the CALLBACK_ILLUMINANCE callback.
If the measurement is out-of-range or the sensor is saturated then you should configure the next higher illuminance range. If the highest range is already in use, then start to reduce the integration time.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 197 def set_configuration(illuminance_range, integration_time) check_validity send_request FUNCTION_SET_CONFIGURATION, [illuminance_range, integration_time], 'C C', 8, '' end
Sets the period with which the threshold callbacks
are triggered, if the thresholds
keep being reached.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 161 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end
Sets the period with which the CALLBACK_ILLUMINANCE
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_ILLUMINANCE
callback is only triggered if the illuminance has changed since the last triggering.
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 115 def set_illuminance_callback_period(period) check_validity send_request FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_ILLUMINANCE_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the illuminance is *outside* the min and max values" "'i'", "Callback is triggered when the illuminance is *inside* the min and max values" "'<'", "Callback is triggered when the illuminance is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the illuminance is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_ambient_light_v2.rb, line 139 def set_illuminance_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_ILLUMINANCE_CALLBACK_THRESHOLD, [option, min, max], 'k L L', 8, '' end