Class: Tinkerforge::BrickletAmbientLightV2
- Defined in:
- lib/tinkerforge/bricklet_ambient_light_v2.rb
Overview
Measures ambient light up to 64000lux
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
259- DEVICE_DISPLAY_NAME =
:nodoc:
'Ambient Light Bricklet 2.0'- 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.
10- 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.
11- FUNCTION_GET_ILLUMINANCE =
:nodoc:
1- FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD =
:nodoc:
2- FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD =
:nodoc:
3- FUNCTION_SET_ILLUMINANCE_CALLBACK_THRESHOLD =
:nodoc:
4- FUNCTION_GET_ILLUMINANCE_CALLBACK_THRESHOLD =
:nodoc:
5- FUNCTION_SET_DEBOUNCE_PERIOD =
:nodoc:
6- FUNCTION_GET_DEBOUNCE_PERIOD =
:nodoc:
7- FUNCTION_SET_CONFIGURATION =
:nodoc:
8- FUNCTION_GET_CONFIGURATION =
:nodoc:
9- 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:
'>'- ILLUMINANCE_RANGE_UNLIMITED =
:nodoc:
6- ILLUMINANCE_RANGE_64000LUX =
:nodoc:
0- ILLUMINANCE_RANGE_32000LUX =
:nodoc:
1- ILLUMINANCE_RANGE_16000LUX =
:nodoc:
2- ILLUMINANCE_RANGE_8000LUX =
:nodoc:
3- ILLUMINANCE_RANGE_1300LUX =
:nodoc:
4- ILLUMINANCE_RANGE_600LUX =
:nodoc:
5- INTEGRATION_TIME_50MS =
:nodoc:
0- INTEGRATION_TIME_100MS =
:nodoc:
1- INTEGRATION_TIME_150MS =
:nodoc:
2- INTEGRATION_TIME_200MS =
:nodoc:
3- INTEGRATION_TIME_250MS =
:nodoc:
4- INTEGRATION_TIME_300MS =
:nodoc:
5- INTEGRATION_TIME_350MS =
:nodoc:
6- INTEGRATION_TIME_400MS =
:nodoc:
7
Constants inherited from Device
Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, 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, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#get_configuration ⇒ Object
Returns the configuration as set by BrickletAmbientLightV2#set_configuration.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAmbientLightV2#set_debounce_period.
-
#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.
-
#get_illuminance ⇒ Object
Returns the illuminance of the ambient light sensor.
-
#get_illuminance_callback_period ⇒ Object
Returns the period as set by BrickletAmbientLightV2#set_illuminance_callback_period.
-
#get_illuminance_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAmbientLightV2#set_illuminance_callback_threshold.
-
#initialize(uid, ipcon) ⇒ BrickletAmbientLightV2
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_configuration(illuminance_range, integration_time) ⇒ Object
Sets the configuration.
-
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks.
-
#set_illuminance_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_ILLUMINANCE callback is triggered periodically.
-
#set_illuminance_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_ILLUMINANCE_REACHED callback.
Methods inherited from Device
#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletAmbientLightV2
Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.
Instance Method Details
#get_configuration ⇒ Object
Returns the configuration as set by BrickletAmbientLightV2#set_configuration.
202 203 204 205 206 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 202 def get_configuration check_validity send_request FUNCTION_GET_CONFIGURATION, [], '', 10, 'C C' end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAmbientLightV2#set_debounce_period.
166 167 168 169 170 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 166 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' 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’, ‘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|
218 219 220 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 218 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_illuminance ⇒ Object
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 that the sensor is saturated and the
configuration should be modified, see BrickletAmbientLightV2#set_configuration.
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.
102 103 104 105 106 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 102 def get_illuminance check_validity send_request FUNCTION_GET_ILLUMINANCE, [], '', 12, 'L' end |
#get_illuminance_callback_period ⇒ Object
Returns the period as set by BrickletAmbientLightV2#set_illuminance_callback_period.
120 121 122 123 124 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 120 def get_illuminance_callback_period check_validity send_request FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_illuminance_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAmbientLightV2#set_illuminance_callback_threshold.
144 145 146 147 148 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 144 def get_illuminance_callback_threshold check_validity send_request FUNCTION_GET_ILLUMINANCE_CALLBACK_THRESHOLD, [], '', 17, 'k L L' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id to the block block.
223 224 225 226 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 223 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_configuration(illuminance_range, integration_time) ⇒ Object
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.
195 196 197 198 199 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 195 def set_configuration(illuminance_range, integration_time) check_validity send_request FUNCTION_SET_CONFIGURATION, [illuminance_range, integration_time], 'C C', 8, '' end |
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks
-
CALLBACK_ILLUMINANCE_REACHED,
are triggered, if the thresholds
-
BrickletAmbientLightV2#set_illuminance_callback_threshold,
keep being reached.
159 160 161 162 163 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 159 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end |
#set_illuminance_callback_period(period) ⇒ Object
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.
113 114 115 116 117 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 113 def set_illuminance_callback_period(period) check_validity send_request FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_illuminance_callback_threshold(option, min, max) ⇒ Object
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)"
137 138 139 140 141 |
# File 'lib/tinkerforge/bricklet_ambient_light_v2.rb', line 137 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 |