tinkerforge 2.1.4 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. data/lib/tinkerforge/brick_dc.rb +42 -4
  2. data/lib/tinkerforge/brick_imu.rb +49 -11
  3. data/lib/tinkerforge/brick_imu_v2.rb +506 -0
  4. data/lib/tinkerforge/brick_master.rb +86 -46
  5. data/lib/tinkerforge/brick_red.rb +36 -5
  6. data/lib/tinkerforge/brick_servo.rb +53 -15
  7. data/lib/tinkerforge/brick_stepper.rb +43 -14
  8. data/lib/tinkerforge/bricklet_accelerometer.rb +229 -0
  9. data/lib/tinkerforge/bricklet_ambient_light.rb +10 -9
  10. data/lib/tinkerforge/bricklet_ambient_light_v2.rb +216 -0
  11. data/lib/tinkerforge/bricklet_analog_in.rb +13 -12
  12. data/lib/tinkerforge/bricklet_analog_in_v2.rb +259 -0
  13. data/lib/tinkerforge/bricklet_analog_out.rb +5 -4
  14. data/lib/tinkerforge/bricklet_analog_out_v2.rb +66 -0
  15. data/lib/tinkerforge/bricklet_barometer.rb +11 -9
  16. data/lib/tinkerforge/bricklet_color.rb +11 -9
  17. data/lib/tinkerforge/bricklet_current12.rb +5 -4
  18. data/lib/tinkerforge/bricklet_current25.rb +5 -4
  19. data/lib/tinkerforge/bricklet_distance_ir.rb +8 -7
  20. data/lib/tinkerforge/bricklet_distance_us.rb +9 -8
  21. data/lib/tinkerforge/bricklet_dual_button.rb +5 -4
  22. data/lib/tinkerforge/bricklet_dual_relay.rb +5 -4
  23. data/lib/tinkerforge/bricklet_dust_detector.rb +178 -0
  24. data/lib/tinkerforge/bricklet_gps.rb +6 -5
  25. data/lib/tinkerforge/bricklet_hall_effect.rb +5 -4
  26. data/lib/tinkerforge/bricklet_humidity.rb +8 -7
  27. data/lib/tinkerforge/bricklet_industrial_analog_out.rb +137 -0
  28. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +8 -7
  29. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +5 -4
  30. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +6 -5
  31. data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +209 -0
  32. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +5 -4
  33. data/lib/tinkerforge/bricklet_io16.rb +8 -7
  34. data/lib/tinkerforge/bricklet_io4.rb +8 -7
  35. data/lib/tinkerforge/bricklet_joystick.rb +5 -4
  36. data/lib/tinkerforge/bricklet_laser_range_finder.rb +324 -0
  37. data/lib/tinkerforge/bricklet_lcd_16x2.rb +7 -6
  38. data/lib/tinkerforge/bricklet_lcd_20x4.rb +11 -10
  39. data/lib/tinkerforge/bricklet_led_strip.rb +12 -10
  40. data/lib/tinkerforge/bricklet_line.rb +5 -4
  41. data/lib/tinkerforge/bricklet_linear_poti.rb +8 -7
  42. data/lib/tinkerforge/bricklet_load_cell.rb +261 -0
  43. data/lib/tinkerforge/bricklet_moisture.rb +6 -5
  44. data/lib/tinkerforge/bricklet_motion_detector.rb +5 -4
  45. data/lib/tinkerforge/bricklet_multi_touch.rb +5 -4
  46. data/lib/tinkerforge/bricklet_nfc_rfid.rb +38 -46
  47. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +5 -4
  48. data/lib/tinkerforge/bricklet_piezo_speaker.rb +6 -5
  49. data/lib/tinkerforge/bricklet_ptc.rb +5 -4
  50. data/lib/tinkerforge/bricklet_remote_switch.rb +9 -8
  51. data/lib/tinkerforge/bricklet_rotary_encoder.rb +5 -4
  52. data/lib/tinkerforge/bricklet_rotary_poti.rb +5 -4
  53. data/lib/tinkerforge/bricklet_rs232.rb +183 -0
  54. data/lib/tinkerforge/bricklet_segment_display_4x7.rb +8 -5
  55. data/lib/tinkerforge/bricklet_solid_state_relay.rb +5 -4
  56. data/lib/tinkerforge/bricklet_sound_intensity.rb +6 -5
  57. data/lib/tinkerforge/bricklet_temperature.rb +7 -6
  58. data/lib/tinkerforge/bricklet_temperature_ir.rb +7 -6
  59. data/lib/tinkerforge/bricklet_tilt.rb +5 -4
  60. data/lib/tinkerforge/bricklet_voltage.rb +8 -7
  61. data/lib/tinkerforge/bricklet_voltage_current.rb +5 -4
  62. data/lib/tinkerforge/version.rb +1 -1
  63. metadata +13 -2
@@ -1,18 +1,19 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2014-12-10. #
3
+ # This file was automatically generated on 2015-11-17. #
4
4
  # #
5
- # Bindings Version 2.1.4 #
5
+ # Bindings Version 2.1.6 #
6
6
  # #
7
7
  # If you have a bugfix for this file and want to commit it, #
8
8
  # please fix the bug in the generator. You can find a link #
9
- # to the generator git on tinkerforge.com #
9
+ # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- # Device for controlling up to seven servos
13
+ # Drives up to 7 RC Servos with up to 3A
14
14
  class BrickServo < Device
15
15
  DEVICE_IDENTIFIER = 14 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'Servo Brick' # :nodoc:
16
17
 
17
18
  # This callback is triggered when the input voltage drops below the value set by
18
19
  # BrickServo#set_minimum_voltage. The parameter is the current voltage given
@@ -74,6 +75,9 @@ module Tinkerforge
74
75
  FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK = 32 # :nodoc:
75
76
  FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK = 33 # :nodoc:
76
77
  FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED = 34 # :nodoc:
78
+ FUNCTION_ENABLE_STATUS_LED = 238 # :nodoc:
79
+ FUNCTION_DISABLE_STATUS_LED = 239 # :nodoc:
80
+ FUNCTION_IS_STATUS_LED_ENABLED = 240 # :nodoc:
77
81
  FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
78
82
  FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
79
83
  FUNCTION_RESET = 243 # :nodoc:
@@ -85,7 +89,7 @@ module Tinkerforge
85
89
  def initialize(uid, ipcon)
86
90
  super uid, ipcon
87
91
 
88
- @api_version = [2, 0, 0]
92
+ @api_version = [2, 0, 1]
89
93
 
90
94
  @response_expected[FUNCTION_ENABLE] = RESPONSE_EXPECTED_FALSE
91
95
  @response_expected[FUNCTION_DISABLE] = RESPONSE_EXPECTED_FALSE
@@ -121,6 +125,9 @@ module Tinkerforge
121
125
  @response_expected[FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK] = RESPONSE_EXPECTED_TRUE
122
126
  @response_expected[FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK] = RESPONSE_EXPECTED_TRUE
123
127
  @response_expected[FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
128
+ @response_expected[FUNCTION_ENABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
129
+ @response_expected[FUNCTION_DISABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
130
+ @response_expected[FUNCTION_IS_STATUS_LED_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
124
131
  @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
125
132
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
126
133
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
@@ -233,7 +240,7 @@ module Tinkerforge
233
240
  # Sets the minimum and maximum pulse width of the specified servo in µs.
234
241
  #
235
242
  # Usually, servos are controlled with a
236
- # `PWM <http://en.wikipedia.org/wiki/Pulse-width_modulation>`__, whereby the
243
+ # `PWM <https://en.wikipedia.org/wiki/Pulse-width_modulation>`__, whereby the
237
244
  # length of the pulse controls the position of the servo. Every servo has
238
245
  # different minimum and maximum pulse widths, these can be specified with
239
246
  # this function.
@@ -300,7 +307,7 @@ module Tinkerforge
300
307
  # Sets the period of the specified servo in µs.
301
308
  #
302
309
  # Usually, servos are controlled with a
303
- # `PWM <http://en.wikipedia.org/wiki/Pulse-width_modulation>`__. Different
310
+ # `PWM <https://en.wikipedia.org/wiki/Pulse-width_modulation>`__. Different
304
311
  # servos expect PWMs with different periods. Most servos run well with a
305
312
  # period of about 20ms.
306
313
  #
@@ -374,7 +381,7 @@ module Tinkerforge
374
381
  #
375
382
  # Default is disabled.
376
383
  #
377
- # .. versionadded:: 2.0.1~(Firmware)
384
+ # .. versionadded:: 2.0.1$nbsp;(Firmware)
378
385
  def enable_position_reached_callback
379
386
  send_request(FUNCTION_ENABLE_POSITION_REACHED_CALLBACK, [], '', 0, '')
380
387
  end
@@ -383,23 +390,23 @@ module Tinkerforge
383
390
  #
384
391
  # Default is disabled.
385
392
  #
386
- # .. versionadded:: 2.0.1~(Firmware)
393
+ # .. versionadded:: 2.0.1$nbsp;(Firmware)
387
394
  def disable_position_reached_callback
388
395
  send_request(FUNCTION_DISABLE_POSITION_REACHED_CALLBACK, [], '', 0, '')
389
396
  end
390
397
 
391
398
  # Returns *true* if CALLBACK_POSITION_REACHED callback is enabled, *false* otherwise.
392
399
  #
393
- # .. versionadded:: 2.0.1~(Firmware)
400
+ # .. versionadded:: 2.0.1$nbsp;(Firmware)
394
401
  def is_position_reached_callback_enabled
395
- send_request(FUNCTION_IS_POSITION_REACHED_CALLBACK_ENABLED, [], '', 1, 'C')
402
+ send_request(FUNCTION_IS_POSITION_REACHED_CALLBACK_ENABLED, [], '', 1, '?')
396
403
  end
397
404
 
398
405
  # Enables the CALLBACK_VELOCITY_REACHED callback.
399
406
  #
400
407
  # Default is disabled.
401
408
  #
402
- # .. versionadded:: 2.0.1~(Firmware)
409
+ # .. versionadded:: 2.0.1$nbsp;(Firmware)
403
410
  def enable_velocity_reached_callback
404
411
  send_request(FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK, [], '', 0, '')
405
412
  end
@@ -408,16 +415,47 @@ module Tinkerforge
408
415
  #
409
416
  # Default is disabled.
410
417
  #
411
- # .. versionadded:: 2.0.1~(Firmware)
418
+ # .. versionadded:: 2.0.1$nbsp;(Firmware)
412
419
  def disable_velocity_reached_callback
413
420
  send_request(FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK, [], '', 0, '')
414
421
  end
415
422
 
416
423
  # Returns *true* if CALLBACK_VELOCITY_REACHED callback is enabled, *false* otherwise.
417
424
  #
418
- # .. versionadded:: 2.0.1~(Firmware)
425
+ # .. versionadded:: 2.0.1$nbsp;(Firmware)
419
426
  def is_velocity_reached_callback_enabled
420
- send_request(FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED, [], '', 1, 'C')
427
+ send_request(FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED, [], '', 1, '?')
428
+ end
429
+
430
+ # Enables the status LED.
431
+ #
432
+ # The status LED is the blue LED next to the USB connector. If enabled is is
433
+ # on and it flickers if data is transfered. If disabled it is always off.
434
+ #
435
+ # The default state is enabled.
436
+ #
437
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
438
+ def enable_status_led
439
+ send_request(FUNCTION_ENABLE_STATUS_LED, [], '', 0, '')
440
+ end
441
+
442
+ # Disables the status LED.
443
+ #
444
+ # The status LED is the blue LED next to the USB connector. If enabled is is
445
+ # on and it flickers if data is transfered. If disabled it is always off.
446
+ #
447
+ # The default state is enabled.
448
+ #
449
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
450
+ def disable_status_led
451
+ send_request(FUNCTION_DISABLE_STATUS_LED, [], '', 0, '')
452
+ end
453
+
454
+ # Returns *true* if the status LED is enabled, *false* otherwise.
455
+ #
456
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
457
+ def is_status_led_enabled
458
+ send_request(FUNCTION_IS_STATUS_LED_ENABLED, [], '', 1, '?')
421
459
  end
422
460
 
423
461
  # Returns the firmware and protocol version and the name of the Bricklet for a
@@ -1,18 +1,19 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2014-12-10. #
3
+ # This file was automatically generated on 2015-11-17. #
4
4
  # #
5
- # Bindings Version 2.1.4 #
5
+ # Bindings Version 2.1.6 #
6
6
  # #
7
7
  # If you have a bugfix for this file and want to commit it, #
8
8
  # please fix the bug in the generator. You can find a link #
9
- # to the generator git on tinkerforge.com #
9
+ # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- # Device for controlling stepper motors
13
+ # Drives one bipolar stepper motor with up to 38V and 2.5A per phase
14
14
  class BrickStepper < Device
15
15
  DEVICE_IDENTIFIER = 15 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'Stepper Brick' # :nodoc:
16
17
 
17
18
  # This callback is triggered when the input voltage drops below the value set by
18
19
  # BrickStepper#set_minimum_voltage. The parameter is the current voltage given
@@ -37,15 +38,6 @@ module Tinkerforge
37
38
 
38
39
  # This callback is triggered whenever the Stepper Brick enters a new state.
39
40
  # It returns the new state as well as the previous state.
40
- #
41
- # Possible states are:
42
- #
43
- # * 1 = Stop
44
- # * 2 = Acceleration
45
- # * 3 = Run
46
- # * 4 = Deacceleration
47
- # * 5 = Direction change to forward
48
- # * 6 = Direction change to backward
49
41
  CALLBACK_NEW_STATE = 41
50
42
 
51
43
  FUNCTION_SET_MAX_VELOCITY = 1 # :nodoc:
@@ -85,6 +77,9 @@ module Tinkerforge
85
77
  FUNCTION_GET_ALL_DATA = 37 # :nodoc:
86
78
  FUNCTION_SET_ALL_DATA_PERIOD = 38 # :nodoc:
87
79
  FUNCTION_GET_ALL_DATA_PERIOD = 39 # :nodoc:
80
+ FUNCTION_ENABLE_STATUS_LED = 238 # :nodoc:
81
+ FUNCTION_DISABLE_STATUS_LED = 239 # :nodoc:
82
+ FUNCTION_IS_STATUS_LED_ENABLED = 240 # :nodoc:
88
83
  FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
89
84
  FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
90
85
  FUNCTION_RESET = 243 # :nodoc:
@@ -149,6 +144,9 @@ module Tinkerforge
149
144
  @response_expected[FUNCTION_GET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
150
145
  @response_expected[CALLBACK_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_FALSE
151
146
  @response_expected[CALLBACK_NEW_STATE] = RESPONSE_EXPECTED_ALWAYS_FALSE
147
+ @response_expected[FUNCTION_ENABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
148
+ @response_expected[FUNCTION_DISABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
149
+ @response_expected[FUNCTION_IS_STATUS_LED_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
152
150
  @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
153
151
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
154
152
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
@@ -428,7 +426,7 @@ module Tinkerforge
428
426
  # decay is used.
429
427
  #
430
428
  # For an explanation of synchronous rectification see
431
- # `here <http://en.wikipedia.org/wiki/Active_rectification>`__.
429
+ # `here <https://en.wikipedia.org/wiki/Active_rectification>`__.
432
430
  #
433
431
  # .. warning::
434
432
  # If you want to use high speeds (> 10000 steps/s) for a large
@@ -483,6 +481,37 @@ module Tinkerforge
483
481
  send_request(FUNCTION_GET_ALL_DATA_PERIOD, [], '', 4, 'L')
484
482
  end
485
483
 
484
+ # Enables the status LED.
485
+ #
486
+ # The status LED is the blue LED next to the USB connector. If enabled is is
487
+ # on and it flickers if data is transfered. If disabled it is always off.
488
+ #
489
+ # The default state is enabled.
490
+ #
491
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
492
+ def enable_status_led
493
+ send_request(FUNCTION_ENABLE_STATUS_LED, [], '', 0, '')
494
+ end
495
+
496
+ # Disables the status LED.
497
+ #
498
+ # The status LED is the blue LED next to the USB connector. If enabled is is
499
+ # on and it flickers if data is transfered. If disabled it is always off.
500
+ #
501
+ # The default state is enabled.
502
+ #
503
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
504
+ def disable_status_led
505
+ send_request(FUNCTION_DISABLE_STATUS_LED, [], '', 0, '')
506
+ end
507
+
508
+ # Returns *true* if the status LED is enabled, *false* otherwise.
509
+ #
510
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
511
+ def is_status_led_enabled
512
+ send_request(FUNCTION_IS_STATUS_LED_ENABLED, [], '', 1, '?')
513
+ end
514
+
486
515
  # Returns the firmware and protocol version and the name of the Bricklet for a
487
516
  # given port.
488
517
  #
@@ -0,0 +1,229 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2015-11-17. #
4
+ # #
5
+ # Bindings Version 2.1.6 #
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 generators git repository on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Measures acceleration in three axis
14
+ class BrickletAccelerometer < Device
15
+ DEVICE_IDENTIFIER = 250 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'Accelerometer Bricklet' # :nodoc:
17
+
18
+ # This callback is triggered periodically with the period that is set by
19
+ # BrickletAccelerometer#set_acceleration_callback_period. The parameters are the
20
+ # X, Y and Z acceleration.
21
+ #
22
+ # CALLBACK_ACCELERATION is only triggered if the acceleration has changed since the
23
+ # last triggering.
24
+ CALLBACK_ACCELERATION = 14
25
+
26
+ # This callback is triggered when the threshold as set by
27
+ # BrickletAccelerometer#set_acceleration_callback_threshold is reached.
28
+ # The parameters are the X, Y and Z acceleration.
29
+ #
30
+ # If the threshold keeps being reached, the callback is triggered periodically
31
+ # with the period as set by BrickletAccelerometer#set_debounce_period.
32
+ CALLBACK_ACCELERATION_REACHED = 15
33
+
34
+ FUNCTION_GET_ACCELERATION = 1 # :nodoc:
35
+ FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD = 2 # :nodoc:
36
+ FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD = 3 # :nodoc:
37
+ FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD = 4 # :nodoc:
38
+ FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD = 5 # :nodoc:
39
+ FUNCTION_SET_DEBOUNCE_PERIOD = 6 # :nodoc:
40
+ FUNCTION_GET_DEBOUNCE_PERIOD = 7 # :nodoc:
41
+ FUNCTION_GET_TEMPERATURE = 8 # :nodoc:
42
+ FUNCTION_SET_CONFIGURATION = 9 # :nodoc:
43
+ FUNCTION_GET_CONFIGURATION = 10 # :nodoc:
44
+ FUNCTION_LED_ON = 11 # :nodoc:
45
+ FUNCTION_LED_OFF = 12 # :nodoc:
46
+ FUNCTION_IS_LED_ON = 13 # :nodoc:
47
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
48
+
49
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
50
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
51
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
52
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
53
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
54
+ DATA_RATE_OFF = 0 # :nodoc:
55
+ DATA_RATE_3HZ = 1 # :nodoc:
56
+ DATA_RATE_6HZ = 2 # :nodoc:
57
+ DATA_RATE_12HZ = 3 # :nodoc:
58
+ DATA_RATE_25HZ = 4 # :nodoc:
59
+ DATA_RATE_50HZ = 5 # :nodoc:
60
+ DATA_RATE_100HZ = 6 # :nodoc:
61
+ DATA_RATE_400HZ = 7 # :nodoc:
62
+ DATA_RATE_800HZ = 8 # :nodoc:
63
+ DATA_RATE_1600HZ = 9 # :nodoc:
64
+ FULL_SCALE_2G = 0 # :nodoc:
65
+ FULL_SCALE_4G = 1 # :nodoc:
66
+ FULL_SCALE_6G = 2 # :nodoc:
67
+ FULL_SCALE_8G = 3 # :nodoc:
68
+ FULL_SCALE_16G = 4 # :nodoc:
69
+ FILTER_BANDWIDTH_800HZ = 0 # :nodoc:
70
+ FILTER_BANDWIDTH_400HZ = 1 # :nodoc:
71
+ FILTER_BANDWIDTH_200HZ = 2 # :nodoc:
72
+ FILTER_BANDWIDTH_50HZ = 3 # :nodoc:
73
+
74
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
75
+ # the IP Connection <tt>ipcon</tt>.
76
+ def initialize(uid, ipcon)
77
+ super uid, ipcon
78
+
79
+ @api_version = [2, 0, 1]
80
+
81
+ @response_expected[FUNCTION_GET_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
82
+ @response_expected[FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
83
+ @response_expected[FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
84
+ @response_expected[FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
85
+ @response_expected[FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
87
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
88
+ @response_expected[FUNCTION_GET_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
89
+ @response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
90
+ @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
91
+ @response_expected[FUNCTION_LED_ON] = RESPONSE_EXPECTED_FALSE
92
+ @response_expected[FUNCTION_LED_OFF] = RESPONSE_EXPECTED_FALSE
93
+ @response_expected[FUNCTION_IS_LED_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
94
+ @response_expected[CALLBACK_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
95
+ @response_expected[CALLBACK_ACCELERATION_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
96
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
97
+
98
+ @callback_formats[CALLBACK_ACCELERATION] = 's s s'
99
+ @callback_formats[CALLBACK_ACCELERATION_REACHED] = 's s s'
100
+ end
101
+
102
+ # Returns the acceleration in x, y and z direction. The values
103
+ # are given in g/1000 (1g = 9.80665m/s²), not to be confused with grams.
104
+ #
105
+ # If you want to get the acceleration periodically, it is recommended
106
+ # to use the callback CALLBACK_ACCELERATION and set the period with
107
+ # BrickletAccelerometer#set_acceleration_callback_period.
108
+ def get_acceleration
109
+ send_request(FUNCTION_GET_ACCELERATION, [], '', 6, 's s s')
110
+ end
111
+
112
+ # Sets the period in ms with which the CALLBACK_ACCELERATION callback is triggered
113
+ # periodically. A value of 0 turns the callback off.
114
+ #
115
+ # CALLBACK_ACCELERATION is only triggered if the acceleration has changed since the
116
+ # last triggering.
117
+ #
118
+ # The default value is 0.
119
+ def set_acceleration_callback_period(period)
120
+ send_request(FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD, [period], 'L', 0, '')
121
+ end
122
+
123
+ # Returns the period as set by BrickletAccelerometer#set_acceleration_callback_period.
124
+ def get_acceleration_callback_period
125
+ send_request(FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD, [], '', 4, 'L')
126
+ end
127
+
128
+ # Sets the thresholds for the CALLBACK_ACCELERATION_REACHED callback.
129
+ #
130
+ # The following options are possible:
131
+ #
132
+ # "Option", "Description"
133
+ #
134
+ # "'x'", "Callback is turned off"
135
+ # "'o'", "Callback is triggered when the acceleration is *outside* the min and max values"
136
+ # "'i'", "Callback is triggered when the acceleration is *inside* the min and max values"
137
+ # "'<'", "Callback is triggered when the acceleration is smaller than the min value (max is ignored)"
138
+ # "'>'", "Callback is triggered when the acceleration is greater than the min value (max is ignored)"
139
+ #
140
+ # The default value is ('x', 0, 0, 0, 0, 0, 0).
141
+ def set_acceleration_callback_threshold(option, min_x, max_x, min_y, max_y, min_z, max_z)
142
+ send_request(FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD, [option, min_x, max_x, min_y, max_y, min_z, max_z], 'k s s s s s s', 0, '')
143
+ end
144
+
145
+ # Returns the threshold as set by BrickletAccelerometer#set_acceleration_callback_threshold.
146
+ def get_acceleration_callback_threshold
147
+ send_request(FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD, [], '', 13, 'k s s s s s s')
148
+ end
149
+
150
+ # Sets the period in ms with which the threshold callback
151
+ #
152
+ # * CALLBACK_ACCELERATION_REACHED
153
+ #
154
+ # is triggered, if the threshold
155
+ #
156
+ # * BrickletAccelerometer#set_acceleration_callback_threshold
157
+ #
158
+ # keeps being reached.
159
+ #
160
+ # The default value is 100.
161
+ def set_debounce_period(debounce)
162
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
163
+ end
164
+
165
+ # Returns the debounce period as set by BrickletAccelerometer#set_debounce_period.
166
+ def get_debounce_period
167
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
168
+ end
169
+
170
+ # Returns the temperature of the accelerometer in °C.
171
+ def get_temperature
172
+ send_request(FUNCTION_GET_TEMPERATURE, [], '', 2, 's')
173
+ end
174
+
175
+ # Configures the data rate, full scale range and filter bandwidth.
176
+ # Possible values are:
177
+ #
178
+ # * Data rate of 0Hz to 1600Hz.
179
+ # * Full scale range of -2G to +2G up to -16G to +16G.
180
+ # * Filter bandwidth between 50Hz and 800Hz.
181
+ #
182
+ # Decreasing data rate or full scale range will also decrease the noise on
183
+ # the data.
184
+ #
185
+ # The default values are 100Hz data rate, -4G to +4G range and 200Hz
186
+ # filter bandwidth.
187
+ def set_configuration(data_rate, full_scale, filter_bandwidth)
188
+ send_request(FUNCTION_SET_CONFIGURATION, [data_rate, full_scale, filter_bandwidth], 'C C C', 0, '')
189
+ end
190
+
191
+ # Returns the configuration as set by BrickletAccelerometer#set_configuration.
192
+ def get_configuration
193
+ send_request(FUNCTION_GET_CONFIGURATION, [], '', 3, 'C C C')
194
+ end
195
+
196
+ # Enables the LED on the Bricklet.
197
+ def led_on
198
+ send_request(FUNCTION_LED_ON, [], '', 0, '')
199
+ end
200
+
201
+ # Disables the LED on the Bricklet.
202
+ def led_off
203
+ send_request(FUNCTION_LED_OFF, [], '', 0, '')
204
+ end
205
+
206
+ # Returns *true* if the LED is enabled, *false* otherwise.
207
+ def is_led_on
208
+ send_request(FUNCTION_IS_LED_ON, [], '', 1, '?')
209
+ end
210
+
211
+ # Returns the UID, the UID where the Bricklet is connected to,
212
+ # the position, the hardware and firmware version as well as the
213
+ # device identifier.
214
+ #
215
+ # The position can be 'a', 'b', 'c' or 'd'.
216
+ #
217
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
218
+ # |device_identifier_constant|
219
+ def get_identity
220
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
221
+ end
222
+
223
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
224
+ def register_callback(id, &block)
225
+ callback = block
226
+ @registered_callbacks[id] = callback
227
+ end
228
+ end
229
+ end