Class: Tinkerforge::BrickletHallEffect
- Defined in:
- lib/tinkerforge/bricklet_hall_effect.rb
Overview
Detects presence of magnetic field
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
240
- DEVICE_DISPLAY_NAME =
:nodoc:
'Hall Effect Bricklet'
- CALLBACK_EDGE_COUNT =
This callback is triggered periodically with the period that is set by BrickletHallEffect#set_edge_count_callback_period. The parameters are the current count and the current value (see BrickletHallEffect#get_value and BrickletHallEffect#get_edge_count).
The CALLBACK_EDGE_COUNT callback is only triggered if the count or value changed since the last triggering.
10
- FUNCTION_GET_VALUE =
:nodoc:
1
- FUNCTION_GET_EDGE_COUNT =
:nodoc:
2
- FUNCTION_SET_EDGE_COUNT_CONFIG =
:nodoc:
3
- FUNCTION_GET_EDGE_COUNT_CONFIG =
:nodoc:
4
- FUNCTION_SET_EDGE_INTERRUPT =
:nodoc:
5
- FUNCTION_GET_EDGE_INTERRUPT =
:nodoc:
6
- FUNCTION_SET_EDGE_COUNT_CALLBACK_PERIOD =
:nodoc:
7
- FUNCTION_GET_EDGE_COUNT_CALLBACK_PERIOD =
:nodoc:
8
- FUNCTION_EDGE_INTERRUPT =
:nodoc:
9
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- EDGE_TYPE_RISING =
:nodoc:
0
- EDGE_TYPE_FALLING =
:nodoc:
1
- EDGE_TYPE_BOTH =
:nodoc:
2
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
-
#edge_interrupt ⇒ Object
This callback is triggered every n-th count, as configured with BrickletHallEffect#set_edge_interrupt.
-
#get_edge_count(reset_counter) ⇒ Object
Returns the current value of the edge counter.
-
#get_edge_count_callback_period ⇒ Object
Returns the period as set by BrickletHallEffect#set_edge_count_callback_period.
-
#get_edge_count_config ⇒ Object
Returns the edge type and debounce time as set by BrickletHallEffect#set_edge_count_config.
-
#get_edge_interrupt ⇒ Object
Returns the edges as set by BrickletHallEffect#set_edge_interrupt.
-
#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_value ⇒ Object
Returns true if a magnetic field of 3.5 millitesla or greater is detected.
-
#initialize(uid, ipcon) ⇒ BrickletHallEffect
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_edge_count_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_EDGE_COUNT callback is triggered periodically.
-
#set_edge_count_config(edge_type, debounce) ⇒ Object
The edge type parameter configures if rising edges, falling edges or both are counted.
-
#set_edge_interrupt(edges) ⇒ Object
Sets the number of edges until an interrupt is invoked.
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) ⇒ BrickletHallEffect
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#edge_interrupt ⇒ Object
This callback is triggered every n-th count, as configured with BrickletHallEffect#set_edge_interrupt. The parameters are the current count and the current value (see BrickletHallEffect#get_value and BrickletHallEffect#get_edge_count).
156 157 158 159 160 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 156 def edge_interrupt check_validity send_request FUNCTION_EDGE_INTERRUPT, [], '', 13, 'L ?' end |
#get_edge_count(reset_counter) ⇒ Object
Returns the current value of the edge counter. You can configure edge type (rising, falling, both) that is counted with BrickletHallEffect#set_edge_count_config.
If you set the reset counter to true, the count is set back to 0 directly after it is read.
80 81 82 83 84 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 80 def get_edge_count(reset_counter) check_validity send_request FUNCTION_GET_EDGE_COUNT, [reset_counter], '?', 12, 'L' end |
#get_edge_count_callback_period ⇒ Object
Returns the period as set by BrickletHallEffect#set_edge_count_callback_period.
146 147 148 149 150 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 146 def get_edge_count_callback_period check_validity send_request FUNCTION_GET_EDGE_COUNT_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_edge_count_config ⇒ Object
Returns the edge type and debounce time as set by BrickletHallEffect#set_edge_count_config.
110 111 112 113 114 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 110 def get_edge_count_config check_validity send_request FUNCTION_GET_EDGE_COUNT_CONFIG, [], '', 10, 'C C' end |
#get_edge_interrupt ⇒ Object
Returns the edges as set by BrickletHallEffect#set_edge_interrupt.
128 129 130 131 132 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 128 def get_edge_interrupt check_validity send_request FUNCTION_GET_EDGE_INTERRUPT, [], '', 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|
172 173 174 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 172 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_value ⇒ Object
Returns true if a magnetic field of 3.5 millitesla or greater is detected.
68 69 70 71 72 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 68 def get_value check_validity send_request FUNCTION_GET_VALUE, [], '', 9, '?' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
177 178 179 180 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 177 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_edge_count_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_EDGE_COUNT callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_EDGE_COUNT callback is only triggered if the edge count has changed since the last triggering.
139 140 141 142 143 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 139 def set_edge_count_callback_period(period) check_validity send_request FUNCTION_SET_EDGE_COUNT_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_edge_count_config(edge_type, debounce) ⇒ Object
The edge type parameter configures if rising edges, falling edges or both are counted. Possible edge types are:
-
0 = rising
-
1 = falling
-
2 = both
A magnetic field of 3.5 millitesla or greater causes a falling edge and a magnetic field of 2.5 millitesla or smaller causes a rising edge.
If a magnet comes near the Bricklet the signal goes low (falling edge), if a magnet is removed from the vicinity the signal goes high (rising edge).
Configuring an edge counter resets its value to 0.
If you don’t know what any of this means, just leave it at default. The default configuration is very likely OK for you.
103 104 105 106 107 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 103 def set_edge_count_config(edge_type, debounce) check_validity send_request FUNCTION_SET_EDGE_COUNT_CONFIG, [edge_type, debounce], 'C C', 8, '' end |
#set_edge_interrupt(edges) ⇒ Object
Sets the number of edges until an interrupt is invoked.
If edges is set to n, an interrupt is invoked for every n-th detected edge.
If edges is set to 0, the interrupt is disabled.
121 122 123 124 125 |
# File 'lib/tinkerforge/bricklet_hall_effect.rb', line 121 def set_edge_interrupt(edges) check_validity send_request FUNCTION_SET_EDGE_INTERRUPT, [edges], 'L', 8, '' end |