Class: Tinkerforge::BrickletMotionDetector
- Defined in:
- lib/tinkerforge/bricklet_motion_detector.rb
Overview
Passive infrared (PIR) motion sensor, 7m range
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
233- DEVICE_DISPLAY_NAME =
:nodoc:
'Motion Detector Bricklet'- CALLBACK_MOTION_DETECTED =
This callback is called after a motion was detected.
2- CALLBACK_DETECTION_CYCLE_ENDED =
This callback is called when the detection cycle ended. When this callback is called, a new motion can be detected again after approximately 2 seconds.
3- FUNCTION_GET_MOTION_DETECTED =
:nodoc:
1- FUNCTION_GET_IDENTITY =
:nodoc:
255- MOTION_NOT_DETECTED =
:nodoc:
0- MOTION_DETECTED =
:nodoc:
1
Constants inherited from Device
Device::RESPONSE_EXPECTED_ALWAYS_FALSE, 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, #registered_callbacks, #uid
Instance Method Summary collapse
-
#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_motion_detected ⇒ Object
Returns 1 if a motion was detected.
-
#initialize(uid, ipcon) ⇒ BrickletMotionDetector
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.
Methods inherited from Device
#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletMotionDetector
Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 34 def initialize(uid, ipcon) super uid, ipcon @api_version = [2, 0, 0] @response_expected[FUNCTION_GET_MOTION_DETECTED] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[CALLBACK_MOTION_DETECTED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_DETECTION_CYCLE_ENDED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_MOTION_DETECTED] = '' @callback_formats[CALLBACK_DETECTION_CYCLE_ENDED] = '' end |
Instance Method Details
#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’ or ‘d’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
67 68 69 |
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 67 def get_identity send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S') end |
#get_motion_detected ⇒ Object
Returns 1 if a motion was detected. How long this returns 1 after a motion was detected can be adjusted with one of the small potentiometers on the Motion Detector Bricklet, see :ref:‘here <motion_detector_bricklet_sensitivity_delay_block_time>`.
There is also a blue LED on the Bricklet that is on as long as the Bricklet is in the “motion detected” state.
55 56 57 |
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 55 def get_motion_detected send_request(FUNCTION_GET_MOTION_DETECTED, [], '', 1, 'C') end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id to the block block.
72 73 74 75 |
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 72 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |