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 DC motors
13
+ # Drives one brushed DC motor with up to 28V and 5A (peak)
14
14
  class BrickDC < Device
15
15
  DEVICE_IDENTIFIER = 11 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'DC Brick' # :nodoc:
16
17
 
17
18
  # This callback is triggered when the input voltage drops below the value set by
18
19
  # BrickDC#set_minimum_voltage. The parameter is the current voltage given
@@ -75,6 +76,9 @@ module Tinkerforge
75
76
  FUNCTION_GET_DRIVE_MODE = 18 # :nodoc:
76
77
  FUNCTION_SET_CURRENT_VELOCITY_PERIOD = 19 # :nodoc:
77
78
  FUNCTION_GET_CURRENT_VELOCITY_PERIOD = 20 # :nodoc:
79
+ FUNCTION_ENABLE_STATUS_LED = 238 # :nodoc:
80
+ FUNCTION_DISABLE_STATUS_LED = 239 # :nodoc:
81
+ FUNCTION_IS_STATUS_LED_ENABLED = 240 # :nodoc:
78
82
  FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
79
83
  FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
80
84
  FUNCTION_RESET = 243 # :nodoc:
@@ -114,6 +118,9 @@ module Tinkerforge
114
118
  @response_expected[CALLBACK_EMERGENCY_SHUTDOWN] = RESPONSE_EXPECTED_ALWAYS_FALSE
115
119
  @response_expected[CALLBACK_VELOCITY_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
116
120
  @response_expected[CALLBACK_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_FALSE
121
+ @response_expected[FUNCTION_ENABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
122
+ @response_expected[FUNCTION_DISABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
123
+ @response_expected[FUNCTION_IS_STATUS_LED_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
117
124
  @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
118
125
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
119
126
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
@@ -304,6 +311,37 @@ module Tinkerforge
304
311
  send_request(FUNCTION_GET_CURRENT_VELOCITY_PERIOD, [], '', 2, 'S')
305
312
  end
306
313
 
314
+ # Enables the status LED.
315
+ #
316
+ # The status LED is the blue LED next to the USB connector. If enabled is is
317
+ # on and it flickers if data is transfered. If disabled it is always off.
318
+ #
319
+ # The default state is enabled.
320
+ #
321
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
322
+ def enable_status_led
323
+ send_request(FUNCTION_ENABLE_STATUS_LED, [], '', 0, '')
324
+ end
325
+
326
+ # Disables the status LED.
327
+ #
328
+ # The status LED is the blue LED next to the USB connector. If enabled is is
329
+ # on and it flickers if data is transfered. If disabled it is always off.
330
+ #
331
+ # The default state is enabled.
332
+ #
333
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
334
+ def disable_status_led
335
+ send_request(FUNCTION_DISABLE_STATUS_LED, [], '', 0, '')
336
+ end
337
+
338
+ # Returns *true* if the status LED is enabled, *false* otherwise.
339
+ #
340
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
341
+ def is_status_led_enabled
342
+ send_request(FUNCTION_IS_STATUS_LED_ENABLED, [], '', 1, '?')
343
+ end
344
+
307
345
  # Returns the firmware and protocol version and the name of the Bricklet for a
308
346
  # given port.
309
347
  #
@@ -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 sensing acceleration, magnetic field and angular velocity
13
+ # Full fledged AHRS with 9 degrees of freedom
14
14
  class BrickIMU < Device
15
15
  DEVICE_IDENTIFIER = 16 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'IMU Brick' # :nodoc:
16
17
 
17
18
  # This callback is triggered periodically with the period that is set by
18
19
  # BrickIMU#set_acceleration_period. The parameters are the acceleration
@@ -80,6 +81,9 @@ module Tinkerforge
80
81
  FUNCTION_ORIENTATION_CALCULATION_ON = 37 # :nodoc:
81
82
  FUNCTION_ORIENTATION_CALCULATION_OFF = 38 # :nodoc:
82
83
  FUNCTION_IS_ORIENTATION_CALCULATION_ON = 39 # :nodoc:
84
+ FUNCTION_ENABLE_STATUS_LED = 238 # :nodoc:
85
+ FUNCTION_DISABLE_STATUS_LED = 239 # :nodoc:
86
+ FUNCTION_IS_STATUS_LED_ENABLED = 240 # :nodoc:
83
87
  FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
84
88
  FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
85
89
  FUNCTION_RESET = 243 # :nodoc:
@@ -138,6 +142,9 @@ module Tinkerforge
138
142
  @response_expected[FUNCTION_ORIENTATION_CALCULATION_ON] = RESPONSE_EXPECTED_FALSE
139
143
  @response_expected[FUNCTION_ORIENTATION_CALCULATION_OFF] = RESPONSE_EXPECTED_FALSE
140
144
  @response_expected[FUNCTION_IS_ORIENTATION_CALCULATION_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
145
+ @response_expected[FUNCTION_ENABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
146
+ @response_expected[FUNCTION_DISABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
147
+ @response_expected[FUNCTION_IS_STATUS_LED_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
141
148
  @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
142
149
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
143
150
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
@@ -152,7 +159,7 @@ module Tinkerforge
152
159
  end
153
160
 
154
161
  # Returns the calibrated acceleration from the accelerometer for the
155
- # x, y and z axis in mG (G/1000, 1G = 9.80605m/s²).
162
+ # x, y and z axis in g/1000 (1g = 9.80665m/s²).
156
163
  #
157
164
  # If you want to get the acceleration periodically, it is recommended
158
165
  # to use the callback CALLBACK_ACCELERATION and set the period with
@@ -196,7 +203,7 @@ module Tinkerforge
196
203
 
197
204
  # Returns the current orientation (roll, pitch, yaw) of the IMU Brick as Euler
198
205
  # angles in one-hundredth degree. Note that Euler angles always experience a
199
- # `gimbal lock <http://en.wikipedia.org/wiki/Gimbal_lock>`__.
206
+ # `gimbal lock <https://en.wikipedia.org/wiki/Gimbal_lock>`__.
200
207
  #
201
208
  # We recommend that you use quaternions instead.
202
209
  #
@@ -211,7 +218,7 @@ module Tinkerforge
211
218
  end
212
219
 
213
220
  # Returns the current orientation (x, y, z, w) of the IMU as
214
- # `quaternions <http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation>`__.
221
+ # `quaternions <https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation>`__.
215
222
  #
216
223
  # You can go from quaternions to Euler angles with the following formula::
217
224
  #
@@ -220,7 +227,7 @@ module Tinkerforge
220
227
  # zAngle = asin(2*x*y + 2*z*w)
221
228
  #
222
229
  # This process is not reversible, because of the
223
- # `gimbal lock <http://en.wikipedia.org/wiki/Gimbal_lock>`__.
230
+ # `gimbal lock <https://en.wikipedia.org/wiki/Gimbal_lock>`__.
224
231
  #
225
232
  # It is also possible to calculate independent angles. You can calculate
226
233
  # yaw, pitch and roll in a right-handed vehicle coordinate system according to DIN70000
@@ -436,7 +443,7 @@ module Tinkerforge
436
443
  #
437
444
  # As default the calculation is on.
438
445
  #
439
- # .. versionadded:: 2.0.2~(Firmware)
446
+ # .. versionadded:: 2.0.2$nbsp;(Firmware)
440
447
  def orientation_calculation_on
441
448
  send_request(FUNCTION_ORIENTATION_CALCULATION_ON, [], '', 0, '')
442
449
  end
@@ -453,7 +460,7 @@ module Tinkerforge
453
460
  #
454
461
  # As default the calculation is on.
455
462
  #
456
- # .. versionadded:: 2.0.2~(Firmware)
463
+ # .. versionadded:: 2.0.2$nbsp;(Firmware)
457
464
  def orientation_calculation_off
458
465
  send_request(FUNCTION_ORIENTATION_CALCULATION_OFF, [], '', 0, '')
459
466
  end
@@ -461,11 +468,42 @@ module Tinkerforge
461
468
  # Returns *true* if the orientation calculation of the IMU Brick
462
469
  # is on, *false* otherwise.
463
470
  #
464
- # .. versionadded:: 2.0.2~(Firmware)
471
+ # .. versionadded:: 2.0.2$nbsp;(Firmware)
465
472
  def is_orientation_calculation_on
466
473
  send_request(FUNCTION_IS_ORIENTATION_CALCULATION_ON, [], '', 1, '?')
467
474
  end
468
475
 
476
+ # Enables the status LED.
477
+ #
478
+ # The status LED is the blue LED next to the USB connector. If enabled is is
479
+ # on and it flickers if data is transfered. If disabled it is always off.
480
+ #
481
+ # The default state is enabled.
482
+ #
483
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
484
+ def enable_status_led
485
+ send_request(FUNCTION_ENABLE_STATUS_LED, [], '', 0, '')
486
+ end
487
+
488
+ # Disables the status LED.
489
+ #
490
+ # The status LED is the blue LED next to the USB connector. If enabled is is
491
+ # on and it flickers if data is transfered. If disabled it is always off.
492
+ #
493
+ # The default state is enabled.
494
+ #
495
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
496
+ def disable_status_led
497
+ send_request(FUNCTION_DISABLE_STATUS_LED, [], '', 0, '')
498
+ end
499
+
500
+ # Returns *true* if the status LED is enabled, *false* otherwise.
501
+ #
502
+ # .. versionadded:: 2.3.1$nbsp;(Firmware)
503
+ def is_status_led_enabled
504
+ send_request(FUNCTION_IS_STATUS_LED_ENABLED, [], '', 1, '?')
505
+ end
506
+
469
507
  # Returns the firmware and protocol version and the name of the Bricklet for a
470
508
  # given port.
471
509
  #
@@ -0,0 +1,506 @@
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
+ # Full fledged AHRS with 9 degrees of freedom
14
+ class BrickIMUV2 < Device
15
+ DEVICE_IDENTIFIER = 18 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'IMU Brick 2.0' # :nodoc:
17
+
18
+ # This callback is triggered periodically with the period that is set by
19
+ # BrickIMUV2#set_acceleration_period. The parameters are the acceleration
20
+ # for the x, y and z axis.
21
+ CALLBACK_ACCELERATION = 32
22
+
23
+ # This callback is triggered periodically with the period that is set by
24
+ # BrickIMUV2#set_magnetic_field_period. The parameters are the magnetic field
25
+ # for the x, y and z axis.
26
+ CALLBACK_MAGNETIC_FIELD = 33
27
+
28
+ # This callback is triggered periodically with the period that is set by
29
+ # BrickIMUV2#set_angular_velocity_period. The parameters are the angular velocity
30
+ # for the x, y and z axis.
31
+ CALLBACK_ANGULAR_VELOCITY = 34
32
+
33
+ # This callback is triggered periodically with the period that is set by
34
+ # BrickIMUV2#set_temperature_period. The parameter is the temperature.
35
+ CALLBACK_TEMPERATURE = 35
36
+
37
+ # This callback is triggered periodically with the period that is set by
38
+ # BrickIMUV2#set_linear_acceleration_period. The parameters are the
39
+ # linear acceleration for the x, y and z axis.
40
+ CALLBACK_LINEAR_ACCELERATION = 36
41
+
42
+ # This callback is triggered periodically with the period that is set by
43
+ # BrickIMUV2#set_gravity_vector_period. The parameters gravity vector
44
+ # for the x, y and z axis.
45
+ CALLBACK_GRAVITY_VECTOR = 37
46
+
47
+ # This callback is triggered periodically with the period that is set by
48
+ # BrickIMUV2#set_orientation_period. The parameters are the orientation
49
+ # (heading (yaw), roll, pitch) of the IMU Brick in Euler angles. See
50
+ # BrickIMUV2#get_orientation for details.
51
+ CALLBACK_ORIENTATION = 38
52
+
53
+ # This callback is triggered periodically with the period that is set by
54
+ # BrickIMUV2#set_quaternion_period. The parameters are the orientation
55
+ # (x, y, z, w) of the IMU Brick in quaternions. See BrickIMUV2#get_quaternion
56
+ # for details.
57
+ CALLBACK_QUATERNION = 39
58
+
59
+ # This callback is triggered periodically with the period that is set by
60
+ # BrickIMUV2#set_all_data_period. The parameters are as for BrickIMUV2#get_all_data.
61
+ CALLBACK_ALL_DATA = 40
62
+
63
+ FUNCTION_GET_ACCELERATION = 1 # :nodoc:
64
+ FUNCTION_GET_MAGNETIC_FIELD = 2 # :nodoc:
65
+ FUNCTION_GET_ANGULAR_VELOCITY = 3 # :nodoc:
66
+ FUNCTION_GET_TEMPERATURE = 4 # :nodoc:
67
+ FUNCTION_GET_ORIENTATION = 5 # :nodoc:
68
+ FUNCTION_GET_LINEAR_ACCELERATION = 6 # :nodoc:
69
+ FUNCTION_GET_GRAVITY_VECTOR = 7 # :nodoc:
70
+ FUNCTION_GET_QUATERNION = 8 # :nodoc:
71
+ FUNCTION_GET_ALL_DATA = 9 # :nodoc:
72
+ FUNCTION_LEDS_ON = 10 # :nodoc:
73
+ FUNCTION_LEDS_OFF = 11 # :nodoc:
74
+ FUNCTION_ARE_LEDS_ON = 12 # :nodoc:
75
+ FUNCTION_SAVE_CALIBRATION = 13 # :nodoc:
76
+ FUNCTION_SET_ACCELERATION_PERIOD = 14 # :nodoc:
77
+ FUNCTION_GET_ACCELERATION_PERIOD = 15 # :nodoc:
78
+ FUNCTION_SET_MAGNETIC_FIELD_PERIOD = 16 # :nodoc:
79
+ FUNCTION_GET_MAGNETIC_FIELD_PERIOD = 17 # :nodoc:
80
+ FUNCTION_SET_ANGULAR_VELOCITY_PERIOD = 18 # :nodoc:
81
+ FUNCTION_GET_ANGULAR_VELOCITY_PERIOD = 19 # :nodoc:
82
+ FUNCTION_SET_TEMPERATURE_PERIOD = 20 # :nodoc:
83
+ FUNCTION_GET_TEMPERATURE_PERIOD = 21 # :nodoc:
84
+ FUNCTION_SET_ORIENTATION_PERIOD = 22 # :nodoc:
85
+ FUNCTION_GET_ORIENTATION_PERIOD = 23 # :nodoc:
86
+ FUNCTION_SET_LINEAR_ACCELERATION_PERIOD = 24 # :nodoc:
87
+ FUNCTION_GET_LINEAR_ACCELERATION_PERIOD = 25 # :nodoc:
88
+ FUNCTION_SET_GRAVITY_VECTOR_PERIOD = 26 # :nodoc:
89
+ FUNCTION_GET_GRAVITY_VECTOR_PERIOD = 27 # :nodoc:
90
+ FUNCTION_SET_QUATERNION_PERIOD = 28 # :nodoc:
91
+ FUNCTION_GET_QUATERNION_PERIOD = 29 # :nodoc:
92
+ FUNCTION_SET_ALL_DATA_PERIOD = 30 # :nodoc:
93
+ FUNCTION_GET_ALL_DATA_PERIOD = 31 # :nodoc:
94
+ FUNCTION_ENABLE_STATUS_LED = 238 # :nodoc:
95
+ FUNCTION_DISABLE_STATUS_LED = 239 # :nodoc:
96
+ FUNCTION_IS_STATUS_LED_ENABLED = 240 # :nodoc:
97
+ FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
98
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
99
+ FUNCTION_RESET = 243 # :nodoc:
100
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
101
+
102
+
103
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
104
+ # the IP Connection <tt>ipcon</tt>.
105
+ def initialize(uid, ipcon)
106
+ super uid, ipcon
107
+
108
+ @api_version = [2, 0, 0]
109
+
110
+ @response_expected[FUNCTION_GET_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
111
+ @response_expected[FUNCTION_GET_MAGNETIC_FIELD] = RESPONSE_EXPECTED_ALWAYS_TRUE
112
+ @response_expected[FUNCTION_GET_ANGULAR_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
113
+ @response_expected[FUNCTION_GET_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
114
+ @response_expected[FUNCTION_GET_ORIENTATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
115
+ @response_expected[FUNCTION_GET_LINEAR_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
116
+ @response_expected[FUNCTION_GET_GRAVITY_VECTOR] = RESPONSE_EXPECTED_ALWAYS_TRUE
117
+ @response_expected[FUNCTION_GET_QUATERNION] = RESPONSE_EXPECTED_ALWAYS_TRUE
118
+ @response_expected[FUNCTION_GET_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_TRUE
119
+ @response_expected[FUNCTION_LEDS_ON] = RESPONSE_EXPECTED_FALSE
120
+ @response_expected[FUNCTION_LEDS_OFF] = RESPONSE_EXPECTED_FALSE
121
+ @response_expected[FUNCTION_ARE_LEDS_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
122
+ @response_expected[FUNCTION_SAVE_CALIBRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
123
+ @response_expected[FUNCTION_SET_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_TRUE
124
+ @response_expected[FUNCTION_GET_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
125
+ @response_expected[FUNCTION_SET_MAGNETIC_FIELD_PERIOD] = RESPONSE_EXPECTED_TRUE
126
+ @response_expected[FUNCTION_GET_MAGNETIC_FIELD_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
127
+ @response_expected[FUNCTION_SET_ANGULAR_VELOCITY_PERIOD] = RESPONSE_EXPECTED_TRUE
128
+ @response_expected[FUNCTION_GET_ANGULAR_VELOCITY_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
129
+ @response_expected[FUNCTION_SET_TEMPERATURE_PERIOD] = RESPONSE_EXPECTED_TRUE
130
+ @response_expected[FUNCTION_GET_TEMPERATURE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
131
+ @response_expected[FUNCTION_SET_ORIENTATION_PERIOD] = RESPONSE_EXPECTED_TRUE
132
+ @response_expected[FUNCTION_GET_ORIENTATION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
133
+ @response_expected[FUNCTION_SET_LINEAR_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_TRUE
134
+ @response_expected[FUNCTION_GET_LINEAR_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
135
+ @response_expected[FUNCTION_SET_GRAVITY_VECTOR_PERIOD] = RESPONSE_EXPECTED_TRUE
136
+ @response_expected[FUNCTION_GET_GRAVITY_VECTOR_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
137
+ @response_expected[FUNCTION_SET_QUATERNION_PERIOD] = RESPONSE_EXPECTED_TRUE
138
+ @response_expected[FUNCTION_GET_QUATERNION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
139
+ @response_expected[FUNCTION_SET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_TRUE
140
+ @response_expected[FUNCTION_GET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
141
+ @response_expected[CALLBACK_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
142
+ @response_expected[CALLBACK_MAGNETIC_FIELD] = RESPONSE_EXPECTED_ALWAYS_FALSE
143
+ @response_expected[CALLBACK_ANGULAR_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_FALSE
144
+ @response_expected[CALLBACK_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_FALSE
145
+ @response_expected[CALLBACK_LINEAR_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
146
+ @response_expected[CALLBACK_GRAVITY_VECTOR] = RESPONSE_EXPECTED_ALWAYS_FALSE
147
+ @response_expected[CALLBACK_ORIENTATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
148
+ @response_expected[CALLBACK_QUATERNION] = RESPONSE_EXPECTED_ALWAYS_FALSE
149
+ @response_expected[CALLBACK_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_FALSE
150
+ @response_expected[FUNCTION_ENABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
151
+ @response_expected[FUNCTION_DISABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
152
+ @response_expected[FUNCTION_IS_STATUS_LED_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
153
+ @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
154
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
155
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
156
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
157
+
158
+ @callback_formats[CALLBACK_ACCELERATION] = 's s s'
159
+ @callback_formats[CALLBACK_MAGNETIC_FIELD] = 's s s'
160
+ @callback_formats[CALLBACK_ANGULAR_VELOCITY] = 's s s'
161
+ @callback_formats[CALLBACK_TEMPERATURE] = 'c'
162
+ @callback_formats[CALLBACK_LINEAR_ACCELERATION] = 's s s'
163
+ @callback_formats[CALLBACK_GRAVITY_VECTOR] = 's s s'
164
+ @callback_formats[CALLBACK_ORIENTATION] = 's s s'
165
+ @callback_formats[CALLBACK_QUATERNION] = 's s s s'
166
+ @callback_formats[CALLBACK_ALL_DATA] = 's3 s3 s3 s3 s4 s3 s3 c C'
167
+ end
168
+
169
+ # Returns the calibrated acceleration from the accelerometer for the
170
+ # x, y and z axis in 1/100 m/s².
171
+ #
172
+ # If you want to get the acceleration periodically, it is recommended
173
+ # to use the callback CALLBACK_ACCELERATION and set the period with
174
+ # BrickIMUV2#set_acceleration_period.
175
+ def get_acceleration
176
+ send_request(FUNCTION_GET_ACCELERATION, [], '', 6, 's s s')
177
+ end
178
+
179
+ # Returns the calibrated magnetic field from the magnetometer for the
180
+ # x, y and z axis in 1/16 µT (Microtesla).
181
+ #
182
+ # If you want to get the magnetic field periodically, it is recommended
183
+ # to use the callback CALLBACK_MAGNETIC_FIELD and set the period with
184
+ # BrickIMUV2#set_magnetic_field_period.
185
+ def get_magnetic_field
186
+ send_request(FUNCTION_GET_MAGNETIC_FIELD, [], '', 6, 's s s')
187
+ end
188
+
189
+ # Returns the calibrated angular velocity from the gyroscope for the
190
+ # x, y and z axis in 1/16 °/s.
191
+ #
192
+ # If you want to get the angular velocity periodically, it is recommended
193
+ # to use the callback CALLBACK_ANGULAR_VELOCITY and set the period with
194
+ # BrickIMUV2#set_angular_velocity_period.
195
+ def get_angular_velocity
196
+ send_request(FUNCTION_GET_ANGULAR_VELOCITY, [], '', 6, 's s s')
197
+ end
198
+
199
+ # Returns the temperature of the IMU Brick. The temperature is given in
200
+ # °C. The temperature is measured in the core of the BNO055 IC, it is not the
201
+ # ambient temperature
202
+ def get_temperature
203
+ send_request(FUNCTION_GET_TEMPERATURE, [], '', 1, 'c')
204
+ end
205
+
206
+ # Returns the current orientation (heading, roll, pitch) of the IMU Brick as
207
+ # independent Euler angles in 1/16 degree. Note that Euler angles always
208
+ # experience a `gimbal lock <https://en.wikipedia.org/wiki/Gimbal_lock>`__. We
209
+ # recommend that you use quaternions instead, if you need the absolute orientation.
210
+ #
211
+ # The rotation angle has the following ranges:
212
+ #
213
+ # * heading: 0° to 360°
214
+ # * roll: -90° to +90°
215
+ # * pitch: -180° to +180°
216
+ #
217
+ # If you want to get the orientation periodically, it is recommended
218
+ # to use the callback CALLBACK_ORIENTATION and set the period with
219
+ # BrickIMUV2#set_orientation_period.
220
+ def get_orientation
221
+ send_request(FUNCTION_GET_ORIENTATION, [], '', 6, 's s s')
222
+ end
223
+
224
+ # Returns the linear acceleration of the IMU Brick for the
225
+ # x, y and z axis in 1/100 m/s².
226
+ #
227
+ # The linear acceleration is the acceleration in each of the three
228
+ # axis of the IMU Brick with the influences of gravity removed.
229
+ #
230
+ # It is also possible to get the gravity vector with the influence of linear
231
+ # acceleration removed, see BrickIMUV2#get_gravity_vector.
232
+ #
233
+ # If you want to get the linear acceleration periodically, it is recommended
234
+ # to use the callback CALLBACK_LINEAR_ACCELERATION and set the period with
235
+ # BrickIMUV2#set_linear_acceleration_period.
236
+ def get_linear_acceleration
237
+ send_request(FUNCTION_GET_LINEAR_ACCELERATION, [], '', 6, 's s s')
238
+ end
239
+
240
+ # Returns the current gravity vector of the IMU Brick for the
241
+ # x, y and z axis in 1/100 m/s².
242
+ #
243
+ # The gravity vector is the acceleration that occurs due to gravity.
244
+ # Influences of additional linear acceleration are removed.
245
+ #
246
+ # It is also possible to get the linear acceleration with the influence
247
+ # of gravity removed, see BrickIMUV2#get_linear_acceleration.
248
+ #
249
+ # If you want to get the gravity vector periodically, it is recommended
250
+ # to use the callback CALLBACK_GRAVITY_VECTOR and set the period with
251
+ # BrickIMUV2#set_gravity_vector_period.
252
+ def get_gravity_vector
253
+ send_request(FUNCTION_GET_GRAVITY_VECTOR, [], '', 6, 's s s')
254
+ end
255
+
256
+ # Returns the current orientation (w, x, y, z) of the IMU Brick as
257
+ # `quaternions <https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation>`__.
258
+ #
259
+ # You have to divide the returns values by 16383 (14 bit) to get
260
+ # the usual range of -1.0 to +1.0 for quaternions.
261
+ #
262
+ # If you want to get the quaternions periodically, it is recommended
263
+ # to use the callback CALLBACK_QUATERNION and set the period with
264
+ # BrickIMUV2#set_quaternion_period.
265
+ def get_quaternion
266
+ send_request(FUNCTION_GET_QUATERNION, [], '', 8, 's s s s')
267
+ end
268
+
269
+ # Return all of the available data of the IMU Brick.
270
+ #
271
+ # * acceleration in 1/100 m/s² (see BrickIMUV2#get_acceleration)
272
+ # * magnetic field in 1/16 µT (see BrickIMUV2#get_magnetic_field)
273
+ # * angular velocity in 1/16 °/s (see BrickIMUV2#get_angular_velocity)
274
+ # * Euler angles in 1/16 ° (see BrickIMUV2#get_orientation)
275
+ # * quaternion 1/16383 (see BrickIMUV2#get_quaternion)
276
+ # * linear acceleration 1/100 m/s² (see BrickIMUV2#get_linear_acceleration)
277
+ # * gravity vector 1/100 m/s² (see BrickIMUV2#get_gravity_vector)
278
+ # * temperature in 1 °C (see BrickIMUV2#get_temperature)
279
+ # * calibration status (see below)
280
+ #
281
+ # The calibration status consists of four pairs of two bits. Each pair
282
+ # of bits represents the status of the current calibration.
283
+ #
284
+ # * bit 0-1: Magnetometer
285
+ # * bit 2-3: Accelerometer
286
+ # * bit 4-5: Gyroscope
287
+ # * bit 6-7: System
288
+ #
289
+ # A value of 0 means for "not calibrated" and a value of 3 means
290
+ # "fully calibrated". In your program you should always be able to
291
+ # ignore the calibration status, it is used by the calibration
292
+ # window of the Brick Viewer and it can be ignored after the first
293
+ # calibration. See the documentation in the calibration window for
294
+ # more information regarding the calibration of the IMU Brick.
295
+ #
296
+ # If you want to get the data periodically, it is recommended
297
+ # to use the callback CALLBACK_ALL_DATA and set the period with
298
+ # BrickIMUV2#set_all_data_period.
299
+ def get_all_data
300
+ send_request(FUNCTION_GET_ALL_DATA, [], '', 46, 's3 s3 s3 s3 s4 s3 s3 c C')
301
+ end
302
+
303
+ # Turns the orientation and direction LEDs of the IMU Brick on.
304
+ def leds_on
305
+ send_request(FUNCTION_LEDS_ON, [], '', 0, '')
306
+ end
307
+
308
+ # Turns the orientation and direction LEDs of the IMU Brick off.
309
+ def leds_off
310
+ send_request(FUNCTION_LEDS_OFF, [], '', 0, '')
311
+ end
312
+
313
+ # Returns *true* if the orientation and direction LEDs of the IMU Brick
314
+ # are on, *false* otherwise.
315
+ def are_leds_on
316
+ send_request(FUNCTION_ARE_LEDS_ON, [], '', 1, '?')
317
+ end
318
+
319
+ # A call of this function saves the current calibration to be used
320
+ # as a starting point for the next restart of continuous calibration
321
+ # of the IMU Brick.
322
+ #
323
+ # A return value of *true* means that the calibration could be used and
324
+ # *false* means that it could not be used (this happens if the calibration
325
+ # status is not "fully calibrated").
326
+ #
327
+ # This function is used by the calibration window of the Brick Viewer, you
328
+ # should not need to call it in your program.
329
+ def save_calibration
330
+ send_request(FUNCTION_SAVE_CALIBRATION, [], '', 1, '?')
331
+ end
332
+
333
+ # Sets the period in ms with which the CALLBACK_ACCELERATION callback is triggered
334
+ # periodically. A value of 0 turns the callback off.
335
+ #
336
+ # The default value is 0.
337
+ def set_acceleration_period(period)
338
+ send_request(FUNCTION_SET_ACCELERATION_PERIOD, [period], 'L', 0, '')
339
+ end
340
+
341
+ # Returns the period as set by BrickIMUV2#set_acceleration_period.
342
+ def get_acceleration_period
343
+ send_request(FUNCTION_GET_ACCELERATION_PERIOD, [], '', 4, 'L')
344
+ end
345
+
346
+ # Sets the period in ms with which the CALLBACK_MAGNETIC_FIELD callback is triggered
347
+ # periodically. A value of 0 turns the callback off.
348
+ def set_magnetic_field_period(period)
349
+ send_request(FUNCTION_SET_MAGNETIC_FIELD_PERIOD, [period], 'L', 0, '')
350
+ end
351
+
352
+ # Returns the period as set by BrickIMUV2#set_magnetic_field_period.
353
+ def get_magnetic_field_period
354
+ send_request(FUNCTION_GET_MAGNETIC_FIELD_PERIOD, [], '', 4, 'L')
355
+ end
356
+
357
+ # Sets the period in ms with which the CALLBACK_ANGULAR_VELOCITY callback is triggered
358
+ # periodically. A value of 0 turns the callback off.
359
+ def set_angular_velocity_period(period)
360
+ send_request(FUNCTION_SET_ANGULAR_VELOCITY_PERIOD, [period], 'L', 0, '')
361
+ end
362
+
363
+ # Returns the period as set by BrickIMUV2#set_angular_velocity_period.
364
+ def get_angular_velocity_period
365
+ send_request(FUNCTION_GET_ANGULAR_VELOCITY_PERIOD, [], '', 4, 'L')
366
+ end
367
+
368
+ # Sets the period in ms with which the CALLBACK_TEMPERATURE callback is triggered
369
+ # periodically. A value of 0 turns the callback off.
370
+ def set_temperature_period(period)
371
+ send_request(FUNCTION_SET_TEMPERATURE_PERIOD, [period], 'L', 0, '')
372
+ end
373
+
374
+ # Returns the period as set by BrickIMUV2#set_temperature_period.
375
+ def get_temperature_period
376
+ send_request(FUNCTION_GET_TEMPERATURE_PERIOD, [], '', 4, 'L')
377
+ end
378
+
379
+ # Sets the period in ms with which the CALLBACK_ORIENTATION callback is triggered
380
+ # periodically. A value of 0 turns the callback off.
381
+ def set_orientation_period(period)
382
+ send_request(FUNCTION_SET_ORIENTATION_PERIOD, [period], 'L', 0, '')
383
+ end
384
+
385
+ # Returns the period as set by BrickIMUV2#set_orientation_period.
386
+ def get_orientation_period
387
+ send_request(FUNCTION_GET_ORIENTATION_PERIOD, [], '', 4, 'L')
388
+ end
389
+
390
+ # Sets the period in ms with which the CALLBACK_LINEAR_ACCELERATION callback is triggered
391
+ # periodically. A value of 0 turns the callback off.
392
+ def set_linear_acceleration_period(period)
393
+ send_request(FUNCTION_SET_LINEAR_ACCELERATION_PERIOD, [period], 'L', 0, '')
394
+ end
395
+
396
+ # Returns the period as set by BrickIMUV2#set_linear_acceleration_period.
397
+ def get_linear_acceleration_period
398
+ send_request(FUNCTION_GET_LINEAR_ACCELERATION_PERIOD, [], '', 4, 'L')
399
+ end
400
+
401
+ # Sets the period in ms with which the CALLBACK_GRAVITY_VECTOR callback is triggered
402
+ # periodically. A value of 0 turns the callback off.
403
+ def set_gravity_vector_period(period)
404
+ send_request(FUNCTION_SET_GRAVITY_VECTOR_PERIOD, [period], 'L', 0, '')
405
+ end
406
+
407
+ # Returns the period as set by BrickIMUV2#set_gravity_vector_period.
408
+ def get_gravity_vector_period
409
+ send_request(FUNCTION_GET_GRAVITY_VECTOR_PERIOD, [], '', 4, 'L')
410
+ end
411
+
412
+ # Sets the period in ms with which the CALLBACK_QUATERNION callback is triggered
413
+ # periodically. A value of 0 turns the callback off.
414
+ def set_quaternion_period(period)
415
+ send_request(FUNCTION_SET_QUATERNION_PERIOD, [period], 'L', 0, '')
416
+ end
417
+
418
+ # Returns the period as set by BrickIMUV2#set_quaternion_period.
419
+ def get_quaternion_period
420
+ send_request(FUNCTION_GET_QUATERNION_PERIOD, [], '', 4, 'L')
421
+ end
422
+
423
+ # Sets the period in ms with which the CALLBACK_ALL_DATA callback is triggered
424
+ # periodically. A value of 0 turns the callback off.
425
+ def set_all_data_period(period)
426
+ send_request(FUNCTION_SET_ALL_DATA_PERIOD, [period], 'L', 0, '')
427
+ end
428
+
429
+ # Returns the period as set by BrickIMUV2#set_all_data_period.
430
+ def get_all_data_period
431
+ send_request(FUNCTION_GET_ALL_DATA_PERIOD, [], '', 4, 'L')
432
+ end
433
+
434
+ # Enables the status LED.
435
+ #
436
+ # The status LED is the blue LED next to the USB connector. If enabled is is
437
+ # on and it flickers if data is transfered. If disabled it is always off.
438
+ #
439
+ # The default state is enabled.
440
+ def enable_status_led
441
+ send_request(FUNCTION_ENABLE_STATUS_LED, [], '', 0, '')
442
+ end
443
+
444
+ # Disables the status LED.
445
+ #
446
+ # The status LED is the blue LED next to the USB connector. If enabled is is
447
+ # on and it flickers if data is transfered. If disabled it is always off.
448
+ #
449
+ # The default state is enabled.
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
+ def is_status_led_enabled
456
+ send_request(FUNCTION_IS_STATUS_LED_ENABLED, [], '', 1, '?')
457
+ end
458
+
459
+ # Returns the firmware and protocol version and the name of the Bricklet for a
460
+ # given port.
461
+ #
462
+ # This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
463
+ # plugins.
464
+ def get_protocol1_bricklet_name(port)
465
+ send_request(FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 44, 'C C3 Z40')
466
+ end
467
+
468
+ # Returns the temperature in °C/10 as measured inside the microcontroller. The
469
+ # value returned is not the ambient temperature!
470
+ #
471
+ # The temperature is only proportional to the real temperature and it has an
472
+ # accuracy of +-15%. Practically it is only useful as an indicator for
473
+ # temperature changes.
474
+ def get_chip_temperature
475
+ send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
476
+ end
477
+
478
+ # Calling this function will reset the Brick. Calling this function
479
+ # on a Brick inside of a stack will reset the whole stack.
480
+ #
481
+ # After a reset you have to create new device objects,
482
+ # calling functions on the existing ones will result in
483
+ # undefined behavior!
484
+ def reset
485
+ send_request(FUNCTION_RESET, [], '', 0, '')
486
+ end
487
+
488
+ # Returns the UID, the UID where the Brick is connected to,
489
+ # the position, the hardware and firmware version as well as the
490
+ # device identifier.
491
+ #
492
+ # The position can be '0'-'8' (stack position).
493
+ #
494
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
495
+ # |device_identifier_constant|
496
+ def get_identity
497
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
498
+ end
499
+
500
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
501
+ def register_callback(id, &block)
502
+ callback = block
503
+ @registered_callbacks[id] = callback
504
+ end
505
+ end
506
+ end