tinkerforge 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/lib/tinkerforge.rb +5 -0
  2. data/lib/tinkerforge/brick_dc.rb +359 -0
  3. data/lib/tinkerforge/brick_imu.rb +512 -0
  4. data/lib/tinkerforge/brick_master.rb +1120 -0
  5. data/lib/tinkerforge/brick_servo.rb +475 -0
  6. data/lib/tinkerforge/brick_stepper.rb +556 -0
  7. data/lib/tinkerforge/bricklet_ambient_light.rb +246 -0
  8. data/lib/tinkerforge/bricklet_analog_in.rb +273 -0
  9. data/lib/tinkerforge/bricklet_analog_out.rb +90 -0
  10. data/lib/tinkerforge/bricklet_barometer.rb +313 -0
  11. data/lib/tinkerforge/bricklet_current12.rb +274 -0
  12. data/lib/tinkerforge/bricklet_current25.rb +274 -0
  13. data/lib/tinkerforge/bricklet_distance_ir.rb +274 -0
  14. data/lib/tinkerforge/bricklet_dual_relay.rb +127 -0
  15. data/lib/tinkerforge/bricklet_gps.rb +301 -0
  16. data/lib/tinkerforge/bricklet_humidity.rb +245 -0
  17. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +165 -0
  18. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +177 -0
  19. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +177 -0
  20. data/lib/tinkerforge/bricklet_io16.rb +237 -0
  21. data/lib/tinkerforge/bricklet_io4.rb +236 -0
  22. data/lib/tinkerforge/bricklet_joystick.rb +274 -0
  23. data/lib/tinkerforge/bricklet_lcd_16x2.rb +175 -0
  24. data/lib/tinkerforge/bricklet_lcd_20x4.rb +231 -0
  25. data/lib/tinkerforge/bricklet_linear_poti.rb +241 -0
  26. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +84 -0
  27. data/lib/tinkerforge/bricklet_ptc.rb +277 -0
  28. data/lib/tinkerforge/bricklet_rotary_poti.rb +241 -0
  29. data/lib/tinkerforge/bricklet_temperature.rb +188 -0
  30. data/lib/tinkerforge/bricklet_temperature_ir.rb +275 -0
  31. data/lib/tinkerforge/bricklet_voltage.rb +241 -0
  32. data/lib/tinkerforge/bricklet_voltage_current.rb +386 -0
  33. data/lib/tinkerforge/ip_connection.rb +1027 -0
  34. data/lib/tinkerforge/version.rb +4 -0
  35. metadata +98 -0
@@ -0,0 +1,274 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
6
+ # #
7
+ # If you have a bugfix for this file and want to commit it, #
8
+ # please fix the bug in the generator. You can find a link #
9
+ # to the generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for sensing current of up to 25A
14
+ class BrickletCurrent25 < Device
15
+ DEVICE_IDENTIFIER = 24 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletCurrent25#set_current_callback_period. The parameter is the current of the
19
+ # sensor.
20
+ #
21
+ # CALLBACK_CURRENT is only triggered if the current has changed since the
22
+ # last triggering.
23
+ CALLBACK_CURRENT = 15
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletCurrent25#set_analog_value_callback_period. The parameter is the analog value of the
27
+ # sensor.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the current has changed since the
30
+ # last triggering.
31
+ CALLBACK_ANALOG_VALUE = 16
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletCurrent25#set_current_callback_threshold is reached.
35
+ # The parameter is the current of the sensor.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletCurrent25#set_debounce_period.
39
+ CALLBACK_CURRENT_REACHED = 17
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletCurrent25#set_analog_value_callback_threshold is reached.
43
+ # The parameter is the analog value of the sensor.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletCurrent25#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 18
48
+
49
+ # This callback is triggered when an over current is measured
50
+ # (see BrickletCurrent25#is_over_current).
51
+ CALLBACK_OVER_CURRENT = 19
52
+
53
+ FUNCTION_GET_CURRENT = 1 # :nodoc:
54
+ FUNCTION_CALIBRATE = 2 # :nodoc:
55
+ FUNCTION_IS_OVER_CURRENT = 3 # :nodoc:
56
+ FUNCTION_GET_ANALOG_VALUE = 4 # :nodoc:
57
+ FUNCTION_SET_CURRENT_CALLBACK_PERIOD = 5 # :nodoc:
58
+ FUNCTION_GET_CURRENT_CALLBACK_PERIOD = 6 # :nodoc:
59
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 7 # :nodoc:
60
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 8 # :nodoc:
61
+ FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD = 9 # :nodoc:
62
+ FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD = 10 # :nodoc:
63
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 11 # :nodoc:
64
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 12 # :nodoc:
65
+ FUNCTION_SET_DEBOUNCE_PERIOD = 13 # :nodoc:
66
+ FUNCTION_GET_DEBOUNCE_PERIOD = 14 # :nodoc:
67
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
68
+
69
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
70
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
71
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
72
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
73
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
74
+
75
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
76
+ # the IP Connection <tt>ipcon</tt>.
77
+ def initialize(uid, ipcon)
78
+ super uid, ipcon
79
+
80
+ @api_version = [2, 0, 0]
81
+
82
+ @response_expected[FUNCTION_GET_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
83
+ @response_expected[FUNCTION_CALIBRATE] = RESPONSE_EXPECTED_FALSE
84
+ @response_expected[FUNCTION_IS_OVER_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
85
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_SET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
87
+ @response_expected[FUNCTION_GET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
88
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
89
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
90
+ @response_expected[FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
91
+ @response_expected[FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
92
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
93
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
94
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
95
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
96
+ @response_expected[CALLBACK_CURRENT] = RESPONSE_EXPECTED_ALWAYS_FALSE
97
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
98
+ @response_expected[CALLBACK_CURRENT_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
99
+ @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
100
+ @response_expected[CALLBACK_OVER_CURRENT] = RESPONSE_EXPECTED_ALWAYS_FALSE
101
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
102
+
103
+ @callback_formats[CALLBACK_CURRENT] = 's'
104
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
105
+ @callback_formats[CALLBACK_CURRENT_REACHED] = 's'
106
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
107
+ @callback_formats[CALLBACK_OVER_CURRENT] = ''
108
+ end
109
+
110
+ # Returns the current of the sensor. The value is in mA
111
+ # and between -25000mA and 25000mA.
112
+ #
113
+ # If you want to get the current periodically, it is recommended to use the
114
+ # callback CALLBACK_CURRENT and set the period with
115
+ # BrickletCurrent25#set_current_callback_period.
116
+ def get_current
117
+ send_request(FUNCTION_GET_CURRENT, [], '', 2, 's')
118
+ end
119
+
120
+ # Calibrates the 0 value of the sensor. You have to call this function
121
+ # when there is no current present.
122
+ #
123
+ # The zero point of the current sensor
124
+ # is depending on the exact properties of the analog-to-digital converter,
125
+ # the length of the Bricklet cable and the temperature. Thus, if you change
126
+ # the Brick or the environment in which the Bricklet is used, you might
127
+ # have to recalibrate.
128
+ #
129
+ # The resulting calibration will be saved on the EEPROM of the Current
130
+ # Bricklet.
131
+ def calibrate
132
+ send_request(FUNCTION_CALIBRATE, [], '', 0, '')
133
+ end
134
+
135
+ # Returns *true* if more than 25A were measured.
136
+ #
137
+ # .. note::
138
+ # To reset this value you have to power cycle the Bricklet.
139
+ def is_over_current
140
+ send_request(FUNCTION_IS_OVER_CURRENT, [], '', 1, '?')
141
+ end
142
+
143
+ # Returns the value as read by a 12-bit analog-to-digital converter.
144
+ # The value is between 0 and 4095.
145
+ #
146
+ # .. note::
147
+ # The value returned by BrickletCurrent25#get_current is averaged over several samples
148
+ # to yield less noise, while BrickletCurrent25#get_analog_value gives back raw
149
+ # unfiltered analog values. The only reason to use BrickletCurrent25#get_analog_value is,
150
+ # if you need the full resolution of the analog-to-digital converter.
151
+ #
152
+ # If you want the analog value periodically, it is recommended to use the
153
+ # callback CALLBACK_ANALOG_VALUE and set the period with
154
+ # BrickletCurrent25#set_analog_value_callback_period.
155
+ def get_analog_value
156
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S')
157
+ end
158
+
159
+ # Sets the period in ms with which the CALLBACK_CURRENT callback is triggered
160
+ # periodically. A value of 0 turns the callback off.
161
+ #
162
+ # CALLBACK_CURRENT is only triggered if the current has changed since the
163
+ # last triggering.
164
+ #
165
+ # The default value is 0.
166
+ def set_current_callback_period(period)
167
+ send_request(FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 0, '')
168
+ end
169
+
170
+ # Returns the period as set by BrickletCurrent25#set_current_callback_period.
171
+ def get_current_callback_period
172
+ send_request(FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 4, 'L')
173
+ end
174
+
175
+ # Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered
176
+ # periodically. A value of 0 turns the callback off.
177
+ #
178
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
179
+ # last triggering.
180
+ #
181
+ # The default value is 0.
182
+ def set_analog_value_callback_period(period)
183
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '')
184
+ end
185
+
186
+ # Returns the period as set by BrickletCurrent25#set_analog_value_callback_period.
187
+ def get_analog_value_callback_period
188
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L')
189
+ end
190
+
191
+ # Sets the thresholds for the CALLBACK_CURRENT_REACHED callback.
192
+ #
193
+ # The following options are possible:
194
+ #
195
+ # "Option", "Description"
196
+ #
197
+ # "'x'", "Callback is turned off"
198
+ # "'o'", "Callback is triggered when the current is *outside* the min and max values"
199
+ # "'i'", "Callback is triggered when the current is *inside* the min and max values"
200
+ # "'<'", "Callback is triggered when the current is smaller than the min value (max is ignored)"
201
+ # "'>'", "Callback is triggered when the current is greater than the min value (max is ignored)"
202
+ #
203
+ # The default value is ('x', 0, 0).
204
+ def set_current_callback_threshold(option, min, max)
205
+ send_request(FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
206
+ end
207
+
208
+ # Returns the threshold as set by BrickletCurrent25#set_current_callback_threshold.
209
+ def get_current_callback_threshold
210
+ send_request(FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
211
+ end
212
+
213
+ # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
214
+ #
215
+ # The following options are possible:
216
+ #
217
+ # "Option", "Description"
218
+ #
219
+ # "'x'", "Callback is turned off"
220
+ # "'o'", "Callback is triggered when the analog value is *outside* the min and max values"
221
+ # "'i'", "Callback is triggered when the analog value is *inside* the min and max values"
222
+ # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
223
+ # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
224
+ #
225
+ # The default value is ('x', 0, 0).
226
+ def set_analog_value_callback_threshold(option, min, max)
227
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
228
+ end
229
+
230
+ # Returns the threshold as set by BrickletCurrent25#set_analog_value_callback_threshold.
231
+ def get_analog_value_callback_threshold
232
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
233
+ end
234
+
235
+ # Sets the period in ms with which the threshold callbacks
236
+ #
237
+ # CALLBACK_CURRENT_REACHED, CALLBACK_ANALOG_VALUE_REACHED
238
+ #
239
+ # are triggered, if the thresholds
240
+ #
241
+ # BrickletCurrent25#set_current_callback_threshold, BrickletCurrent25#set_analog_value_callback_threshold
242
+ #
243
+ # keep being reached.
244
+ #
245
+ # The default value is 100.
246
+ def set_debounce_period(debounce)
247
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
248
+ end
249
+
250
+ # Returns the debounce period as set by BrickletCurrent25#set_debounce_period.
251
+ def get_debounce_period
252
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
253
+ end
254
+
255
+ # Returns the UID, the UID where the Bricklet is connected to,
256
+ # the position, the hardware and firmware version as well as the
257
+ # device identifier.
258
+ #
259
+ # The position can be 'a', 'b', 'c' or 'd'.
260
+ #
261
+ # The device identifiers can be found :ref:`here <device_identifier>`.
262
+ #
263
+ # .. versionadded:: 2.0.0~(Plugin)
264
+ def get_identity
265
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
266
+ end
267
+
268
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
269
+ def register_callback(id, &block)
270
+ callback = block
271
+ @registered_callbacks[id] = callback
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,274 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
6
+ # #
7
+ # If you have a bugfix for this file and want to commit it, #
8
+ # please fix the bug in the generator. You can find a link #
9
+ # to the generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for sensing distance via infrared
14
+ class BrickletDistanceIR < Device
15
+ DEVICE_IDENTIFIER = 25 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletDistanceIR#set_distance_callback_period. The parameter is the distance of the
19
+ # sensor.
20
+ #
21
+ # CALLBACK_DISTANCE is only triggered if the distance has changed since the
22
+ # last triggering.
23
+ CALLBACK_DISTANCE = 15
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletDistanceIR#set_analog_value_callback_period. The parameter is the analog value of the
27
+ # sensor.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
30
+ # last triggering.
31
+ CALLBACK_ANALOG_VALUE = 16
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletDistanceIR#set_distance_callback_threshold is reached.
35
+ # The parameter is the distance of the sensor.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletDistanceIR#set_debounce_period.
39
+ CALLBACK_DISTANCE_REACHED = 17
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletDistanceIR#set_analog_value_callback_threshold is reached.
43
+ # The parameter is the analog value of the sensor.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletDistanceIR#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 18
48
+
49
+ FUNCTION_GET_DISTANCE = 1 # :nodoc:
50
+ FUNCTION_GET_ANALOG_VALUE = 2 # :nodoc:
51
+ FUNCTION_SET_SAMPLING_POINT = 3 # :nodoc:
52
+ FUNCTION_GET_SAMPLING_POINT = 4 # :nodoc:
53
+ FUNCTION_SET_DISTANCE_CALLBACK_PERIOD = 5 # :nodoc:
54
+ FUNCTION_GET_DISTANCE_CALLBACK_PERIOD = 6 # :nodoc:
55
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 7 # :nodoc:
56
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 8 # :nodoc:
57
+ FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD = 9 # :nodoc:
58
+ FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD = 10 # :nodoc:
59
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 11 # :nodoc:
60
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 12 # :nodoc:
61
+ FUNCTION_SET_DEBOUNCE_PERIOD = 13 # :nodoc:
62
+ FUNCTION_GET_DEBOUNCE_PERIOD = 14 # :nodoc:
63
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
64
+
65
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
66
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
67
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
68
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
69
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
70
+
71
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
72
+ # the IP Connection <tt>ipcon</tt>.
73
+ def initialize(uid, ipcon)
74
+ super uid, ipcon
75
+
76
+ @api_version = [2, 0, 0]
77
+
78
+ @response_expected[FUNCTION_GET_DISTANCE] = RESPONSE_EXPECTED_ALWAYS_TRUE
79
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
80
+ @response_expected[FUNCTION_SET_SAMPLING_POINT] = RESPONSE_EXPECTED_FALSE
81
+ @response_expected[FUNCTION_GET_SAMPLING_POINT] = RESPONSE_EXPECTED_ALWAYS_TRUE
82
+ @response_expected[FUNCTION_SET_DISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
83
+ @response_expected[FUNCTION_GET_DISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
84
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
85
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
87
+ @response_expected[FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
88
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
89
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
90
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
91
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
92
+ @response_expected[CALLBACK_DISTANCE] = RESPONSE_EXPECTED_ALWAYS_FALSE
93
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
94
+ @response_expected[CALLBACK_DISTANCE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
95
+ @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
96
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
97
+
98
+ @callback_formats[CALLBACK_DISTANCE] = 'S'
99
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
100
+ @callback_formats[CALLBACK_DISTANCE_REACHED] = 'S'
101
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
102
+ end
103
+
104
+ # Returns the distance measured by the sensor. The value is in mm and possible
105
+ # distance ranges are 40 to 300, 100 to 800 and 200 to 1500, depending on the
106
+ # selected IR sensor.
107
+ #
108
+ # If you want to get the distance periodically, it is recommended to use the
109
+ # callback CALLBACK_DISTANCE and set the period with
110
+ # BrickletDistanceIR#set_distance_callback_period.
111
+ def get_distance
112
+ send_request(FUNCTION_GET_DISTANCE, [], '', 2, 'S')
113
+ end
114
+
115
+ # Returns the value as read by a 12-bit analog-to-digital converter.
116
+ # The value is between 0 and 4095.
117
+ #
118
+ # .. note::
119
+ # The value returned by BrickletDistanceIR#get_distance is averaged over several samples
120
+ # to yield less noise, while BrickletDistanceIR#get_analog_value gives back raw
121
+ # unfiltered analog values. The only reason to use BrickletDistanceIR#get_analog_value is,
122
+ # if you need the full resolution of the analog-to-digital converter.
123
+ #
124
+ # If you want the analog value periodically, it is recommended to use the
125
+ # callback CALLBACK_ANALOG_VALUE and set the period with
126
+ # BrickletDistanceIR#set_analog_value_callback_period.
127
+ def get_analog_value
128
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S')
129
+ end
130
+
131
+ # Sets a sampling point value to a specific position of the lookup table.
132
+ # The lookup table comprises 128 equidistant analog values with
133
+ # corresponding distances.
134
+ #
135
+ # If you measure a distance of 50cm at the analog value 2048, you
136
+ # should call this function with (64, 5000). The utilized analog-to-digital
137
+ # converter has a resolution of 12 bit. With 128 sampling points on the
138
+ # whole range, this means that every sampling point has a size of 32
139
+ # analog values. Thus the analog value 2048 has the corresponding sampling
140
+ # point 64 = 2048/32.
141
+ #
142
+ # Sampling points are saved on the EEPROM of the Distance IR Bricklet and
143
+ # loaded again on startup.
144
+ #
145
+ # .. note::
146
+ # An easy way to calibrate the sampling points of the Distance IR Bricklet is
147
+ # implemented in the Brick Viewer. If you want to calibrate your Bricklet it is
148
+ # highly recommended to use this implementation.
149
+ def set_sampling_point(position, distance)
150
+ send_request(FUNCTION_SET_SAMPLING_POINT, [position, distance], 'C S', 0, '')
151
+ end
152
+
153
+ # Returns the distance to a sampling point position as set by
154
+ # BrickletDistanceIR#set_sampling_point.
155
+ def get_sampling_point(position)
156
+ send_request(FUNCTION_GET_SAMPLING_POINT, [position], 'C', 2, 'S')
157
+ end
158
+
159
+ # Sets the period in ms with which the CALLBACK_DISTANCE callback is triggered
160
+ # periodically. A value of 0 turns the callback off.
161
+ #
162
+ # CALLBACK_DISTANCE is only triggered if the distance has changed since the
163
+ # last triggering.
164
+ #
165
+ # The default value is 0.
166
+ def set_distance_callback_period(period)
167
+ send_request(FUNCTION_SET_DISTANCE_CALLBACK_PERIOD, [period], 'L', 0, '')
168
+ end
169
+
170
+ # Returns the period as set by BrickletDistanceIR#set_distance_callback_period.
171
+ def get_distance_callback_period
172
+ send_request(FUNCTION_GET_DISTANCE_CALLBACK_PERIOD, [], '', 4, 'L')
173
+ end
174
+
175
+ # Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered
176
+ # periodically. A value of 0 turns the callback off.
177
+ #
178
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
179
+ # last triggering.
180
+ #
181
+ # The default value is 0.
182
+ def set_analog_value_callback_period(period)
183
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '')
184
+ end
185
+
186
+ # Returns the period as set by BrickletDistanceIR#set_analog_value_callback_period.
187
+ def get_analog_value_callback_period
188
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L')
189
+ end
190
+
191
+ # Sets the thresholds for the CALLBACK_DISTANCE_REACHED callback.
192
+ #
193
+ # The following options are possible:
194
+ #
195
+ # "Option", "Description"
196
+ #
197
+ # "'x'", "Callback is turned off"
198
+ # "'o'", "Callback is triggered when the distance is *outside* the min and max values"
199
+ # "'i'", "Callback is triggered when the distance is *inside* the min and max values"
200
+ # "'<'", "Callback is triggered when the distance is smaller than the min value (max is ignored)"
201
+ # "'>'", "Callback is triggered when the distance is greater than the min value (max is ignored)"
202
+ #
203
+ # The default value is ('x', 0, 0).
204
+ def set_distance_callback_threshold(option, min, max)
205
+ send_request(FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
206
+ end
207
+
208
+ # Returns the threshold as set by BrickletDistanceIR#set_distance_callback_threshold.
209
+ def get_distance_callback_threshold
210
+ send_request(FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
211
+ end
212
+
213
+ # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
214
+ #
215
+ # The following options are possible:
216
+ #
217
+ # "Option", "Description"
218
+ #
219
+ # "'x'", "Callback is turned off"
220
+ # "'o'", "Callback is triggered when the analog value is *outside* the min and max values"
221
+ # "'i'", "Callback is triggered when the analog value is *inside* the min and max values"
222
+ # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
223
+ # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
224
+ #
225
+ # The default value is ('x', 0, 0).
226
+ def set_analog_value_callback_threshold(option, min, max)
227
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
228
+ end
229
+
230
+ # Returns the threshold as set by BrickletDistanceIR#set_analog_value_callback_threshold.
231
+ def get_analog_value_callback_threshold
232
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
233
+ end
234
+
235
+ # Sets the period in ms with which the threshold callbacks
236
+ #
237
+ # CALLBACK_DISTANCE_REACHED, CALLBACK_ANALOG_VALUE_REACHED
238
+ #
239
+ # are triggered, if the thresholds
240
+ #
241
+ # BrickletDistanceIR#set_distance_callback_threshold, BrickletDistanceIR#set_analog_value_callback_threshold
242
+ #
243
+ # keep being reached.
244
+ #
245
+ # The default value is 100.
246
+ def set_debounce_period(debounce)
247
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
248
+ end
249
+
250
+ # Returns the debounce period as set by BrickletDistanceIR#set_debounce_period.
251
+ def get_debounce_period
252
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
253
+ end
254
+
255
+ # Returns the UID, the UID where the Bricklet is connected to,
256
+ # the position, the hardware and firmware version as well as the
257
+ # device identifier.
258
+ #
259
+ # The position can be 'a', 'b', 'c' or 'd'.
260
+ #
261
+ # The device identifiers can be found :ref:`here <device_identifier>`.
262
+ #
263
+ # .. versionadded:: 2.0.0~(Plugin)
264
+ def get_identity
265
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
266
+ end
267
+
268
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
269
+ def register_callback(id, &block)
270
+ callback = block
271
+ @registered_callbacks[id] = callback
272
+ end
273
+ end
274
+ end