class Tinkerforge::BrickletTilt

Detects inclination of Bricklet (tilt switch open/closed)

Constants

CALLBACK_TILT_STATE

This callback provides the current tilt state. It is called every time the state changes.

See BrickletTilt#get_tilt_state for a description of the states.

Public Class Methods

new(uid, ipcon) click to toggle source

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

Calls superclass method
# File lib/tinkerforge/bricklet_tilt.rb, line 37
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_TILT_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_ENABLE_TILT_STATE_CALLBACK] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_DISABLE_TILT_STATE_CALLBACK] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_IS_TILT_STATE_CALLBACK_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_TILT_STATE] = [9, 'C']

  @ipcon.add_device self
end

Public Instance Methods

disable_tilt_state_callback() click to toggle source

Disables the CALLBACK_TILT_STATE callback.

# File lib/tinkerforge/bricklet_tilt.rb, line 78
def disable_tilt_state_callback
  check_validity

  send_request FUNCTION_DISABLE_TILT_STATE_CALLBACK, [], '', 8, ''
end
enable_tilt_state_callback() click to toggle source

Enables the CALLBACK_TILT_STATE callback.

# File lib/tinkerforge/bricklet_tilt.rb, line 71
def enable_tilt_state_callback
  check_validity

  send_request FUNCTION_ENABLE_TILT_STATE_CALLBACK, [], '', 8, ''
end
get_identity() click to toggle source

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_tilt.rb, line 101
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_tilt_state() click to toggle source

Returns the current tilt state. The state can either be

  • 0 = Closed: The ball in the tilt switch closes the circuit.

  • 1 = Open: The ball in the tilt switch does not close the circuit.

  • 2 = Closed Vibrating: The tilt switch is in motion (rapid change between open and close).

.. image

/Images/Bricklets/bricklet_tilt_mechanics.jpg

:scale: 100 %
:alt: Tilt states
:align: center
:target: ../../_images/Bricklets/bricklet_tilt_mechanics.jpg
# File lib/tinkerforge/bricklet_tilt.rb, line 64
def get_tilt_state
  check_validity

  send_request FUNCTION_GET_TILT_STATE, [], '', 9, 'C'
end
is_tilt_state_callback_enabled() click to toggle source

Returns true if the CALLBACK_TILT_STATE callback is enabled.

# File lib/tinkerforge/bricklet_tilt.rb, line 85
def is_tilt_state_callback_enabled
  check_validity

  send_request FUNCTION_IS_TILT_STATE_CALLBACK_ENABLED, [], '', 9, '?'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_tilt.rb, line 106
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end