tinkerforge 2.1.23 → 2.1.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/lib/tinkerforge/brick_dc.rb +156 -75
  3. data/lib/tinkerforge/brick_hat.rb +109 -30
  4. data/lib/tinkerforge/brick_hat_zero.rb +119 -21
  5. data/lib/tinkerforge/brick_imu.rb +191 -86
  6. data/lib/tinkerforge/brick_imu_v2.rb +219 -118
  7. data/lib/tinkerforge/brick_master.rb +495 -195
  8. data/lib/tinkerforge/brick_red.rb +197 -74
  9. data/lib/tinkerforge/brick_servo.rb +186 -102
  10. data/lib/tinkerforge/brick_silent_stepper.rb +248 -168
  11. data/lib/tinkerforge/brick_stepper.rb +212 -100
  12. data/lib/tinkerforge/bricklet_accelerometer.rb +61 -36
  13. data/lib/tinkerforge/bricklet_accelerometer_v2.rb +107 -63
  14. data/lib/tinkerforge/bricklet_air_quality.rb +123 -76
  15. data/lib/tinkerforge/bricklet_ambient_light.rb +62 -46
  16. data/lib/tinkerforge/bricklet_ambient_light_v2.rb +41 -28
  17. data/lib/tinkerforge/bricklet_ambient_light_v3.rb +61 -28
  18. data/lib/tinkerforge/bricklet_analog_in.rb +66 -45
  19. data/lib/tinkerforge/bricklet_analog_in_v2.rb +60 -43
  20. data/lib/tinkerforge/bricklet_analog_in_v3.rb +68 -32
  21. data/lib/tinkerforge/bricklet_analog_out.rb +25 -16
  22. data/lib/tinkerforge/bricklet_analog_out_v2.rb +21 -10
  23. data/lib/tinkerforge/bricklet_analog_out_v3.rb +55 -22
  24. data/lib/tinkerforge/bricklet_barometer.rb +108 -58
  25. data/lib/tinkerforge/bricklet_barometer_v2.rb +109 -67
  26. data/lib/tinkerforge/bricklet_can.rb +84 -24
  27. data/lib/tinkerforge/bricklet_can_v2.rb +173 -72
  28. data/lib/tinkerforge/bricklet_co2.rb +36 -25
  29. data/lib/tinkerforge/bricklet_co2_v2.rb +119 -60
  30. data/lib/tinkerforge/bricklet_color.rb +75 -47
  31. data/lib/tinkerforge/bricklet_color_v2.rb +91 -47
  32. data/lib/tinkerforge/bricklet_compass.rb +81 -40
  33. data/lib/tinkerforge/bricklet_current12.rb +61 -40
  34. data/lib/tinkerforge/bricklet_current25.rb +61 -40
  35. data/lib/tinkerforge/bricklet_distance_ir.rb +60 -38
  36. data/lib/tinkerforge/bricklet_distance_ir_v2.rb +85 -45
  37. data/lib/tinkerforge/bricklet_distance_us.rb +43 -30
  38. data/lib/tinkerforge/bricklet_distance_us_v2.rb +68 -33
  39. data/lib/tinkerforge/bricklet_dmx.rb +92 -48
  40. data/lib/tinkerforge/bricklet_dual_button.rb +23 -12
  41. data/lib/tinkerforge/bricklet_dual_button_v2.rb +64 -29
  42. data/lib/tinkerforge/bricklet_dual_relay.rb +27 -14
  43. data/lib/tinkerforge/bricklet_dust_detector.rb +43 -30
  44. data/lib/tinkerforge/bricklet_e_paper_296x128.rb +115 -63
  45. data/lib/tinkerforge/bricklet_energy_monitor.rb +81 -40
  46. data/lib/tinkerforge/bricklet_gps.rb +72 -48
  47. data/lib/tinkerforge/bricklet_gps_v2.rb +124 -73
  48. data/lib/tinkerforge/bricklet_hall_effect.rb +43 -28
  49. data/lib/tinkerforge/bricklet_hall_effect_v2.rb +76 -44
  50. data/lib/tinkerforge/bricklet_humidity.rb +54 -38
  51. data/lib/tinkerforge/bricklet_humidity_v2.rb +86 -49
  52. data/lib/tinkerforge/bricklet_imu_v3.rb +784 -0
  53. data/lib/tinkerforge/bricklet_industrial_analog_out.rb +41 -18
  54. data/lib/tinkerforge/bricklet_industrial_analog_out_v2.rb +84 -40
  55. data/lib/tinkerforge/bricklet_industrial_counter.rb +102 -59
  56. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +51 -24
  57. data/lib/tinkerforge/bricklet_industrial_digital_in_4_v2.rb +79 -40
  58. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +36 -15
  59. data/lib/tinkerforge/bricklet_industrial_digital_out_4_v2.rb +75 -33
  60. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +43 -29
  61. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma_v2.rb +81 -44
  62. data/lib/tinkerforge/bricklet_industrial_dual_ac_relay.rb +325 -0
  63. data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +51 -30
  64. data/lib/tinkerforge/bricklet_industrial_dual_analog_in_v2.rb +139 -40
  65. data/lib/tinkerforge/bricklet_industrial_dual_relay.rb +63 -28
  66. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +36 -15
  67. data/lib/tinkerforge/bricklet_industrial_quad_relay_v2.rb +67 -28
  68. data/lib/tinkerforge/bricklet_io16.rb +57 -32
  69. data/lib/tinkerforge/bricklet_io16_v2.rb +93 -48
  70. data/lib/tinkerforge/bricklet_io4.rb +56 -31
  71. data/lib/tinkerforge/bricklet_io4_v2.rb +109 -57
  72. data/lib/tinkerforge/bricklet_isolator.rb +111 -35
  73. data/lib/tinkerforge/bricklet_joystick.rb +63 -42
  74. data/lib/tinkerforge/bricklet_joystick_v2.rb +71 -35
  75. data/lib/tinkerforge/bricklet_laser_range_finder.rb +87 -59
  76. data/lib/tinkerforge/bricklet_laser_range_finder_v2.rb +99 -51
  77. data/lib/tinkerforge/bricklet_lcd_128x64.rb +219 -131
  78. data/lib/tinkerforge/bricklet_lcd_16x2.rb +49 -25
  79. data/lib/tinkerforge/bricklet_lcd_20x4.rb +59 -29
  80. data/lib/tinkerforge/bricklet_led_strip.rb +69 -47
  81. data/lib/tinkerforge/bricklet_led_strip_v2.rb +105 -48
  82. data/lib/tinkerforge/bricklet_line.rb +35 -22
  83. data/lib/tinkerforge/bricklet_linear_poti.rb +53 -35
  84. data/lib/tinkerforge/bricklet_linear_poti_v2.rb +55 -24
  85. data/lib/tinkerforge/bricklet_load_cell.rb +64 -40
  86. data/lib/tinkerforge/bricklet_load_cell_v2.rb +81 -41
  87. data/lib/tinkerforge/bricklet_moisture.rb +43 -30
  88. data/lib/tinkerforge/bricklet_motion_detector.rb +21 -10
  89. data/lib/tinkerforge/bricklet_motion_detector_v2.rb +62 -29
  90. data/lib/tinkerforge/bricklet_motorized_linear_poti.rb +71 -32
  91. data/lib/tinkerforge/bricklet_multi_touch.rb +30 -17
  92. data/lib/tinkerforge/bricklet_multi_touch_v2.rb +76 -39
  93. data/lib/tinkerforge/bricklet_nfc.rb +130 -80
  94. data/lib/tinkerforge/bricklet_nfc_rfid.rb +32 -13
  95. data/lib/tinkerforge/bricklet_oled_128x64.rb +30 -17
  96. data/lib/tinkerforge/bricklet_oled_128x64_v2.rb +75 -40
  97. data/lib/tinkerforge/bricklet_oled_64x48.rb +30 -17
  98. data/lib/tinkerforge/bricklet_one_wire.rb +65 -24
  99. data/lib/tinkerforge/bricklet_outdoor_weather.rb +84 -41
  100. data/lib/tinkerforge/bricklet_particulate_matter.rb +85 -37
  101. data/lib/tinkerforge/bricklet_performance_dc.rb +676 -0
  102. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +19 -13
  103. data/lib/tinkerforge/bricklet_piezo_speaker.rb +22 -19
  104. data/lib/tinkerforge/bricklet_piezo_speaker_v2.rb +84 -57
  105. data/lib/tinkerforge/bricklet_ptc.rb +76 -51
  106. data/lib/tinkerforge/bricklet_ptc_v2.rb +96 -54
  107. data/lib/tinkerforge/bricklet_real_time_clock.rb +45 -36
  108. data/lib/tinkerforge/bricklet_real_time_clock_v2.rb +78 -47
  109. data/lib/tinkerforge/bricklet_remote_switch.rb +38 -29
  110. data/lib/tinkerforge/bricklet_remote_switch_v2.rb +86 -49
  111. data/lib/tinkerforge/bricklet_rgb_led.rb +17 -8
  112. data/lib/tinkerforge/bricklet_rgb_led_button.rb +61 -30
  113. data/lib/tinkerforge/bricklet_rgb_led_matrix.rb +78 -33
  114. data/lib/tinkerforge/bricklet_rgb_led_v2.rb +51 -20
  115. data/lib/tinkerforge/bricklet_rotary_encoder.rb +40 -25
  116. data/lib/tinkerforge/bricklet_rotary_encoder_v2.rb +60 -27
  117. data/lib/tinkerforge/bricklet_rotary_poti.rb +55 -37
  118. data/lib/tinkerforge/bricklet_rotary_poti_v2.rb +57 -26
  119. data/lib/tinkerforge/bricklet_rs232.rb +89 -28
  120. data/lib/tinkerforge/bricklet_rs232_v2.rb +121 -47
  121. data/lib/tinkerforge/bricklet_rs485.rb +250 -164
  122. data/lib/tinkerforge/bricklet_segment_display_4x7.rb +24 -14
  123. data/lib/tinkerforge/bricklet_segment_display_4x7_v2.rb +75 -36
  124. data/lib/tinkerforge/bricklet_servo_v2.rb +565 -0
  125. data/lib/tinkerforge/bricklet_solid_state_relay.rb +24 -13
  126. data/lib/tinkerforge/bricklet_solid_state_relay_v2.rb +58 -25
  127. data/lib/tinkerforge/bricklet_sound_intensity.rb +36 -24
  128. data/lib/tinkerforge/bricklet_sound_pressure_level.rb +77 -41
  129. data/lib/tinkerforge/bricklet_temperature.rb +43 -28
  130. data/lib/tinkerforge/bricklet_temperature_ir.rb +61 -47
  131. data/lib/tinkerforge/bricklet_temperature_ir_v2.rb +74 -44
  132. data/lib/tinkerforge/bricklet_temperature_v2.rb +62 -31
  133. data/lib/tinkerforge/bricklet_thermal_imaging.rb +118 -68
  134. data/lib/tinkerforge/bricklet_thermocouple.rb +46 -30
  135. data/lib/tinkerforge/bricklet_thermocouple_v2.rb +65 -30
  136. data/lib/tinkerforge/bricklet_tilt.rb +23 -10
  137. data/lib/tinkerforge/bricklet_uv_light.rb +37 -24
  138. data/lib/tinkerforge/bricklet_uv_light_v2.rb +87 -46
  139. data/lib/tinkerforge/bricklet_voltage.rb +54 -37
  140. data/lib/tinkerforge/bricklet_voltage_current.rb +94 -85
  141. data/lib/tinkerforge/bricklet_voltage_current_v2.rb +92 -77
  142. data/lib/tinkerforge/bricklet_xmc1400_breakout.rb +81 -36
  143. data/lib/tinkerforge/device_display_names.rb +167 -0
  144. data/lib/tinkerforge/ip_connection.rb +156 -33
  145. data/lib/tinkerforge/version.rb +1 -1
  146. metadata +8 -3
@@ -1,14 +1,16 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2019-08-23. #
3
+ # This file was automatically generated on 2021-01-15. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.23 #
5
+ # Ruby Bindings Version 2.1.28 #
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
9
  # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
+ require_relative './ip_connection'
13
+
12
14
  module Tinkerforge
13
15
  # Four 7-segment displays with switchable colon
14
16
  class BrickletSegmentDisplay4x7 < Device
@@ -29,7 +31,7 @@ module Tinkerforge
29
31
  # Creates an object with the unique device ID <tt>uid</tt> and adds it to
30
32
  # the IP Connection <tt>ipcon</tt>.
31
33
  def initialize(uid, ipcon)
32
- super uid, ipcon
34
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
33
35
 
34
36
  @api_version = [2, 0, 0]
35
37
 
@@ -39,8 +41,9 @@ module Tinkerforge
39
41
  @response_expected[FUNCTION_GET_COUNTER_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
40
42
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
41
43
 
42
- @callback_formats[CALLBACK_COUNTER_FINISHED] = ''
44
+ @callback_formats[CALLBACK_COUNTER_FINISHED] = [8, '']
43
45
 
46
+ @ipcon.add_device self
44
47
  end
45
48
 
46
49
  # The 7-segment display can be set with bitmaps. Every bit controls one
@@ -57,50 +60,57 @@ module Tinkerforge
57
60
  # The brightness can be set between 0 (dark) and 7 (bright). The colon
58
61
  # parameter turns the colon of the display on or off.
59
62
  def set_segments(segments, brightness, colon)
60
- send_request FUNCTION_SET_SEGMENTS, [segments, brightness, colon], 'C4 C ?', 0, ''
63
+ check_validity
64
+
65
+ send_request FUNCTION_SET_SEGMENTS, [segments, brightness, colon], 'C4 C ?', 8, ''
61
66
  end
62
67
 
63
68
  # Returns the segment, brightness and color data as set by
64
69
  # BrickletSegmentDisplay4x7#set_segments.
65
70
  def get_segments
66
- send_request FUNCTION_GET_SEGMENTS, [], '', 6, 'C4 C ?'
71
+ check_validity
72
+
73
+ send_request FUNCTION_GET_SEGMENTS, [], '', 14, 'C4 C ?'
67
74
  end
68
75
 
69
76
  # Starts a counter with the *from* value that counts to the *to*
70
77
  # value with the each step incremented by *increment*.
71
- # The *length* of the increment is given in ms.
78
+ # *length* is the pause between each increment.
72
79
  #
73
80
  # Example: If you set *from* to 0, *to* to 100, *increment* to 1 and
74
81
  # *length* to 1000, a counter that goes from 0 to 100 with one second
75
82
  # pause between each increment will be started.
76
83
  #
77
- # The maximum values for *from*, *to* and *increment* is 9999,
78
- # the minimum value is -999.
79
- #
80
84
  # Using a negative increment allows to count backwards.
81
85
  #
82
86
  # You can stop the counter at every time by calling BrickletSegmentDisplay4x7#set_segments.
83
87
  def start_counter(value_from, value_to, increment, length)
84
- send_request FUNCTION_START_COUNTER, [value_from, value_to, increment, length], 's s s L', 0, ''
88
+ check_validity
89
+
90
+ send_request FUNCTION_START_COUNTER, [value_from, value_to, increment, length], 's s s L', 8, ''
85
91
  end
86
92
 
87
93
  # Returns the counter value that is currently shown on the display.
88
94
  #
89
95
  # If there is no counter running a 0 will be returned.
90
96
  def get_counter_value
91
- send_request FUNCTION_GET_COUNTER_VALUE, [], '', 2, 'S'
97
+ check_validity
98
+
99
+ send_request FUNCTION_GET_COUNTER_VALUE, [], '', 10, 'S'
92
100
  end
93
101
 
94
102
  # Returns the UID, the UID where the Bricklet is connected to,
95
103
  # the position, the hardware and firmware version as well as the
96
104
  # device identifier.
97
105
  #
98
- # The position can be 'a', 'b', 'c' or 'd'.
106
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
107
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
108
+ # position 'z'.
99
109
  #
100
110
  # The device identifier numbers can be found :ref:`here <device_identifier>`.
101
111
  # |device_identifier_constant|
102
112
  def get_identity
103
- send_request FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S'
113
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
104
114
  end
105
115
 
106
116
  # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
@@ -1,14 +1,16 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2019-08-23. #
3
+ # This file was automatically generated on 2021-01-15. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.23 #
5
+ # Ruby Bindings Version 2.1.28 #
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
9
  # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
+ require_relative './ip_connection'
13
+
12
14
  module Tinkerforge
13
15
  # Four 7-segment displays with switchable dots
14
16
  class BrickletSegmentDisplay4x7V2 < Device
@@ -60,7 +62,7 @@ module Tinkerforge
60
62
  # Creates an object with the unique device ID <tt>uid</tt> and adds it to
61
63
  # the IP Connection <tt>ipcon</tt>.
62
64
  def initialize(uid, ipcon)
63
- super uid, ipcon
65
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
64
66
 
65
67
  @api_version = [2, 0, 0]
66
68
 
@@ -86,8 +88,9 @@ module Tinkerforge
86
88
  @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
87
89
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
88
90
 
89
- @callback_formats[CALLBACK_COUNTER_FINISHED] = ''
91
+ @callback_formats[CALLBACK_COUNTER_FINISHED] = [8, '']
90
92
 
93
+ @ipcon.add_device self
91
94
  end
92
95
 
93
96
  # Sets the segments of the Segment Display 4x7 Bricklet 2.0 segment-by-segment.
@@ -101,28 +104,33 @@ module Tinkerforge
101
104
  # :alt: Indices of segments
102
105
  # :align: center
103
106
  def set_segments(digit0, digit1, digit2, digit3, colon, tick)
104
- send_request FUNCTION_SET_SEGMENTS, [digit0, digit1, digit2, digit3, colon, tick], '?8 ?8 ?8 ?8 ?2 ?', 0, ''
107
+ check_validity
108
+
109
+ send_request FUNCTION_SET_SEGMENTS, [digit0, digit1, digit2, digit3, colon, tick], '?8 ?8 ?8 ?8 ?2 ?', 8, ''
105
110
  end
106
111
 
107
112
  # Returns the segment data as set by BrickletSegmentDisplay4x7V2#set_segments.
108
113
  def get_segments
109
- send_request FUNCTION_GET_SEGMENTS, [], '', 35, '?8 ?8 ?8 ?8 ?2 ?'
114
+ check_validity
115
+
116
+ send_request FUNCTION_GET_SEGMENTS, [], '', 14, '?8 ?8 ?8 ?8 ?2 ?'
110
117
  end
111
118
 
112
- # The brightness can be set between 0 (dark) and 7 (bright).
113
- #
114
- # The default value is 7.
119
+ # The brightness can be set between 0 (dark) and 7 (bright).
115
120
  def set_brightness(brightness)
116
- send_request FUNCTION_SET_BRIGHTNESS, [brightness], 'C', 0, ''
121
+ check_validity
122
+
123
+ send_request FUNCTION_SET_BRIGHTNESS, [brightness], 'C', 8, ''
117
124
  end
118
125
 
119
126
  # Returns the brightness as set by BrickletSegmentDisplay4x7V2#set_brightness.
120
127
  def get_brightness
121
- send_request FUNCTION_GET_BRIGHTNESS, [], '', 1, 'C'
128
+ check_validity
129
+
130
+ send_request FUNCTION_GET_BRIGHTNESS, [], '', 9, 'C'
122
131
  end
123
132
 
124
- # Sets a numeric value for each of the digits. The values can be between
125
- # -2 and 15. They represent:
133
+ # Sets a numeric value for each of the digits. They represent:
126
134
  #
127
135
  # * -2: minus sign
128
136
  # * -1: blank
@@ -136,7 +144,9 @@ module Tinkerforge
136
144
  #
137
145
  # Example: A call with [-2, -1, 4, 2] will result in a display of "- 42".
138
146
  def set_numeric_value(value)
139
- send_request FUNCTION_SET_NUMERIC_VALUE, [value], 'c4', 0, ''
147
+ check_validity
148
+
149
+ send_request FUNCTION_SET_NUMERIC_VALUE, [value], 'c4', 8, ''
140
150
  end
141
151
 
142
152
  # Turns one specified segment on or off.
@@ -148,38 +158,43 @@ module Tinkerforge
148
158
  # :alt: Indices of selected segments
149
159
  # :align: center
150
160
  def set_selected_segment(segment, value)
151
- send_request FUNCTION_SET_SELECTED_SEGMENT, [segment, value], 'C ?', 0, ''
161
+ check_validity
162
+
163
+ send_request FUNCTION_SET_SELECTED_SEGMENT, [segment, value], 'C ?', 8, ''
152
164
  end
153
165
 
154
166
  # Returns the value of a single segment.
155
167
  def get_selected_segment(segment)
156
- send_request FUNCTION_GET_SELECTED_SEGMENT, [segment], 'C', 1, '?'
168
+ check_validity
169
+
170
+ send_request FUNCTION_GET_SELECTED_SEGMENT, [segment], 'C', 9, '?'
157
171
  end
158
172
 
159
173
  # Starts a counter with the *from* value that counts to the *to*
160
174
  # value with the each step incremented by *increment*.
161
- # The *length* of the increment is given in ms.
175
+ # *length* is the pause between each increment.
162
176
  #
163
177
  # Example: If you set *from* to 0, *to* to 100, *increment* to 1 and
164
178
  # *length* to 1000, a counter that goes from 0 to 100 with one second
165
179
  # pause between each increment will be started.
166
180
  #
167
- # The maximum values for *from*, *to* and *increment* is 9999,
168
- # the minimum value is -999.
169
- #
170
181
  # Using a negative *increment* allows to count backwards.
171
182
  #
172
183
  # You can stop the counter at every time by calling BrickletSegmentDisplay4x7V2#set_segments
173
184
  # or BrickletSegmentDisplay4x7V2#set_numeric_value.
174
185
  def start_counter(value_from, value_to, increment, length)
175
- send_request FUNCTION_START_COUNTER, [value_from, value_to, increment, length], 's s s L', 0, ''
186
+ check_validity
187
+
188
+ send_request FUNCTION_START_COUNTER, [value_from, value_to, increment, length], 's s s L', 8, ''
176
189
  end
177
190
 
178
191
  # Returns the counter value that is currently shown on the display.
179
192
  #
180
193
  # If there is no counter running a 0 will be returned.
181
194
  def get_counter_value
182
- send_request FUNCTION_GET_COUNTER_VALUE, [], '', 2, 'S'
195
+ check_validity
196
+
197
+ send_request FUNCTION_GET_COUNTER_VALUE, [], '', 10, 'S'
183
198
  end
184
199
 
185
200
  # Returns the error count for the communication between Brick and Bricklet.
@@ -194,7 +209,9 @@ module Tinkerforge
194
209
  # The errors counts are for errors that occur on the Bricklet side. All
195
210
  # Bricks have a similar function that returns the errors on the Brick side.
196
211
  def get_spitfp_error_count
197
- send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 16, 'L L L L'
212
+ check_validity
213
+
214
+ send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
198
215
  end
199
216
 
200
217
  # Sets the bootloader mode and returns the status after the requested
@@ -207,12 +224,16 @@ module Tinkerforge
207
224
  # This function is used by Brick Viewer during flashing. It should not be
208
225
  # necessary to call it in a normal user program.
209
226
  def set_bootloader_mode(mode)
210
- send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 1, 'C'
227
+ check_validity
228
+
229
+ send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
211
230
  end
212
231
 
213
232
  # Returns the current bootloader mode, see BrickletSegmentDisplay4x7V2#set_bootloader_mode.
214
233
  def get_bootloader_mode
215
- send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 1, 'C'
234
+ check_validity
235
+
236
+ send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
216
237
  end
217
238
 
218
239
  # Sets the firmware pointer for BrickletSegmentDisplay4x7V2#write_firmware. The pointer has
@@ -222,7 +243,9 @@ module Tinkerforge
222
243
  # This function is used by Brick Viewer during flashing. It should not be
223
244
  # necessary to call it in a normal user program.
224
245
  def set_write_firmware_pointer(pointer)
225
- send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 0, ''
246
+ check_validity
247
+
248
+ send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
226
249
  end
227
250
 
228
251
  # Writes 64 Bytes of firmware at the position as written by
@@ -234,7 +257,9 @@ module Tinkerforge
234
257
  # This function is used by Brick Viewer during flashing. It should not be
235
258
  # necessary to call it in a normal user program.
236
259
  def write_firmware(data)
237
- send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 1, 'C'
260
+ check_validity
261
+
262
+ send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
238
263
  end
239
264
 
240
265
  # Sets the status LED configuration. By default the LED shows
@@ -245,22 +270,28 @@ module Tinkerforge
245
270
  #
246
271
  # If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
247
272
  def set_status_led_config(config)
248
- send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 0, ''
273
+ check_validity
274
+
275
+ send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
249
276
  end
250
277
 
251
278
  # Returns the configuration as set by BrickletSegmentDisplay4x7V2#set_status_led_config
252
279
  def get_status_led_config
253
- send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 1, 'C'
280
+ check_validity
281
+
282
+ send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
254
283
  end
255
284
 
256
- # Returns the temperature in °C as measured inside the microcontroller. The
285
+ # Returns the temperature as measured inside the microcontroller. The
257
286
  # value returned is not the ambient temperature!
258
287
  #
259
288
  # The temperature is only proportional to the real temperature and it has bad
260
289
  # accuracy. Practically it is only useful as an indicator for
261
290
  # temperature changes.
262
291
  def get_chip_temperature
263
- send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's'
292
+ check_validity
293
+
294
+ send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
264
295
  end
265
296
 
266
297
  # Calling this function will reset the Bricklet. All configurations
@@ -270,7 +301,9 @@ module Tinkerforge
270
301
  # calling functions on the existing ones will result in
271
302
  # undefined behavior!
272
303
  def reset
273
- send_request FUNCTION_RESET, [], '', 0, ''
304
+ check_validity
305
+
306
+ send_request FUNCTION_RESET, [], '', 8, ''
274
307
  end
275
308
 
276
309
  # Writes a new UID into flash. If you want to set a new UID
@@ -279,25 +312,31 @@ module Tinkerforge
279
312
  #
280
313
  # We recommend that you use Brick Viewer to change the UID.
281
314
  def write_uid(uid)
282
- send_request FUNCTION_WRITE_UID, [uid], 'L', 0, ''
315
+ check_validity
316
+
317
+ send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
283
318
  end
284
319
 
285
320
  # Returns the current UID as an integer. Encode as
286
321
  # Base58 to get the usual string version.
287
322
  def read_uid
288
- send_request FUNCTION_READ_UID, [], '', 4, 'L'
323
+ check_validity
324
+
325
+ send_request FUNCTION_READ_UID, [], '', 12, 'L'
289
326
  end
290
327
 
291
328
  # Returns the UID, the UID where the Bricklet is connected to,
292
329
  # the position, the hardware and firmware version as well as the
293
330
  # device identifier.
294
331
  #
295
- # The position can be 'a', 'b', 'c' or 'd'.
332
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
333
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
334
+ # position 'z'.
296
335
  #
297
336
  # The device identifier numbers can be found :ref:`here <device_identifier>`.
298
337
  # |device_identifier_constant|
299
338
  def get_identity
300
- send_request FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S'
339
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
301
340
  end
302
341
 
303
342
  # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
@@ -0,0 +1,565 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2021-01-15. #
4
+ # #
5
+ # Ruby Bindings Version 2.1.28 #
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
+ require_relative './ip_connection'
13
+
14
+ module Tinkerforge
15
+ # Drives up to 10 RC Servos
16
+ class BrickletServoV2 < Device
17
+ DEVICE_IDENTIFIER = 2157 # :nodoc:
18
+ DEVICE_DISPLAY_NAME = 'Servo Bricklet 2.0' # :nodoc:
19
+
20
+ # This callback is triggered when a position set by BrickletServoV2#set_position
21
+ # is reached. If the new position matches the current position then the
22
+ # callback is not triggered, because the servo didn't move.
23
+ # The parameters are the servo and the position that is reached.
24
+ #
25
+ # You can enable this callback with BrickletServoV2#set_position_reached_callback_configuration.
26
+ #
27
+ # .. note::
28
+ # Since we can't get any feedback from the servo, this only works if the
29
+ # velocity (see BrickletServoV2#set_motion_configuration) 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
+ FUNCTION_GET_STATUS = 1 # :nodoc:
35
+ FUNCTION_SET_ENABLE = 2 # :nodoc:
36
+ FUNCTION_GET_ENABLED = 3 # :nodoc:
37
+ FUNCTION_SET_POSITION = 4 # :nodoc:
38
+ FUNCTION_GET_POSITION = 5 # :nodoc:
39
+ FUNCTION_GET_CURRENT_POSITION = 6 # :nodoc:
40
+ FUNCTION_GET_CURRENT_VELOCITY = 7 # :nodoc:
41
+ FUNCTION_SET_MOTION_CONFIGURATION = 8 # :nodoc:
42
+ FUNCTION_GET_MOTION_CONFIGURATION = 9 # :nodoc:
43
+ FUNCTION_SET_PULSE_WIDTH = 10 # :nodoc:
44
+ FUNCTION_GET_PULSE_WIDTH = 11 # :nodoc:
45
+ FUNCTION_SET_DEGREE = 12 # :nodoc:
46
+ FUNCTION_GET_DEGREE = 13 # :nodoc:
47
+ FUNCTION_SET_PERIOD = 14 # :nodoc:
48
+ FUNCTION_GET_PERIOD = 15 # :nodoc:
49
+ FUNCTION_GET_SERVO_CURRENT = 16 # :nodoc:
50
+ FUNCTION_SET_SERVO_CURRENT_CONFIGURATION = 17 # :nodoc:
51
+ FUNCTION_GET_SERVO_CURRENT_CONFIGURATION = 18 # :nodoc:
52
+ FUNCTION_SET_INPUT_VOLTAGE_CONFIGURATION = 19 # :nodoc:
53
+ FUNCTION_GET_INPUT_VOLTAGE_CONFIGURATION = 20 # :nodoc:
54
+ FUNCTION_GET_OVERALL_CURRENT = 21 # :nodoc:
55
+ FUNCTION_GET_INPUT_VOLTAGE = 22 # :nodoc:
56
+ FUNCTION_SET_CURRENT_CALIBRATION = 23 # :nodoc:
57
+ FUNCTION_GET_CURRENT_CALIBRATION = 24 # :nodoc:
58
+ FUNCTION_SET_POSITION_REACHED_CALLBACK_CONFIGURATION = 25 # :nodoc:
59
+ FUNCTION_GET_POSITION_REACHED_CALLBACK_CONFIGURATION = 26 # :nodoc:
60
+ FUNCTION_GET_SPITFP_ERROR_COUNT = 234 # :nodoc:
61
+ FUNCTION_SET_BOOTLOADER_MODE = 235 # :nodoc:
62
+ FUNCTION_GET_BOOTLOADER_MODE = 236 # :nodoc:
63
+ FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237 # :nodoc:
64
+ FUNCTION_WRITE_FIRMWARE = 238 # :nodoc:
65
+ FUNCTION_SET_STATUS_LED_CONFIG = 239 # :nodoc:
66
+ FUNCTION_GET_STATUS_LED_CONFIG = 240 # :nodoc:
67
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
68
+ FUNCTION_RESET = 243 # :nodoc:
69
+ FUNCTION_WRITE_UID = 248 # :nodoc:
70
+ FUNCTION_READ_UID = 249 # :nodoc:
71
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
72
+
73
+ BOOTLOADER_MODE_BOOTLOADER = 0 # :nodoc:
74
+ BOOTLOADER_MODE_FIRMWARE = 1 # :nodoc:
75
+ BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2 # :nodoc:
76
+ BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3 # :nodoc:
77
+ BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4 # :nodoc:
78
+ BOOTLOADER_STATUS_OK = 0 # :nodoc:
79
+ BOOTLOADER_STATUS_INVALID_MODE = 1 # :nodoc:
80
+ BOOTLOADER_STATUS_NO_CHANGE = 2 # :nodoc:
81
+ BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT = 3 # :nodoc:
82
+ BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT = 4 # :nodoc:
83
+ BOOTLOADER_STATUS_CRC_MISMATCH = 5 # :nodoc:
84
+ STATUS_LED_CONFIG_OFF = 0 # :nodoc:
85
+ STATUS_LED_CONFIG_ON = 1 # :nodoc:
86
+ STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2 # :nodoc:
87
+ STATUS_LED_CONFIG_SHOW_STATUS = 3 # :nodoc:
88
+
89
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
90
+ # the IP Connection <tt>ipcon</tt>.
91
+ def initialize(uid, ipcon)
92
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
93
+
94
+ @api_version = [2, 0, 0]
95
+
96
+ @response_expected[FUNCTION_GET_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE
97
+ @response_expected[FUNCTION_SET_ENABLE] = RESPONSE_EXPECTED_FALSE
98
+ @response_expected[FUNCTION_GET_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
99
+ @response_expected[FUNCTION_SET_POSITION] = RESPONSE_EXPECTED_FALSE
100
+ @response_expected[FUNCTION_GET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
101
+ @response_expected[FUNCTION_GET_CURRENT_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
102
+ @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+ @response_expected[FUNCTION_SET_MOTION_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
104
+ @response_expected[FUNCTION_GET_MOTION_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
105
+ @response_expected[FUNCTION_SET_PULSE_WIDTH] = RESPONSE_EXPECTED_FALSE
106
+ @response_expected[FUNCTION_GET_PULSE_WIDTH] = RESPONSE_EXPECTED_ALWAYS_TRUE
107
+ @response_expected[FUNCTION_SET_DEGREE] = RESPONSE_EXPECTED_FALSE
108
+ @response_expected[FUNCTION_GET_DEGREE] = RESPONSE_EXPECTED_ALWAYS_TRUE
109
+ @response_expected[FUNCTION_SET_PERIOD] = RESPONSE_EXPECTED_FALSE
110
+ @response_expected[FUNCTION_GET_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
111
+ @response_expected[FUNCTION_GET_SERVO_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
112
+ @response_expected[FUNCTION_SET_SERVO_CURRENT_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
113
+ @response_expected[FUNCTION_GET_SERVO_CURRENT_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
114
+ @response_expected[FUNCTION_SET_INPUT_VOLTAGE_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
115
+ @response_expected[FUNCTION_GET_INPUT_VOLTAGE_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
116
+ @response_expected[FUNCTION_GET_OVERALL_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
117
+ @response_expected[FUNCTION_GET_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
118
+ @response_expected[FUNCTION_SET_CURRENT_CALIBRATION] = RESPONSE_EXPECTED_FALSE
119
+ @response_expected[FUNCTION_GET_CURRENT_CALIBRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
120
+ @response_expected[FUNCTION_SET_POSITION_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
121
+ @response_expected[FUNCTION_GET_POSITION_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
122
+ @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
123
+ @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
124
+ @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
125
+ @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE
126
+ @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE
127
+ @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
128
+ @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
129
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
130
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
131
+ @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE
132
+ @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
133
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
134
+
135
+ @callback_formats[CALLBACK_POSITION_REACHED] = [12, 'S s']
136
+
137
+ @ipcon.add_device self
138
+ end
139
+
140
+ # Returns the status information of the Servo Bricklet 2.0.
141
+ #
142
+ # The status includes
143
+ #
144
+ # * for each channel if it is enabled or disabled,
145
+ # * for each channel the current position,
146
+ # * for each channel the current velocity,
147
+ # * for each channel the current usage and
148
+ # * the input voltage.
149
+ #
150
+ # Please note that the position and the velocity is a snapshot of the
151
+ # current position and velocity of the servo in motion.
152
+ def get_status
153
+ check_validity
154
+
155
+ send_request FUNCTION_GET_STATUS, [], '', 72, '?10 s10 s10 S10 S'
156
+ end
157
+
158
+ # Enables a servo channel (0 to 9). If a servo is enabled, the configured position,
159
+ # velocity, acceleration, etc. are applied immediately.
160
+ def set_enable(servo_channel, enable)
161
+ check_validity
162
+
163
+ send_request FUNCTION_SET_ENABLE, [servo_channel, enable], 'S ?', 8, ''
164
+ end
165
+
166
+ # Returns *true* if the specified servo channel is enabled, *false* otherwise.
167
+ def get_enabled(servo_channel)
168
+ check_validity
169
+
170
+ send_request FUNCTION_GET_ENABLED, [servo_channel], 'S', 9, '?'
171
+ end
172
+
173
+ # Sets the position in °/100 for the specified servo channel.
174
+ #
175
+ # The default range of the position is -9000 to 9000, but it can be specified
176
+ # according to your servo with BrickletServoV2#set_degree.
177
+ #
178
+ # If you want to control a linear servo or RC brushless motor controller or
179
+ # similar with the Servo Brick, you can also define lengths or speeds with
180
+ # BrickletServoV2#set_degree.
181
+ def set_position(servo_channel, position)
182
+ check_validity
183
+
184
+ send_request FUNCTION_SET_POSITION, [servo_channel, position], 'S s', 8, ''
185
+ end
186
+
187
+ # Returns the position of the specified servo channel as set by BrickletServoV2#set_position.
188
+ def get_position(servo_channel)
189
+ check_validity
190
+
191
+ send_request FUNCTION_GET_POSITION, [servo_channel], 'S', 10, 's'
192
+ end
193
+
194
+ # Returns the *current* position of the specified servo channel. This may not be the
195
+ # value of BrickletServoV2#set_position if the servo is currently approaching a
196
+ # position goal.
197
+ def get_current_position(servo_channel)
198
+ check_validity
199
+
200
+ send_request FUNCTION_GET_CURRENT_POSITION, [servo_channel], 'S', 10, 's'
201
+ end
202
+
203
+ # Returns the *current* velocity of the specified servo channel. This may not be the
204
+ # velocity specified by BrickletServoV2#set_motion_configuration. if the servo is
205
+ # currently approaching a velocity goal.
206
+ def get_current_velocity(servo_channel)
207
+ check_validity
208
+
209
+ send_request FUNCTION_GET_CURRENT_VELOCITY, [servo_channel], 'S', 10, 'S'
210
+ end
211
+
212
+ # Sets the maximum velocity of the specified servo channel in °/100s as well as
213
+ # the acceleration and deceleration in °/100s²
214
+ #
215
+ # With a velocity of 0 °/100s the position will be set immediately (no velocity).
216
+ #
217
+ # With an acc-/deceleration of 0 °/100s² the velocity will be set immediately
218
+ # (no acc-/deceleration).
219
+ def set_motion_configuration(servo_channel, velocity, acceleration, deceleration)
220
+ check_validity
221
+
222
+ send_request FUNCTION_SET_MOTION_CONFIGURATION, [servo_channel, velocity, acceleration, deceleration], 'S L L L', 8, ''
223
+ end
224
+
225
+ # Returns the motion configuration as set by BrickletServoV2#set_motion_configuration.
226
+ def get_motion_configuration(servo_channel)
227
+ check_validity
228
+
229
+ send_request FUNCTION_GET_MOTION_CONFIGURATION, [servo_channel], 'S', 20, 'L L L'
230
+ end
231
+
232
+ # Sets the minimum and maximum pulse width of the specified servo channel in µs.
233
+ #
234
+ # Usually, servos are controlled with a
235
+ # `PWM <https://en.wikipedia.org/wiki/Pulse-width_modulation>`__, whereby the
236
+ # length of the pulse controls the position of the servo. Every servo has
237
+ # different minimum and maximum pulse widths, these can be specified with
238
+ # this function.
239
+ #
240
+ # If you have a datasheet for your servo that specifies the minimum and
241
+ # maximum pulse width, you should set the values accordingly. If your servo
242
+ # comes without any datasheet you have to find the values via trial and error.
243
+ #
244
+ # Both values have a range from 1 to 65535 (unsigned 16-bit integer). The
245
+ # minimum must be smaller than the maximum.
246
+ #
247
+ # The default values are 1000µs (1ms) and 2000µs (2ms) for minimum and
248
+ # maximum pulse width.
249
+ def set_pulse_width(servo_channel, min, max)
250
+ check_validity
251
+
252
+ send_request FUNCTION_SET_PULSE_WIDTH, [servo_channel, min, max], 'S L L', 8, ''
253
+ end
254
+
255
+ # Returns the minimum and maximum pulse width for the specified servo channel as set by
256
+ # BrickletServoV2#set_pulse_width.
257
+ def get_pulse_width(servo_channel)
258
+ check_validity
259
+
260
+ send_request FUNCTION_GET_PULSE_WIDTH, [servo_channel], 'S', 16, 'L L'
261
+ end
262
+
263
+ # Sets the minimum and maximum degree for the specified servo channel (by default
264
+ # given as °/100).
265
+ #
266
+ # This only specifies the abstract values between which the minimum and maximum
267
+ # pulse width is scaled. For example: If you specify a pulse width of 1000µs
268
+ # to 2000µs and a degree range of -90° to 90°, a call of BrickletServoV2#set_position
269
+ # with 0 will result in a pulse width of 1500µs
270
+ # (-90° = 1000µs, 90° = 2000µs, etc.).
271
+ #
272
+ # Possible usage:
273
+ #
274
+ # * The datasheet of your servo specifies a range of 200° with the middle position
275
+ # at 110°. In this case you can set the minimum to -9000 and the maximum to 11000.
276
+ # * You measure a range of 220° on your servo and you don't have or need a middle
277
+ # position. In this case you can set the minimum to 0 and the maximum to 22000.
278
+ # * You have a linear servo with a drive length of 20cm, In this case you could
279
+ # set the minimum to 0 and the maximum to 20000. Now you can set the Position
280
+ # with BrickletServoV2#set_position with a resolution of cm/100. Also the velocity will
281
+ # have a resolution of cm/100s and the acceleration will have a resolution of
282
+ # cm/100s².
283
+ # * You don't care about units and just want the highest possible resolution. In
284
+ # this case you should set the minimum to -32767 and the maximum to 32767.
285
+ # * You have a brushless motor with a maximum speed of 10000 rpm and want to
286
+ # control it with a RC brushless motor controller. In this case you can set the
287
+ # minimum to 0 and the maximum to 10000. BrickletServoV2#set_position now controls the rpm.
288
+ #
289
+ # Both values have a possible range from -32767 to 32767
290
+ # (signed 16-bit integer). The minimum must be smaller than the maximum.
291
+ #
292
+ # The default values are -9000 and 9000 for the minimum and maximum degree.
293
+ def set_degree(servo_channel, min, max)
294
+ check_validity
295
+
296
+ send_request FUNCTION_SET_DEGREE, [servo_channel, min, max], 'S s s', 8, ''
297
+ end
298
+
299
+ # Returns the minimum and maximum degree for the specified servo channel as set by
300
+ # BrickletServoV2#set_degree.
301
+ def get_degree(servo_channel)
302
+ check_validity
303
+
304
+ send_request FUNCTION_GET_DEGREE, [servo_channel], 'S', 12, 's s'
305
+ end
306
+
307
+ # Sets the period of the specified servo channel in µs.
308
+ #
309
+ # Usually, servos are controlled with a
310
+ # `PWM <https://en.wikipedia.org/wiki/Pulse-width_modulation>`__. Different
311
+ # servos expect PWMs with different periods. Most servos run well with a
312
+ # period of about 20ms.
313
+ #
314
+ # If your servo comes with a datasheet that specifies a period, you should
315
+ # set it accordingly. If you don't have a datasheet and you have no idea
316
+ # what the correct period is, the default value (19.5ms) will most likely
317
+ # work fine.
318
+ #
319
+ # The minimum possible period is 1µs and the maximum is 1000000µs.
320
+ #
321
+ # The default value is 19.5ms (19500µs).
322
+ def set_period(servo_channel, period)
323
+ check_validity
324
+
325
+ send_request FUNCTION_SET_PERIOD, [servo_channel, period], 'S L', 8, ''
326
+ end
327
+
328
+ # Returns the period for the specified servo channel as set by BrickletServoV2#set_period.
329
+ def get_period(servo_channel)
330
+ check_validity
331
+
332
+ send_request FUNCTION_GET_PERIOD, [servo_channel], 'S', 12, 'L'
333
+ end
334
+
335
+ # Returns the current consumption of the specified servo channel in mA.
336
+ def get_servo_current(servo_channel)
337
+ check_validity
338
+
339
+ send_request FUNCTION_GET_SERVO_CURRENT, [servo_channel], 'S', 10, 'S'
340
+ end
341
+
342
+ # Sets the averaging duration of the current measurement for the specified servo channel in ms.
343
+ def set_servo_current_configuration(servo_channel, averaging_duration)
344
+ check_validity
345
+
346
+ send_request FUNCTION_SET_SERVO_CURRENT_CONFIGURATION, [servo_channel, averaging_duration], 'S C', 8, ''
347
+ end
348
+
349
+ # Returns the servo current configuration for the specified servo channel as set
350
+ # by BrickletServoV2#set_servo_current_configuration.
351
+ def get_servo_current_configuration(servo_channel)
352
+ check_validity
353
+
354
+ send_request FUNCTION_GET_SERVO_CURRENT_CONFIGURATION, [servo_channel], 'S', 9, 'C'
355
+ end
356
+
357
+ # Sets the averaging duration of the input voltage measurement for the specified servo channel in ms.
358
+ def set_input_voltage_configuration(averaging_duration)
359
+ check_validity
360
+
361
+ send_request FUNCTION_SET_INPUT_VOLTAGE_CONFIGURATION, [averaging_duration], 'C', 8, ''
362
+ end
363
+
364
+ # Returns the input voltage configuration as set by BrickletServoV2#set_input_voltage_configuration.
365
+ def get_input_voltage_configuration
366
+ check_validity
367
+
368
+ send_request FUNCTION_GET_INPUT_VOLTAGE_CONFIGURATION, [], '', 9, 'C'
369
+ end
370
+
371
+ # Returns the current consumption of all servos together in mA.
372
+ def get_overall_current
373
+ check_validity
374
+
375
+ send_request FUNCTION_GET_OVERALL_CURRENT, [], '', 10, 'S'
376
+ end
377
+
378
+ # Returns the input voltage in mV. The input voltage is
379
+ # given via the black power input connector on the Servo Brick.
380
+ def get_input_voltage
381
+ check_validity
382
+
383
+ send_request FUNCTION_GET_INPUT_VOLTAGE, [], '', 10, 'S'
384
+ end
385
+
386
+ # Sets an offset value (in mA) for each channel.
387
+ #
388
+ # Note: On delivery the Servo Bricklet 2.0 is already calibrated.
389
+ def set_current_calibration(offset)
390
+ check_validity
391
+
392
+ send_request FUNCTION_SET_CURRENT_CALIBRATION, [offset], 's10', 8, ''
393
+ end
394
+
395
+ # Returns the current calibration as set by BrickletServoV2#set_current_calibration.
396
+ def get_current_calibration
397
+ check_validity
398
+
399
+ send_request FUNCTION_GET_CURRENT_CALIBRATION, [], '', 28, 's10'
400
+ end
401
+
402
+ # Enable/Disable CALLBACK_POSITION_REACHED callback.
403
+ def set_position_reached_callback_configuration(servo_channel, enabled)
404
+ check_validity
405
+
406
+ send_request FUNCTION_SET_POSITION_REACHED_CALLBACK_CONFIGURATION, [servo_channel, enabled], 'S ?', 8, ''
407
+ end
408
+
409
+ # Returns the callback configuration as set by
410
+ # BrickletServoV2#set_position_reached_callback_configuration.
411
+ def get_position_reached_callback_configuration(servo_channel)
412
+ check_validity
413
+
414
+ send_request FUNCTION_GET_POSITION_REACHED_CALLBACK_CONFIGURATION, [servo_channel], 'S', 9, '?'
415
+ end
416
+
417
+ # Returns the error count for the communication between Brick and Bricklet.
418
+ #
419
+ # The errors are divided into
420
+ #
421
+ # * ACK checksum errors,
422
+ # * message checksum errors,
423
+ # * framing errors and
424
+ # * overflow errors.
425
+ #
426
+ # The errors counts are for errors that occur on the Bricklet side. All
427
+ # Bricks have a similar function that returns the errors on the Brick side.
428
+ def get_spitfp_error_count
429
+ check_validity
430
+
431
+ send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
432
+ end
433
+
434
+ # Sets the bootloader mode and returns the status after the requested
435
+ # mode change was instigated.
436
+ #
437
+ # You can change from bootloader mode to firmware mode and vice versa. A change
438
+ # from bootloader mode to firmware mode will only take place if the entry function,
439
+ # device identifier and CRC are present and correct.
440
+ #
441
+ # This function is used by Brick Viewer during flashing. It should not be
442
+ # necessary to call it in a normal user program.
443
+ def set_bootloader_mode(mode)
444
+ check_validity
445
+
446
+ send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
447
+ end
448
+
449
+ # Returns the current bootloader mode, see BrickletServoV2#set_bootloader_mode.
450
+ def get_bootloader_mode
451
+ check_validity
452
+
453
+ send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
454
+ end
455
+
456
+ # Sets the firmware pointer for BrickletServoV2#write_firmware. The pointer has
457
+ # to be increased by chunks of size 64. The data is written to flash
458
+ # every 4 chunks (which equals to one page of size 256).
459
+ #
460
+ # This function is used by Brick Viewer during flashing. It should not be
461
+ # necessary to call it in a normal user program.
462
+ def set_write_firmware_pointer(pointer)
463
+ check_validity
464
+
465
+ send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
466
+ end
467
+
468
+ # Writes 64 Bytes of firmware at the position as written by
469
+ # BrickletServoV2#set_write_firmware_pointer before. The firmware is written
470
+ # to flash every 4 chunks.
471
+ #
472
+ # You can only write firmware in bootloader mode.
473
+ #
474
+ # This function is used by Brick Viewer during flashing. It should not be
475
+ # necessary to call it in a normal user program.
476
+ def write_firmware(data)
477
+ check_validity
478
+
479
+ send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
480
+ end
481
+
482
+ # Sets the status LED configuration. By default the LED shows
483
+ # communication traffic between Brick and Bricklet, it flickers once
484
+ # for every 10 received data packets.
485
+ #
486
+ # You can also turn the LED permanently on/off or show a heartbeat.
487
+ #
488
+ # If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
489
+ def set_status_led_config(config)
490
+ check_validity
491
+
492
+ send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
493
+ end
494
+
495
+ # Returns the configuration as set by BrickletServoV2#set_status_led_config
496
+ def get_status_led_config
497
+ check_validity
498
+
499
+ send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
500
+ end
501
+
502
+ # Returns the temperature as measured inside the microcontroller. The
503
+ # value returned is not the ambient temperature!
504
+ #
505
+ # The temperature is only proportional to the real temperature and it has bad
506
+ # accuracy. Practically it is only useful as an indicator for
507
+ # temperature changes.
508
+ def get_chip_temperature
509
+ check_validity
510
+
511
+ send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
512
+ end
513
+
514
+ # Calling this function will reset the Bricklet. All configurations
515
+ # will be lost.
516
+ #
517
+ # After a reset you have to create new device objects,
518
+ # calling functions on the existing ones will result in
519
+ # undefined behavior!
520
+ def reset
521
+ check_validity
522
+
523
+ send_request FUNCTION_RESET, [], '', 8, ''
524
+ end
525
+
526
+ # Writes a new UID into flash. If you want to set a new UID
527
+ # you have to decode the Base58 encoded UID string into an
528
+ # integer first.
529
+ #
530
+ # We recommend that you use Brick Viewer to change the UID.
531
+ def write_uid(uid)
532
+ check_validity
533
+
534
+ send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
535
+ end
536
+
537
+ # Returns the current UID as an integer. Encode as
538
+ # Base58 to get the usual string version.
539
+ def read_uid
540
+ check_validity
541
+
542
+ send_request FUNCTION_READ_UID, [], '', 12, 'L'
543
+ end
544
+
545
+ # Returns the UID, the UID where the Bricklet is connected to,
546
+ # the position, the hardware and firmware version as well as the
547
+ # device identifier.
548
+ #
549
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
550
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
551
+ # position 'z'.
552
+ #
553
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
554
+ # |device_identifier_constant|
555
+ def get_identity
556
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
557
+ end
558
+
559
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
560
+ def register_callback(id, &block)
561
+ callback = block
562
+ @registered_callbacks[id] = callback
563
+ end
564
+ end
565
+ end