Class: Tinkerforge::BrickletRotaryPoti

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

Overview

300° rotary potentiometer

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

215
DEVICE_DISPLAY_NAME =

:nodoc:

'Rotary Poti Bricklet'
CALLBACK_POSITION =

This callback is triggered periodically with the period that is set by BrickletRotaryPoti#set_position_callback_period. The parameter is the position of the rotary potentiometer.

The CALLBACK_POSITION callback is only triggered if the position has changed since the last triggering.

13
CALLBACK_ANALOG_VALUE =

This callback is triggered periodically with the period that is set by BrickletRotaryPoti#set_analog_value_callback_period. The parameter is the analog value of the rotary potentiometer.

The CALLBACK_ANALOG_VALUE callback is only triggered if the position has changed since the last triggering.

14
CALLBACK_POSITION_REACHED =

This callback is triggered when the threshold as set by BrickletRotaryPoti#set_position_callback_threshold is reached. The parameter is the position of the rotary potentiometer.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletRotaryPoti#set_debounce_period.

15
CALLBACK_ANALOG_VALUE_REACHED =

This callback is triggered when the threshold as set by BrickletRotaryPoti#set_analog_value_callback_threshold is reached. The parameter is the analog value of the rotary potentiometer.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletRotaryPoti#set_debounce_period.

16
FUNCTION_GET_POSITION =

:nodoc:

1
FUNCTION_GET_ANALOG_VALUE =

:nodoc:

2
FUNCTION_SET_POSITION_CALLBACK_PERIOD =

:nodoc:

3
FUNCTION_GET_POSITION_CALLBACK_PERIOD =

:nodoc:

4
FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD =

:nodoc:

5
FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD =

:nodoc:

6
FUNCTION_SET_POSITION_CALLBACK_THRESHOLD =

:nodoc:

7
FUNCTION_GET_POSITION_CALLBACK_THRESHOLD =

:nodoc:

8
FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD =

:nodoc:

9
FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD =

:nodoc:

10
FUNCTION_SET_DEBOUNCE_PERIOD =

:nodoc:

11
FUNCTION_GET_DEBOUNCE_PERIOD =

:nodoc:

12
FUNCTION_GET_IDENTITY =

:nodoc:

255
THRESHOLD_OPTION_OFF =

:nodoc:

'x'
THRESHOLD_OPTION_OUTSIDE =

:nodoc:

'o'
THRESHOLD_OPTION_INSIDE =

:nodoc:

'i'
THRESHOLD_OPTION_SMALLER =

:nodoc:

'<'
THRESHOLD_OPTION_GREATER =

:nodoc:

'>'

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

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 74

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

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_POSITION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_POSITION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_POSITION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_POSITION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_POSITION] = [10, 's']
  @callback_formats[CALLBACK_ANALOG_VALUE] = [10, 'S']
  @callback_formats[CALLBACK_POSITION_REACHED] = [10, 's']
  @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = [10, 'S']

  @ipcon.add_device self
end

Instance Method Details

#get_analog_valueObject

Returns the value as read by a 12-bit analog-to-digital converter.

.. note

The value returned by BrickletRotaryPoti#get_position is averaged over several samples to yield less noise, while BrickletRotaryPoti#get_analog_value gives back raw unfiltered analog values. The only reason to use BrickletRotaryPoti#get_analog_value is, if you need the full resolution of the analog-to-digital converter.

If you want the analog value periodically, it is recommended to use the CALLBACK_ANALOG_VALUE callback and set the period with BrickletRotaryPoti#set_analog_value_callback_period.



124
125
126
127
128
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 124

def get_analog_value
  check_validity

  send_request FUNCTION_GET_ANALOG_VALUE, [], '', 10, 'S'
end

#get_analog_value_callback_periodObject

Returns the period as set by BrickletRotaryPoti#set_analog_value_callback_period.



160
161
162
163
164
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 160

def get_analog_value_callback_period
  check_validity

  send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 12, 'L'
end

#get_analog_value_callback_thresholdObject

Returns the threshold as set by BrickletRotaryPoti#set_analog_value_callback_threshold.



208
209
210
211
212
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 208

def get_analog_value_callback_threshold
  check_validity

  send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 13, 'k S S'
end

#get_debounce_periodObject

Returns the debounce period as set by BrickletRotaryPoti#set_debounce_period.



232
233
234
235
236
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 232

def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end

#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|



248
249
250
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 248

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

#get_positionObject

Returns the position of the rotary potentiometer. The value is between -150° (turned left) and 150° (turned right).

If you want to get the position periodically, it is recommended to use the CALLBACK_POSITION callback and set the period with BrickletRotaryPoti#set_position_callback_period.



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

def get_position
  check_validity

  send_request FUNCTION_GET_POSITION, [], '', 10, 's'
end

#get_position_callback_periodObject

Returns the period as set by BrickletRotaryPoti#set_position_callback_period.



142
143
144
145
146
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 142

def get_position_callback_period
  check_validity

  send_request FUNCTION_GET_POSITION_CALLBACK_PERIOD, [], '', 12, 'L'
end

#get_position_callback_thresholdObject

Returns the threshold as set by BrickletRotaryPoti#set_position_callback_threshold.



184
185
186
187
188
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 184

def get_position_callback_threshold
  check_validity

  send_request FUNCTION_GET_POSITION_CALLBACK_THRESHOLD, [], '', 13, 'k s s'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



253
254
255
256
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 253

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

#set_analog_value_callback_period(period) ⇒ Object

Sets the period with which the CALLBACK_ANALOG_VALUE callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_ANALOG_VALUE callback is only triggered if the analog value has changed since the last triggering.



153
154
155
156
157
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 153

def set_analog_value_callback_period(period)
  check_validity

  send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 8, ''
end

#set_analog_value_callback_threshold(option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the analog value is *outside* the min and max values"
"'i'",    "Callback is triggered when the analog value is *inside* the min and max values"
"'<'",    "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the analog value is greater than the min value (max is ignored)"


201
202
203
204
205
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 201

def set_analog_value_callback_threshold(option, min, max)
  check_validity

  send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, ''
end

#set_debounce_period(debounce) ⇒ Object

Sets the period with which the threshold callbacks

  • CALLBACK_POSITION_REACHED,

  • CALLBACK_ANALOG_VALUE_REACHED

are triggered, if the thresholds

  • BrickletRotaryPoti#set_position_callback_threshold,

  • BrickletRotaryPoti#set_analog_value_callback_threshold

keep being reached.



225
226
227
228
229
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 225

def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end

#set_position_callback_period(period) ⇒ Object

Sets the period with which the CALLBACK_POSITION callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_POSITION callback is only triggered if the position has changed since the last triggering.



135
136
137
138
139
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 135

def set_position_callback_period(period)
  check_validity

  send_request FUNCTION_SET_POSITION_CALLBACK_PERIOD, [period], 'L', 8, ''
end

#set_position_callback_threshold(option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_POSITION_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the position is *outside* the min and max values"
"'i'",    "Callback is triggered when the position is *inside* the min and max values"
"'<'",    "Callback is triggered when the position is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the position is greater than the min value (max is ignored)"


177
178
179
180
181
# File 'lib/tinkerforge/bricklet_rotary_poti.rb', line 177

def set_position_callback_threshold(option, min, max)
  check_validity

  send_request FUNCTION_SET_POSITION_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 8, ''
end