Class: Tinkerforge::BrickletMotionDetector

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_motion_detector.rb

Overview

Passive infrared (PIR) motion sensor with 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_SET_STATUS_LED_CONFIG =

:nodoc:

4
FUNCTION_GET_STATUS_LED_CONFIG =

:nodoc:

5
FUNCTION_GET_IDENTITY =

:nodoc:

255
MOTION_NOT_DETECTED =

:nodoc:

0
MOTION_DETECTED =

:nodoc:

1
STATUS_LED_CONFIG_OFF =

:nodoc:

0
STATUS_LED_CONFIG_ON =

:nodoc:

1
STATUS_LED_CONFIG_SHOW_STATUS =

: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

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) ⇒ BrickletMotionDetector

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 41

def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 1]

  @response_expected[FUNCTION_GET_MOTION_DETECTED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_MOTION_DETECTED] = [8, '']
  @callback_formats[CALLBACK_DETECTION_CYCLE_ENDED] = [8, '']

  @ipcon.add_device self
end

Instance Method Details

#get_identityObject

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|



103
104
105
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 103

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#get_motion_detectedObject

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.



64
65
66
67
68
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 64

def get_motion_detected
  check_validity

  send_request FUNCTION_GET_MOTION_DETECTED, [], '', 9, 'C'
end

#get_status_led_configObject

Returns the configuration as set by BrickletMotionDetector#set_status_led_config.

.. versionadded

2.0.1$nbsp;(Plugin)



87
88
89
90
91
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 87

def get_status_led_config
  check_validity

  send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



108
109
110
111
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 108

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#set_status_led_config(config) ⇒ Object

Sets the status led configuration.

By default the status LED turns on if a motion is detected and off is no motion is detected.

You can also turn the LED permanently on/off.

.. versionadded

2.0.1$nbsp;(Plugin)



78
79
80
81
82
# File 'lib/tinkerforge/bricklet_motion_detector.rb', line 78

def set_status_led_config(config)
  check_validity

  send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
end