Class: Tinkerforge::BrickletAnalogInV2
- Defined in:
- lib/tinkerforge/bricklet_analog_in_v2.rb
Overview
Measures DC voltage between 0V and 42V
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
251
- DEVICE_DISPLAY_NAME =
:nodoc:
'Analog In Bricklet 2.0'
- CALLBACK_VOLTAGE =
This callback is triggered periodically with the period that is set by BrickletAnalogInV2#set_voltage_callback_period. The parameter is the voltage of the sensor.
Der CALLBACK_VOLTAGE callback is only triggered if the voltage has changed since the last triggering.
15
- CALLBACK_ANALOG_VALUE =
This callback is triggered periodically with the period that is set by BrickletAnalogInV2#set_analog_value_callback_period. The parameter is the analog value of the sensor.
The CALLBACK_ANALOG_VALUE callback is only triggered if the voltage has changed since the last triggering.
16
- CALLBACK_VOLTAGE_REACHED =
This callback is triggered when the threshold as set by BrickletAnalogInV2#set_voltage_callback_threshold is reached. The parameter is the voltage of the sensor.
If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletAnalogInV2#set_debounce_period.
17
- CALLBACK_ANALOG_VALUE_REACHED =
This callback is triggered when the threshold as set by BrickletAnalogInV2#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 BrickletAnalogInV2#set_debounce_period.
18
- FUNCTION_GET_VOLTAGE =
:nodoc:
1
- FUNCTION_GET_ANALOG_VALUE =
:nodoc:
2
- FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD =
:nodoc:
3
- FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD =
:nodoc:
4
- FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
5
- FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD =
:nodoc:
6
- FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD =
:nodoc:
7
- FUNCTION_GET_VOLTAGE_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_SET_MOVING_AVERAGE =
:nodoc:
13
- FUNCTION_GET_MOVING_AVERAGE =
:nodoc:
14
- 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::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_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 BrickletAnalogInV2#set_analog_value_callback_period.
-
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogInV2#set_analog_value_callback_threshold.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAnalogInV2#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_moving_average ⇒ Object
Returns the length of the moving average as set by BrickletAnalogInV2#set_moving_average.
-
#get_voltage ⇒ Object
Returns the measured voltage.
-
#get_voltage_callback_period ⇒ Object
Returns the period as set by BrickletAnalogInV2#set_voltage_callback_period.
-
#get_voltage_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogInV2#set_voltage_callback_threshold.
-
#initialize(uid, ipcon) ⇒ BrickletAnalogInV2
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#set_analog_value_callback_period(period) ⇒ Object
Sets the period 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 with which the threshold callbacks.
-
#set_moving_average(average) ⇒ Object
Sets the length of a ‘moving averaging <en.wikipedia.org/wiki/Moving_average>`__ for the voltage.
-
#set_voltage_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_VOLTAGE callback is triggered periodically.
-
#set_voltage_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_VOLTAGE_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) ⇒ BrickletAnalogInV2
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#get_analog_value ⇒ Object
Returns the value as read by a 12-bit analog-to-digital converter.
If you want the analog value periodically, it is recommended to use the CALLBACK_ANALOG_VALUE callback and set the period with BrickletAnalogInV2#set_analog_value_callback_period.
121 122 123 124 125 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 121 def get_analog_value check_validity send_request FUNCTION_GET_ANALOG_VALUE, [], '', 10, 'S' end |
#get_analog_value_callback_period ⇒ Object
Returns the period as set by BrickletAnalogInV2#set_analog_value_callback_period.
157 158 159 160 161 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 157 def get_analog_value_callback_period check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_analog_value_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogInV2#set_analog_value_callback_threshold.
205 206 207 208 209 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 205 def get_analog_value_callback_threshold check_validity send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAnalogInV2#set_debounce_period.
229 230 231 232 233 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 229 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|
263 264 265 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 263 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_moving_average ⇒ Object
Returns the length of the moving average as set by BrickletAnalogInV2#set_moving_average.
247 248 249 250 251 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 247 def get_moving_average check_validity send_request FUNCTION_GET_MOVING_AVERAGE, [], '', 9, 'C' end |
#get_voltage ⇒ Object
Returns the measured voltage. The resolution is approximately 10mV.
If you want to get the voltage periodically, it is recommended to use the CALLBACK_VOLTAGE callback and set the period with BrickletAnalogInV2#set_voltage_callback_period.
110 111 112 113 114 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 110 def get_voltage check_validity send_request FUNCTION_GET_VOLTAGE, [], '', 10, 'S' end |
#get_voltage_callback_period ⇒ Object
Returns the period as set by BrickletAnalogInV2#set_voltage_callback_period.
139 140 141 142 143 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 139 def get_voltage_callback_period check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_voltage_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAnalogInV2#set_voltage_callback_threshold.
181 182 183 184 185 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 181 def get_voltage_callback_threshold check_validity send_request FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
268 269 270 271 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 268 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_analog_value_callback_period(period) ⇒ Object
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.
150 151 152 153 154 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 150 def set_analog_value_callback_period(period) check_validity send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 8, '' 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)"
198 199 200 201 202 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 198 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 |
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks
-
CALLBACK_VOLTAGE_REACHED,
-
CALLBACK_ANALOG_VALUE_REACHED
are triggered, if the thresholds
-
BrickletAnalogInV2#set_voltage_callback_threshold,
-
BrickletAnalogInV2#set_analog_value_callback_threshold
keep being reached.
222 223 224 225 226 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 222 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end |
#set_moving_average(average) ⇒ Object
Sets the length of a ‘moving averaging <en.wikipedia.org/wiki/Moving_average>`__ for the voltage.
Setting the length to 1 will turn the averaging off. With less averaging, there is more noise on the data.
240 241 242 243 244 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 240 def set_moving_average(average) check_validity send_request FUNCTION_SET_MOVING_AVERAGE, [average], 'C', 8, '' end |
#set_voltage_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_VOLTAGE callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_VOLTAGE callback is only triggered if the voltage has changed since the last triggering.
132 133 134 135 136 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 132 def set_voltage_callback_period(period) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_voltage_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_VOLTAGE_REACHED callback.
The following options are possible:
"Option", "Description"
"'x'", "Callback is turned off"
"'o'", "Callback is triggered when the voltage is *outside* the min and max values"
"'i'", "Callback is triggered when the voltage is *inside* the min and max values"
"'<'", "Callback is triggered when the voltage is smaller than the min value (max is ignored)"
"'>'", "Callback is triggered when the voltage is greater than the min value (max is ignored)"
174 175 176 177 178 |
# File 'lib/tinkerforge/bricklet_analog_in_v2.rb', line 174 def set_voltage_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, '' end |