class Tinkerforge::BrickletHallEffect
Detects presence of magnetic field
Constants
- 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 (seeBrickletHallEffect#get_value
andBrickletHallEffect#get_edge_count
).The
CALLBACK_EDGE_COUNT
callback is only triggered if the count or value changed since the last triggering.
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 45 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 0] @response_expected[FUNCTION_GET_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_EDGE_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_EDGE_COUNT_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_EDGE_COUNT_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_EDGE_INTERRUPT] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_EDGE_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_EDGE_COUNT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_EDGE_COUNT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_EDGE_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_EDGE_COUNT] = [13, 'L ?'] @ipcon.add_device self end
Public Instance Methods
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
).
# File lib/tinkerforge/bricklet_hall_effect.rb, line 155 def edge_interrupt check_validity send_request FUNCTION_EDGE_INTERRUPT, [], '', 13, 'L ?' end
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.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 79 def get_edge_count(reset_counter) check_validity send_request FUNCTION_GET_EDGE_COUNT, [reset_counter], '?', 12, 'L' end
Returns the period as set by BrickletHallEffect#set_edge_count_callback_period
.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 145 def get_edge_count_callback_period check_validity send_request FUNCTION_GET_EDGE_COUNT_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the edge type and debounce time as set by BrickletHallEffect#set_edge_count_config
.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 109 def get_edge_count_config check_validity send_request FUNCTION_GET_EDGE_COUNT_CONFIG, [], '', 10, 'C C' end
Returns the edges as set by BrickletHallEffect#set_edge_interrupt
.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 127 def get_edge_interrupt check_validity send_request FUNCTION_GET_EDGE_INTERRUPT, [], '', 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_hall_effect.rb, line 171 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns true if a magnetic field of 3.5 millitesla or greater is detected.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 67 def get_value check_validity send_request FUNCTION_GET_VALUE, [], '', 9, '?' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 176 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
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.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 138 def set_edge_count_callback_period(period) check_validity send_request FUNCTION_SET_EDGE_COUNT_CALLBACK_PERIOD, [period], 'L', 8, '' end
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.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 102 def set_edge_count_config(edge_type, debounce) check_validity send_request FUNCTION_SET_EDGE_COUNT_CONFIG, [edge_type, debounce], 'C C', 8, '' end
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.
# File lib/tinkerforge/bricklet_hall_effect.rb, line 120 def set_edge_interrupt(edges) check_validity send_request FUNCTION_SET_EDGE_INTERRUPT, [edges], 'L', 8, '' end