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,475 @@
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 controlling up to seven servos
14
+ class BrickServo < Device
15
+ DEVICE_IDENTIFIER = 14 # :nodoc:
16
+
17
+ # This callback is triggered when the input voltage drops below the value set by
18
+ # BrickServo#set_minimum_voltage. The parameter is the current voltage given
19
+ # in mV.
20
+ CALLBACK_UNDER_VOLTAGE = 26
21
+
22
+ # This callback is triggered when a position set by BrickServo#set_position
23
+ # is reached. The parameters are the servo and the position that is reached.
24
+ #
25
+ # You can enable this callback with BrickServo#enable_position_reached_callback.
26
+ #
27
+ # .. note::
28
+ # Since we can't get any feedback from the servo, this only works if the
29
+ # velocity (see BrickServo#set_velocity) is set smaller or equal to the
30
+ # maximum velocity of the servo. Otherwise the servo will lag behind the
31
+ # control value and the callback will be triggered too early.
32
+ CALLBACK_POSITION_REACHED = 27
33
+
34
+ # This callback is triggered when a velocity set by BrickServo#set_velocity
35
+ # is reached. The parameters are the servo and the velocity that is reached.
36
+ #
37
+ # You can enable this callback with BrickServo#enable_velocity_reached_callback.
38
+ #
39
+ # .. note::
40
+ # Since we can't get any feedback from the servo, this only works if the
41
+ # acceleration (see BrickServo#set_acceleration) is set smaller or equal to the
42
+ # maximum acceleration of the servo. Otherwise the servo will lag behind the
43
+ # control value and the callback will be triggered too early.
44
+ CALLBACK_VELOCITY_REACHED = 28
45
+
46
+ FUNCTION_ENABLE = 1 # :nodoc:
47
+ FUNCTION_DISABLE = 2 # :nodoc:
48
+ FUNCTION_IS_ENABLED = 3 # :nodoc:
49
+ FUNCTION_SET_POSITION = 4 # :nodoc:
50
+ FUNCTION_GET_POSITION = 5 # :nodoc:
51
+ FUNCTION_GET_CURRENT_POSITION = 6 # :nodoc:
52
+ FUNCTION_SET_VELOCITY = 7 # :nodoc:
53
+ FUNCTION_GET_VELOCITY = 8 # :nodoc:
54
+ FUNCTION_GET_CURRENT_VELOCITY = 9 # :nodoc:
55
+ FUNCTION_SET_ACCELERATION = 10 # :nodoc:
56
+ FUNCTION_GET_ACCELERATION = 11 # :nodoc:
57
+ FUNCTION_SET_OUTPUT_VOLTAGE = 12 # :nodoc:
58
+ FUNCTION_GET_OUTPUT_VOLTAGE = 13 # :nodoc:
59
+ FUNCTION_SET_PULSE_WIDTH = 14 # :nodoc:
60
+ FUNCTION_GET_PULSE_WIDTH = 15 # :nodoc:
61
+ FUNCTION_SET_DEGREE = 16 # :nodoc:
62
+ FUNCTION_GET_DEGREE = 17 # :nodoc:
63
+ FUNCTION_SET_PERIOD = 18 # :nodoc:
64
+ FUNCTION_GET_PERIOD = 19 # :nodoc:
65
+ FUNCTION_GET_SERVO_CURRENT = 20 # :nodoc:
66
+ FUNCTION_GET_OVERALL_CURRENT = 21 # :nodoc:
67
+ FUNCTION_GET_STACK_INPUT_VOLTAGE = 22 # :nodoc:
68
+ FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE = 23 # :nodoc:
69
+ FUNCTION_SET_MINIMUM_VOLTAGE = 24 # :nodoc:
70
+ FUNCTION_GET_MINIMUM_VOLTAGE = 25 # :nodoc:
71
+ FUNCTION_ENABLE_POSITION_REACHED_CALLBACK = 29 # :nodoc:
72
+ FUNCTION_DISABLE_POSITION_REACHED_CALLBACK = 30 # :nodoc:
73
+ FUNCTION_IS_POSITION_REACHED_CALLBACK_ENABLED = 31 # :nodoc:
74
+ FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK = 32 # :nodoc:
75
+ FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK = 33 # :nodoc:
76
+ FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED = 34 # :nodoc:
77
+ FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
78
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
79
+ FUNCTION_RESET = 243 # :nodoc:
80
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
81
+
82
+
83
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
84
+ # the IP Connection <tt>ipcon</tt>.
85
+ def initialize(uid, ipcon)
86
+ super uid, ipcon
87
+
88
+ @api_version = [2, 0, 0]
89
+
90
+ @response_expected[FUNCTION_ENABLE] = RESPONSE_EXPECTED_FALSE
91
+ @response_expected[FUNCTION_DISABLE] = RESPONSE_EXPECTED_FALSE
92
+ @response_expected[FUNCTION_IS_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
93
+ @response_expected[FUNCTION_SET_POSITION] = RESPONSE_EXPECTED_FALSE
94
+ @response_expected[FUNCTION_GET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
95
+ @response_expected[FUNCTION_GET_CURRENT_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
96
+ @response_expected[FUNCTION_SET_VELOCITY] = RESPONSE_EXPECTED_FALSE
97
+ @response_expected[FUNCTION_GET_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
98
+ @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
99
+ @response_expected[FUNCTION_SET_ACCELERATION] = RESPONSE_EXPECTED_FALSE
100
+ @response_expected[FUNCTION_GET_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
101
+ @response_expected[FUNCTION_SET_OUTPUT_VOLTAGE] = RESPONSE_EXPECTED_FALSE
102
+ @response_expected[FUNCTION_GET_OUTPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+ @response_expected[FUNCTION_SET_PULSE_WIDTH] = RESPONSE_EXPECTED_FALSE
104
+ @response_expected[FUNCTION_GET_PULSE_WIDTH] = RESPONSE_EXPECTED_ALWAYS_TRUE
105
+ @response_expected[FUNCTION_SET_DEGREE] = RESPONSE_EXPECTED_FALSE
106
+ @response_expected[FUNCTION_GET_DEGREE] = RESPONSE_EXPECTED_ALWAYS_TRUE
107
+ @response_expected[FUNCTION_SET_PERIOD] = RESPONSE_EXPECTED_FALSE
108
+ @response_expected[FUNCTION_GET_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
109
+ @response_expected[FUNCTION_GET_SERVO_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
110
+ @response_expected[FUNCTION_GET_OVERALL_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
111
+ @response_expected[FUNCTION_GET_STACK_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
112
+ @response_expected[FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
113
+ @response_expected[FUNCTION_SET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_TRUE
114
+ @response_expected[FUNCTION_GET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
115
+ @response_expected[CALLBACK_UNDER_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_FALSE
116
+ @response_expected[CALLBACK_POSITION_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
117
+ @response_expected[CALLBACK_VELOCITY_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
118
+ @response_expected[FUNCTION_ENABLE_POSITION_REACHED_CALLBACK] = RESPONSE_EXPECTED_TRUE
119
+ @response_expected[FUNCTION_DISABLE_POSITION_REACHED_CALLBACK] = RESPONSE_EXPECTED_TRUE
120
+ @response_expected[FUNCTION_IS_POSITION_REACHED_CALLBACK_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
121
+ @response_expected[FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK] = RESPONSE_EXPECTED_TRUE
122
+ @response_expected[FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK] = RESPONSE_EXPECTED_TRUE
123
+ @response_expected[FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
124
+ @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
125
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
126
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
127
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
128
+
129
+ @callback_formats[CALLBACK_UNDER_VOLTAGE] = 'S'
130
+ @callback_formats[CALLBACK_POSITION_REACHED] = 'C s'
131
+ @callback_formats[CALLBACK_VELOCITY_REACHED] = 'C s'
132
+ end
133
+
134
+ # Enables a servo (0 to 6). If a servo is enabled, the configured position,
135
+ # velocity, acceleration, etc. are applied immediately.
136
+ def enable(servo_num)
137
+ send_request(FUNCTION_ENABLE, [servo_num], 'C', 0, '')
138
+ end
139
+
140
+ # Disables a servo (0 to 6). Disabled servos are not driven at all, i.e. a
141
+ # disabled servo will not hold its position if a load is applied.
142
+ def disable(servo_num)
143
+ send_request(FUNCTION_DISABLE, [servo_num], 'C', 0, '')
144
+ end
145
+
146
+ # Returns *true* if the specified servo is enabled, *false* otherwise.
147
+ def is_enabled(servo_num)
148
+ send_request(FUNCTION_IS_ENABLED, [servo_num], 'C', 1, '?')
149
+ end
150
+
151
+ # Sets the position in °/100 for the specified servo.
152
+ #
153
+ # The default range of the position is -9000 to 9000, but it can be specified
154
+ # according to your servo with BrickServo#set_degree.
155
+ #
156
+ # If you want to control a linear servo or RC brushless motor controller or
157
+ # similar with the Servo Brick, you can also define lengths or speeds with
158
+ # BrickServo#set_degree.
159
+ def set_position(servo_num, position)
160
+ send_request(FUNCTION_SET_POSITION, [servo_num, position], 'C s', 0, '')
161
+ end
162
+
163
+ # Returns the position of the specified servo as set by BrickServo#set_position.
164
+ def get_position(servo_num)
165
+ send_request(FUNCTION_GET_POSITION, [servo_num], 'C', 2, 's')
166
+ end
167
+
168
+ # Returns the *current* position of the specified servo. This may not be the
169
+ # value of BrickServo#set_position if the servo is currently approaching a
170
+ # position goal.
171
+ def get_current_position(servo_num)
172
+ send_request(FUNCTION_GET_CURRENT_POSITION, [servo_num], 'C', 2, 's')
173
+ end
174
+
175
+ # Sets the maximum velocity of the specified servo in °/100s. The velocity
176
+ # is accelerated according to the value set by BrickServo#set_acceleration.
177
+ #
178
+ # The minimum velocity is 0 (no movement) and the maximum velocity is 65535.
179
+ # With a value of 65535 the position will be set immediately (no velocity).
180
+ #
181
+ # The default value is 65535.
182
+ def set_velocity(servo_num, velocity)
183
+ send_request(FUNCTION_SET_VELOCITY, [servo_num, velocity], 'C S', 0, '')
184
+ end
185
+
186
+ # Returns the velocity of the specified servo as set by BrickServo#set_velocity.
187
+ def get_velocity(servo_num)
188
+ send_request(FUNCTION_GET_VELOCITY, [servo_num], 'C', 2, 'S')
189
+ end
190
+
191
+ # Returns the *current* velocity of the specified servo. This may not be the
192
+ # value of BrickServo#set_velocity if the servo is currently approaching a
193
+ # velocity goal.
194
+ def get_current_velocity(servo_num)
195
+ send_request(FUNCTION_GET_CURRENT_VELOCITY, [servo_num], 'C', 2, 'S')
196
+ end
197
+
198
+ # Sets the acceleration of the specified servo in °/100s².
199
+ #
200
+ # The minimum acceleration is 1 and the maximum acceleration is 65535.
201
+ # With a value of 65535 the velocity will be set immediately (no acceleration).
202
+ #
203
+ # The default value is 65535.
204
+ def set_acceleration(servo_num, acceleration)
205
+ send_request(FUNCTION_SET_ACCELERATION, [servo_num, acceleration], 'C S', 0, '')
206
+ end
207
+
208
+ # Returns the acceleration for the specified servo as set by
209
+ # BrickServo#set_acceleration.
210
+ def get_acceleration(servo_num)
211
+ send_request(FUNCTION_GET_ACCELERATION, [servo_num], 'C', 2, 'S')
212
+ end
213
+
214
+ # Sets the output voltages with which the servos are driven in mV.
215
+ # The minimum output voltage is 5000mV and the maximum output voltage is
216
+ # 9000mV.
217
+ #
218
+ # .. note::
219
+ # We recommend that you set this value to the maximum voltage that is
220
+ # specified for your servo, most servos achieve their maximum force only
221
+ # with high voltages.
222
+ #
223
+ # The default value is 5000.
224
+ def set_output_voltage(voltage)
225
+ send_request(FUNCTION_SET_OUTPUT_VOLTAGE, [voltage], 'S', 0, '')
226
+ end
227
+
228
+ # Returns the output voltage as specified by BrickServo#set_output_voltage.
229
+ def get_output_voltage
230
+ send_request(FUNCTION_GET_OUTPUT_VOLTAGE, [], '', 2, 'S')
231
+ end
232
+
233
+ # Sets the minimum and maximum pulse width of the specified servo in µs.
234
+ #
235
+ # Usually, servos are controlled with a
236
+ # `PWM <http://en.wikipedia.org/wiki/Pulse-width_modulation>`__, whereby the
237
+ # length of the pulse controls the position of the servo. Every servo has
238
+ # different minimum and maximum pulse widths, these can be specified with
239
+ # this function.
240
+ #
241
+ # If you have a datasheet for your servo that specifies the minimum and
242
+ # maximum pulse width, you should set the values accordingly. If your servo
243
+ # comes without any datasheet you have to find the values via trial and error.
244
+ #
245
+ # Both values have a range from 1 to 65535 (unsigned 16-bit integer). The
246
+ # minimum must be smaller than the maximum.
247
+ #
248
+ # The default values are 1000µs (1ms) and 2000µs (2ms) for minimum and
249
+ # maximum pulse width.
250
+ def set_pulse_width(servo_num, min, max)
251
+ send_request(FUNCTION_SET_PULSE_WIDTH, [servo_num, min, max], 'C S S', 0, '')
252
+ end
253
+
254
+ # Returns the minimum and maximum pulse width for the specified servo as set by
255
+ # BrickServo#set_pulse_width.
256
+ def get_pulse_width(servo_num)
257
+ send_request(FUNCTION_GET_PULSE_WIDTH, [servo_num], 'C', 4, 'S S')
258
+ end
259
+
260
+ # Sets the minimum and maximum degree for the specified servo (by default
261
+ # given as °/100).
262
+ #
263
+ # This only specifies the abstract values between which the minimum and maximum
264
+ # pulse width is scaled. For example: If you specify a pulse width of 1000µs
265
+ # to 2000µs and a degree range of -90° to 90°, a call of BrickServo#set_position
266
+ # with 0 will result in a pulse width of 1500µs
267
+ # (-90° = 1000µs, 90° = 2000µs, etc.).
268
+ #
269
+ # Possible usage:
270
+ #
271
+ # * The datasheet of your servo specifies a range of 200° with the middle position
272
+ # at 110°. In this case you can set the minimum to -9000 and the maximum to 11000.
273
+ # * You measure a range of 220° on your servo and you don't have or need a middle
274
+ # position. In this case you can set the minimum to 0 and the maximum to 22000.
275
+ # * You have a linear servo with a drive length of 20cm, In this case you could
276
+ # set the minimum to 0 and the maximum to 20000. Now you can set the Position
277
+ # with BrickServo#set_position with a resolution of cm/100. Also the velocity will
278
+ # have a resolution of cm/100s and the acceleration will have a resolution of
279
+ # cm/100s².
280
+ # * You don't care about units and just want the highest possible resolution. In
281
+ # this case you should set the minimum to -32767 and the maximum to 32767.
282
+ # * You have a brushless motor with a maximum speed of 10000 rpm and want to
283
+ # control it with a RC brushless motor controller. In this case you can set the
284
+ # minimum to 0 and the maximum to 10000. BrickServo#set_position now controls the rpm.
285
+ #
286
+ # Both values have a possible range from -32767 to 32767
287
+ # (signed 16-bit integer). The minimum must be smaller than the maximum.
288
+ #
289
+ # The default values are -9000 and 9000 for the minimum and maximum degree.
290
+ def set_degree(servo_num, min, max)
291
+ send_request(FUNCTION_SET_DEGREE, [servo_num, min, max], 'C s s', 0, '')
292
+ end
293
+
294
+ # Returns the minimum and maximum degree for the specified servo as set by
295
+ # BrickServo#set_degree.
296
+ def get_degree(servo_num)
297
+ send_request(FUNCTION_GET_DEGREE, [servo_num], 'C', 4, 's s')
298
+ end
299
+
300
+ # Sets the period of the specified servo in µs.
301
+ #
302
+ # Usually, servos are controlled with a
303
+ # `PWM <http://en.wikipedia.org/wiki/Pulse-width_modulation>`__. Different
304
+ # servos expect PWMs with different periods. Most servos run well with a
305
+ # period of about 20ms.
306
+ #
307
+ # If your servo comes with a datasheet that specifies a period, you should
308
+ # set it accordingly. If you don't have a datasheet and you have no idea
309
+ # what the correct period is, the default value (19.5ms) will most likely
310
+ # work fine.
311
+ #
312
+ # The minimum possible period is 2000µs and the maximum is 65535µs.
313
+ #
314
+ # The default value is 19.5ms (19500µs).
315
+ def set_period(servo_num, period)
316
+ send_request(FUNCTION_SET_PERIOD, [servo_num, period], 'C S', 0, '')
317
+ end
318
+
319
+ # Returns the period for the specified servo as set by BrickServo#set_period.
320
+ def get_period(servo_num)
321
+ send_request(FUNCTION_GET_PERIOD, [servo_num], 'C', 2, 'S')
322
+ end
323
+
324
+ # Returns the current consumption of the specified servo in mA.
325
+ def get_servo_current(servo_num)
326
+ send_request(FUNCTION_GET_SERVO_CURRENT, [servo_num], 'C', 2, 'S')
327
+ end
328
+
329
+ # Returns the current consumption of all servos together in mA.
330
+ def get_overall_current
331
+ send_request(FUNCTION_GET_OVERALL_CURRENT, [], '', 2, 'S')
332
+ end
333
+
334
+ # Returns the stack input voltage in mV. The stack input voltage is the
335
+ # voltage that is supplied via the stack, i.e. it is given by a
336
+ # Step-Down or Step-Up Power Supply.
337
+ def get_stack_input_voltage
338
+ send_request(FUNCTION_GET_STACK_INPUT_VOLTAGE, [], '', 2, 'S')
339
+ end
340
+
341
+ # Returns the external input voltage in mV. The external input voltage is
342
+ # given via the black power input connector on the Servo Brick.
343
+ #
344
+ # If there is an external input voltage and a stack input voltage, the motors
345
+ # will be driven by the external input voltage. If there is only a stack
346
+ # voltage present, the motors will be driven by this voltage.
347
+ #
348
+ # .. warning::
349
+ # This means, if you have a high stack voltage and a low external voltage,
350
+ # the motors will be driven with the low external voltage. If you then remove
351
+ # the external connection, it will immediately be driven by the high
352
+ # stack voltage
353
+ def get_external_input_voltage
354
+ send_request(FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE, [], '', 2, 'S')
355
+ end
356
+
357
+ # Sets the minimum voltage in mV, below which the CALLBACK_UNDER_VOLTAGE callback
358
+ # is triggered. The minimum possible value that works with the Servo Brick is 5V.
359
+ # You can use this function to detect the discharge of a battery that is used
360
+ # to drive the stepper motor. If you have a fixed power supply, you likely do
361
+ # not need this functionality.
362
+ #
363
+ # The default value is 5V (5000mV).
364
+ def set_minimum_voltage(voltage)
365
+ send_request(FUNCTION_SET_MINIMUM_VOLTAGE, [voltage], 'S', 0, '')
366
+ end
367
+
368
+ # Returns the minimum voltage as set by BrickServo#set_minimum_voltage
369
+ def get_minimum_voltage
370
+ send_request(FUNCTION_GET_MINIMUM_VOLTAGE, [], '', 2, 'S')
371
+ end
372
+
373
+ # Enables the CALLBACK_POSITION_REACHED callback.
374
+ #
375
+ # Default is disabled.
376
+ #
377
+ # .. versionadded:: 2.0.1~(Firmware)
378
+ def enable_position_reached_callback
379
+ send_request(FUNCTION_ENABLE_POSITION_REACHED_CALLBACK, [], '', 0, '')
380
+ end
381
+
382
+ # Disables the CALLBACK_POSITION_REACHED callback.
383
+ #
384
+ # Default is disabled.
385
+ #
386
+ # .. versionadded:: 2.0.1~(Firmware)
387
+ def disable_position_reached_callback
388
+ send_request(FUNCTION_DISABLE_POSITION_REACHED_CALLBACK, [], '', 0, '')
389
+ end
390
+
391
+ # Returns *true* if CALLBACK_POSITION_REACHED callback is enabled, *false* otherwise.
392
+ #
393
+ # .. versionadded:: 2.0.1~(Firmware)
394
+ def is_position_reached_callback_enabled
395
+ send_request(FUNCTION_IS_POSITION_REACHED_CALLBACK_ENABLED, [], '', 1, 'C')
396
+ end
397
+
398
+ # Enables the CALLBACK_VELOCITY_REACHED callback.
399
+ #
400
+ # Default is disabled.
401
+ #
402
+ # .. versionadded:: 2.0.1~(Firmware)
403
+ def enable_velocity_reached_callback
404
+ send_request(FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK, [], '', 0, '')
405
+ end
406
+
407
+ # Disables the CALLBACK_VELOCITY_REACHED callback.
408
+ #
409
+ # Default is disabled.
410
+ #
411
+ # .. versionadded:: 2.0.1~(Firmware)
412
+ def disable_velocity_reached_callback
413
+ send_request(FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK, [], '', 0, '')
414
+ end
415
+
416
+ # Returns *true* if CALLBACK_VELOCITY_REACHED callback is enabled, *false* otherwise.
417
+ #
418
+ # .. versionadded:: 2.0.1~(Firmware)
419
+ def is_velocity_reached_callback_enabled
420
+ send_request(FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED, [], '', 1, 'C')
421
+ end
422
+
423
+ # Returns the firmware and protocol version and the name of the Bricklet for a given port.
424
+ #
425
+ # This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet plugins.
426
+ #
427
+ # .. versionadded:: 2.0.0~(Firmware)
428
+ def get_protocol1_bricklet_name(port)
429
+ send_request(FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 44, 'C C3 Z40')
430
+ end
431
+
432
+ # Returns the temperature in °C/10 as measured inside the microcontroller. The
433
+ # value returned is not the ambient temperature!
434
+ #
435
+ # The temperature is only proportional to the real temperature and it has an
436
+ # accuracy of +-15%. Practically it is only useful as an indicator for
437
+ # temperature changes.
438
+ #
439
+ # .. versionadded:: 1.1.3~(Firmware)
440
+ def get_chip_temperature
441
+ send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
442
+ end
443
+
444
+ # Calling this function will reset the Brick. Calling this function
445
+ # on a Brick inside of a stack will reset the whole stack.
446
+ #
447
+ # After a reset you have to create new device objects,
448
+ # calling functions on the existing ones will result in
449
+ # undefined behavior!
450
+ #
451
+ # .. versionadded:: 1.1.3~(Firmware)
452
+ def reset
453
+ send_request(FUNCTION_RESET, [], '', 0, '')
454
+ end
455
+
456
+ # Returns the UID, the UID where the Brick is connected to,
457
+ # the position, the hardware and firmware version as well as the
458
+ # device identifier.
459
+ #
460
+ # The position can be '0'-'8' (stack position).
461
+ #
462
+ # The device identifiers can be found :ref:`here <device_identifier>`.
463
+ #
464
+ # .. versionadded:: 2.0.0~(Firmware)
465
+ def get_identity
466
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
467
+ end
468
+
469
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
470
+ def register_callback(id, &block)
471
+ callback = block
472
+ @registered_callbacks[id] = callback
473
+ end
474
+ end
475
+ end