tinkerforge 2.1.24 → 2.1.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +5 -5
  2. data/lib/tinkerforge/brick_dc.rb +156 -75
  3. data/lib/tinkerforge/brick_hat.rb +69 -31
  4. data/lib/tinkerforge/brick_hat_zero.rb +55 -23
  5. data/lib/tinkerforge/brick_imu.rb +185 -78
  6. data/lib/tinkerforge/brick_imu_v2.rb +209 -106
  7. data/lib/tinkerforge/brick_master.rb +491 -183
  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 +247 -167
  11. data/lib/tinkerforge/brick_stepper.rb +211 -99
  12. data/lib/tinkerforge/bricklet_accelerometer.rb +57 -23
  13. data/lib/tinkerforge/bricklet_accelerometer_v2.rb +104 -54
  14. data/lib/tinkerforge/bricklet_air_quality.rb +116 -59
  15. data/lib/tinkerforge/bricklet_ambient_light.rb +50 -21
  16. data/lib/tinkerforge/bricklet_ambient_light_v2.rb +44 -24
  17. data/lib/tinkerforge/bricklet_ambient_light_v3.rb +65 -27
  18. data/lib/tinkerforge/bricklet_analog_in.rb +62 -25
  19. data/lib/tinkerforge/bricklet_analog_in_v2.rb +56 -23
  20. data/lib/tinkerforge/bricklet_analog_in_v3.rb +66 -25
  21. data/lib/tinkerforge/bricklet_analog_out.rb +22 -9
  22. data/lib/tinkerforge/bricklet_analog_out_v2.rb +19 -8
  23. data/lib/tinkerforge/bricklet_analog_out_v3.rb +53 -20
  24. data/lib/tinkerforge/bricklet_barometer.rb +100 -27
  25. data/lib/tinkerforge/bricklet_barometer_v2.rb +98 -37
  26. data/lib/tinkerforge/bricklet_can.rb +83 -19
  27. data/lib/tinkerforge/bricklet_can_v2.rb +171 -38
  28. data/lib/tinkerforge/bricklet_co2.rb +33 -14
  29. data/lib/tinkerforge/bricklet_co2_v2.rb +97 -38
  30. data/lib/tinkerforge/bricklet_color.rb +68 -27
  31. data/lib/tinkerforge/bricklet_color_v2.rb +86 -33
  32. data/lib/tinkerforge/bricklet_compass.rb +77 -30
  33. data/lib/tinkerforge/bricklet_current12.rb +57 -24
  34. data/lib/tinkerforge/bricklet_current25.rb +57 -24
  35. data/lib/tinkerforge/bricklet_dc_v2.rb +521 -0
  36. data/lib/tinkerforge/bricklet_distance_ir.rb +56 -23
  37. data/lib/tinkerforge/bricklet_distance_ir_v2.rb +82 -31
  38. data/lib/tinkerforge/bricklet_distance_us.rb +39 -16
  39. data/lib/tinkerforge/bricklet_distance_us_v2.rb +66 -25
  40. data/lib/tinkerforge/bricklet_dmx.rb +87 -34
  41. data/lib/tinkerforge/bricklet_dual_button.rb +23 -10
  42. data/lib/tinkerforge/bricklet_dual_button_v2.rb +63 -24
  43. data/lib/tinkerforge/bricklet_dual_relay.rb +26 -11
  44. data/lib/tinkerforge/bricklet_dust_detector.rb +39 -16
  45. data/lib/tinkerforge/bricklet_e_paper_296x128.rb +87 -32
  46. data/lib/tinkerforge/bricklet_energy_monitor.rb +72 -27
  47. data/lib/tinkerforge/bricklet_gps.rb +63 -26
  48. data/lib/tinkerforge/bricklet_gps_v2.rb +116 -47
  49. data/lib/tinkerforge/bricklet_hall_effect.rb +42 -23
  50. data/lib/tinkerforge/bricklet_hall_effect_v2.rb +70 -27
  51. data/lib/tinkerforge/bricklet_humidity.rb +50 -21
  52. data/lib/tinkerforge/bricklet_humidity_v2.rb +82 -31
  53. data/lib/tinkerforge/bricklet_imu_v3.rb +784 -0
  54. data/lib/tinkerforge/bricklet_industrial_analog_out.rb +37 -14
  55. data/lib/tinkerforge/bricklet_industrial_analog_out_v2.rb +80 -29
  56. data/lib/tinkerforge/bricklet_industrial_counter.rb +100 -39
  57. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +44 -17
  58. data/lib/tinkerforge/bricklet_industrial_digital_in_4_v2.rb +76 -29
  59. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +35 -14
  60. data/lib/tinkerforge/bricklet_industrial_digital_out_4_v2.rb +72 -27
  61. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +39 -16
  62. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma_v2.rb +79 -30
  63. data/lib/tinkerforge/bricklet_industrial_dual_ac_relay.rb +325 -0
  64. data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +48 -19
  65. data/lib/tinkerforge/bricklet_industrial_dual_analog_in_v2.rb +137 -31
  66. data/lib/tinkerforge/bricklet_industrial_dual_relay.rb +60 -23
  67. data/lib/tinkerforge/bricklet_industrial_ptc.rb +475 -0
  68. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +35 -14
  69. data/lib/tinkerforge/bricklet_industrial_quad_relay_v2.rb +66 -25
  70. data/lib/tinkerforge/bricklet_io16.rb +54 -21
  71. data/lib/tinkerforge/bricklet_io16_v2.rb +89 -34
  72. data/lib/tinkerforge/bricklet_io4.rb +54 -23
  73. data/lib/tinkerforge/bricklet_io4_v2.rb +95 -36
  74. data/lib/tinkerforge/bricklet_isolator.rb +72 -29
  75. data/lib/tinkerforge/bricklet_joystick.rb +58 -25
  76. data/lib/tinkerforge/bricklet_joystick_v2.rb +67 -26
  77. data/lib/tinkerforge/bricklet_laser_range_finder.rb +81 -32
  78. data/lib/tinkerforge/bricklet_laser_range_finder_v2.rb +95 -36
  79. data/lib/tinkerforge/bricklet_lcd_128x64.rb +191 -70
  80. data/lib/tinkerforge/bricklet_lcd_16x2.rb +44 -18
  81. data/lib/tinkerforge/bricklet_lcd_20x4.rb +57 -23
  82. data/lib/tinkerforge/bricklet_led_strip.rb +59 -22
  83. data/lib/tinkerforge/bricklet_led_strip_v2.rb +90 -46
  84. data/lib/tinkerforge/bricklet_line.rb +33 -14
  85. data/lib/tinkerforge/bricklet_linear_poti.rb +50 -21
  86. data/lib/tinkerforge/bricklet_linear_poti_v2.rb +54 -21
  87. data/lib/tinkerforge/bricklet_load_cell.rb +60 -23
  88. data/lib/tinkerforge/bricklet_load_cell_v2.rb +79 -30
  89. data/lib/tinkerforge/bricklet_moisture.rb +39 -16
  90. data/lib/tinkerforge/bricklet_motion_detector.rb +21 -10
  91. data/lib/tinkerforge/bricklet_motion_detector_v2.rb +61 -27
  92. data/lib/tinkerforge/bricklet_motorized_linear_poti.rb +70 -27
  93. data/lib/tinkerforge/bricklet_multi_touch.rb +30 -13
  94. data/lib/tinkerforge/bricklet_multi_touch_v2.rb +75 -28
  95. data/lib/tinkerforge/bricklet_nfc.rb +126 -62
  96. data/lib/tinkerforge/bricklet_nfc_rfid.rb +32 -13
  97. data/lib/tinkerforge/bricklet_oled_128x64.rb +28 -11
  98. data/lib/tinkerforge/bricklet_oled_128x64_v2.rb +65 -24
  99. data/lib/tinkerforge/bricklet_oled_64x48.rb +28 -11
  100. data/lib/tinkerforge/bricklet_one_wire.rb +65 -24
  101. data/lib/tinkerforge/bricklet_outdoor_weather.rb +71 -28
  102. data/lib/tinkerforge/bricklet_particulate_matter.rb +74 -30
  103. data/lib/tinkerforge/bricklet_performance_dc.rb +682 -0
  104. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +18 -9
  105. data/lib/tinkerforge/bricklet_piezo_speaker.rb +21 -10
  106. data/lib/tinkerforge/bricklet_piezo_speaker_v2.rb +79 -42
  107. data/lib/tinkerforge/bricklet_ptc.rb +73 -42
  108. data/lib/tinkerforge/bricklet_ptc_v2.rb +94 -48
  109. data/lib/tinkerforge/bricklet_real_time_clock.rb +44 -33
  110. data/lib/tinkerforge/bricklet_real_time_clock_v2.rb +77 -44
  111. data/lib/tinkerforge/bricklet_remote_switch.rb +38 -29
  112. data/lib/tinkerforge/bricklet_remote_switch_v2.rb +86 -49
  113. data/lib/tinkerforge/bricklet_rgb_led.rb +17 -8
  114. data/lib/tinkerforge/bricklet_rgb_led_button.rb +61 -30
  115. data/lib/tinkerforge/bricklet_rgb_led_matrix.rb +78 -33
  116. data/lib/tinkerforge/bricklet_rgb_led_v2.rb +51 -20
  117. data/lib/tinkerforge/bricklet_rotary_encoder.rb +38 -19
  118. data/lib/tinkerforge/bricklet_rotary_encoder_v2.rb +59 -24
  119. data/lib/tinkerforge/bricklet_rotary_poti.rb +52 -28
  120. data/lib/tinkerforge/bricklet_rotary_poti_v2.rb +56 -23
  121. data/lib/tinkerforge/bricklet_rs232.rb +89 -28
  122. data/lib/tinkerforge/bricklet_rs232_v2.rb +117 -44
  123. data/lib/tinkerforge/bricklet_rs485.rb +222 -95
  124. data/lib/tinkerforge/bricklet_segment_display_4x7.rb +24 -14
  125. data/lib/tinkerforge/bricklet_segment_display_4x7_v2.rb +74 -35
  126. data/lib/tinkerforge/bricklet_servo_v2.rb +565 -0
  127. data/lib/tinkerforge/bricklet_silent_stepper_v2.rb +1024 -0
  128. data/lib/tinkerforge/bricklet_solid_state_relay.rb +24 -13
  129. data/lib/tinkerforge/bricklet_solid_state_relay_v2.rb +58 -25
  130. data/lib/tinkerforge/bricklet_sound_intensity.rb +34 -18
  131. data/lib/tinkerforge/bricklet_sound_pressure_level.rb +71 -31
  132. data/lib/tinkerforge/bricklet_temperature.rb +39 -16
  133. data/lib/tinkerforge/bricklet_temperature_ir.rb +56 -23
  134. data/lib/tinkerforge/bricklet_temperature_ir_v2.rb +70 -27
  135. data/lib/tinkerforge/bricklet_temperature_v2.rb +60 -25
  136. data/lib/tinkerforge/bricklet_thermal_imaging.rb +104 -44
  137. data/lib/tinkerforge/bricklet_thermocouple.rb +44 -24
  138. data/lib/tinkerforge/bricklet_thermocouple_v2.rb +64 -27
  139. data/lib/tinkerforge/bricklet_tilt.rb +23 -10
  140. data/lib/tinkerforge/bricklet_uv_light.rb +35 -18
  141. data/lib/tinkerforge/bricklet_uv_light_v2.rb +84 -37
  142. data/lib/tinkerforge/bricklet_voltage.rb +51 -28
  143. data/lib/tinkerforge/bricklet_voltage_current.rb +90 -73
  144. data/lib/tinkerforge/bricklet_voltage_current_v2.rb +89 -68
  145. data/lib/tinkerforge/bricklet_xmc1400_breakout.rb +79 -30
  146. data/lib/tinkerforge/device_display_names.rb +170 -0
  147. data/lib/tinkerforge/ip_connection.rb +153 -33
  148. data/lib/tinkerforge/version.rb +1 -1
  149. metadata +11 -3
@@ -1,14 +1,16 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2019-11-25. #
3
+ # This file was automatically generated on 2021-05-06. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.24 #
5
+ # Ruby Bindings Version 2.1.29 #
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
  # Measures AC/DC current between -12.5A and +12.5A
14
16
  class BrickletCurrent12 < Device
@@ -76,7 +78,7 @@ module Tinkerforge
76
78
  # Creates an object with the unique device ID <tt>uid</tt> and adds it to
77
79
  # the IP Connection <tt>ipcon</tt>.
78
80
  def initialize(uid, ipcon)
79
- super uid, ipcon
81
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
80
82
 
81
83
  @api_version = [2, 0, 0]
82
84
 
@@ -96,12 +98,13 @@ module Tinkerforge
96
98
  @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
97
99
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
98
100
 
99
- @callback_formats[CALLBACK_CURRENT] = 's'
100
- @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
101
- @callback_formats[CALLBACK_CURRENT_REACHED] = 's'
102
- @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
103
- @callback_formats[CALLBACK_OVER_CURRENT] = ''
101
+ @callback_formats[CALLBACK_CURRENT] = [10, 's']
102
+ @callback_formats[CALLBACK_ANALOG_VALUE] = [10, 'S']
103
+ @callback_formats[CALLBACK_CURRENT_REACHED] = [10, 's']
104
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = [10, 'S']
105
+ @callback_formats[CALLBACK_OVER_CURRENT] = [8, '']
104
106
 
107
+ @ipcon.add_device self
105
108
  end
106
109
 
107
110
  # Returns the current of the sensor.
@@ -110,7 +113,9 @@ module Tinkerforge
110
113
  # CALLBACK_CURRENT callback and set the period with
111
114
  # BrickletCurrent12#set_current_callback_period.
112
115
  def get_current
113
- send_request FUNCTION_GET_CURRENT, [], '', 2, 's'
116
+ check_validity
117
+
118
+ send_request FUNCTION_GET_CURRENT, [], '', 10, 's'
114
119
  end
115
120
 
116
121
  # Calibrates the 0 value of the sensor. You have to call this function
@@ -125,7 +130,9 @@ module Tinkerforge
125
130
  # The resulting calibration will be saved on the EEPROM of the Current
126
131
  # Bricklet.
127
132
  def calibrate
128
- send_request FUNCTION_CALIBRATE, [], '', 0, ''
133
+ check_validity
134
+
135
+ send_request FUNCTION_CALIBRATE, [], '', 8, ''
129
136
  end
130
137
 
131
138
  # Returns *true* if more than 12.5A were measured.
@@ -133,7 +140,9 @@ module Tinkerforge
133
140
  # .. note::
134
141
  # To reset this value you have to power cycle the Bricklet.
135
142
  def is_over_current
136
- send_request FUNCTION_IS_OVER_CURRENT, [], '', 1, '?'
143
+ check_validity
144
+
145
+ send_request FUNCTION_IS_OVER_CURRENT, [], '', 9, '?'
137
146
  end
138
147
 
139
148
  # Returns the value as read by a 12-bit analog-to-digital converter.
@@ -148,7 +157,9 @@ module Tinkerforge
148
157
  # CALLBACK_ANALOG_VALUE callback and set the period with
149
158
  # BrickletCurrent12#set_analog_value_callback_period.
150
159
  def get_analog_value
151
- send_request FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S'
160
+ check_validity
161
+
162
+ send_request FUNCTION_GET_ANALOG_VALUE, [], '', 10, 'S'
152
163
  end
153
164
 
154
165
  # Sets the period with which the CALLBACK_CURRENT callback is triggered
@@ -157,12 +168,16 @@ module Tinkerforge
157
168
  # The CALLBACK_CURRENT callback is only triggered if the current has changed since
158
169
  # the last triggering.
159
170
  def set_current_callback_period(period)
160
- send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 0, ''
171
+ check_validity
172
+
173
+ send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 8, ''
161
174
  end
162
175
 
163
176
  # Returns the period as set by BrickletCurrent12#set_current_callback_period.
164
177
  def get_current_callback_period
165
- send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 4, 'L'
178
+ check_validity
179
+
180
+ send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 12, 'L'
166
181
  end
167
182
 
168
183
  # Sets the period with which the CALLBACK_ANALOG_VALUE callback is triggered
@@ -171,12 +186,16 @@ module Tinkerforge
171
186
  # The CALLBACK_ANALOG_VALUE callback is only triggered if the analog value has
172
187
  # changed since the last triggering.
173
188
  def set_analog_value_callback_period(period)
174
- send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, ''
189
+ check_validity
190
+
191
+ send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 8, ''
175
192
  end
176
193
 
177
194
  # Returns the period as set by BrickletCurrent12#set_analog_value_callback_period.
178
195
  def get_analog_value_callback_period
179
- send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L'
196
+ check_validity
197
+
198
+ send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 12, 'L'
180
199
  end
181
200
 
182
201
  # Sets the thresholds for the CALLBACK_CURRENT_REACHED callback.
@@ -191,12 +210,16 @@ module Tinkerforge
191
210
  # "'<'", "Callback is triggered when the current is smaller than the min value (max is ignored)"
192
211
  # "'>'", "Callback is triggered when the current is greater than the min value (max is ignored)"
193
212
  def set_current_callback_threshold(option, min, max)
194
- send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, ''
213
+ check_validity
214
+
215
+ send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 8, ''
195
216
  end
196
217
 
197
218
  # Returns the threshold as set by BrickletCurrent12#set_current_callback_threshold.
198
219
  def get_current_callback_threshold
199
- send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 5, 'k s s'
220
+ check_validity
221
+
222
+ send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 13, 'k s s'
200
223
  end
201
224
 
202
225
  # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
@@ -211,12 +234,16 @@ module Tinkerforge
211
234
  # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
212
235
  # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
213
236
  def set_analog_value_callback_threshold(option, min, max)
214
- send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, ''
237
+ check_validity
238
+
239
+ send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, ''
215
240
  end
216
241
 
217
242
  # Returns the threshold as set by BrickletCurrent12#set_analog_value_callback_threshold.
218
243
  def get_analog_value_callback_threshold
219
- send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S'
244
+ check_validity
245
+
246
+ send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 13, 'k S S'
220
247
  end
221
248
 
222
249
  # Sets the period with which the threshold callbacks
@@ -231,24 +258,30 @@ module Tinkerforge
231
258
  #
232
259
  # keep being reached.
233
260
  def set_debounce_period(debounce)
234
- send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, ''
261
+ check_validity
262
+
263
+ send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
235
264
  end
236
265
 
237
266
  # Returns the debounce period as set by BrickletCurrent12#set_debounce_period.
238
267
  def get_debounce_period
239
- send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L'
268
+ check_validity
269
+
270
+ send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
240
271
  end
241
272
 
242
273
  # Returns the UID, the UID where the Bricklet is connected to,
243
274
  # the position, the hardware and firmware version as well as the
244
275
  # device identifier.
245
276
  #
246
- # The position can be 'a', 'b', 'c' or 'd'.
277
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
278
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
279
+ # position 'z'.
247
280
  #
248
281
  # The device identifier numbers can be found :ref:`here <device_identifier>`.
249
282
  # |device_identifier_constant|
250
283
  def get_identity
251
- send_request FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S'
284
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
252
285
  end
253
286
 
254
287
  # 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-11-25. #
3
+ # This file was automatically generated on 2021-05-06. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.24 #
5
+ # Ruby Bindings Version 2.1.29 #
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
  # Measures AC/DC current between -25A and +25A
14
16
  class BrickletCurrent25 < Device
@@ -76,7 +78,7 @@ module Tinkerforge
76
78
  # Creates an object with the unique device ID <tt>uid</tt> and adds it to
77
79
  # the IP Connection <tt>ipcon</tt>.
78
80
  def initialize(uid, ipcon)
79
- super uid, ipcon
81
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
80
82
 
81
83
  @api_version = [2, 0, 0]
82
84
 
@@ -96,12 +98,13 @@ module Tinkerforge
96
98
  @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
97
99
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
98
100
 
99
- @callback_formats[CALLBACK_CURRENT] = 's'
100
- @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
101
- @callback_formats[CALLBACK_CURRENT_REACHED] = 's'
102
- @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
103
- @callback_formats[CALLBACK_OVER_CURRENT] = ''
101
+ @callback_formats[CALLBACK_CURRENT] = [10, 's']
102
+ @callback_formats[CALLBACK_ANALOG_VALUE] = [10, 'S']
103
+ @callback_formats[CALLBACK_CURRENT_REACHED] = [10, 's']
104
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = [10, 'S']
105
+ @callback_formats[CALLBACK_OVER_CURRENT] = [8, '']
104
106
 
107
+ @ipcon.add_device self
105
108
  end
106
109
 
107
110
  # Returns the current of the sensor.
@@ -110,7 +113,9 @@ module Tinkerforge
110
113
  # CALLBACK_CURRENT callback and set the period with
111
114
  # BrickletCurrent25#set_current_callback_period.
112
115
  def get_current
113
- send_request FUNCTION_GET_CURRENT, [], '', 2, 's'
116
+ check_validity
117
+
118
+ send_request FUNCTION_GET_CURRENT, [], '', 10, 's'
114
119
  end
115
120
 
116
121
  # Calibrates the 0 value of the sensor. You have to call this function
@@ -125,7 +130,9 @@ module Tinkerforge
125
130
  # The resulting calibration will be saved on the EEPROM of the Current
126
131
  # Bricklet.
127
132
  def calibrate
128
- send_request FUNCTION_CALIBRATE, [], '', 0, ''
133
+ check_validity
134
+
135
+ send_request FUNCTION_CALIBRATE, [], '', 8, ''
129
136
  end
130
137
 
131
138
  # Returns *true* if more than 25A were measured.
@@ -133,7 +140,9 @@ module Tinkerforge
133
140
  # .. note::
134
141
  # To reset this value you have to power cycle the Bricklet.
135
142
  def is_over_current
136
- send_request FUNCTION_IS_OVER_CURRENT, [], '', 1, '?'
143
+ check_validity
144
+
145
+ send_request FUNCTION_IS_OVER_CURRENT, [], '', 9, '?'
137
146
  end
138
147
 
139
148
  # Returns the value as read by a 12-bit analog-to-digital converter.
@@ -148,7 +157,9 @@ module Tinkerforge
148
157
  # CALLBACK_ANALOG_VALUE callback and set the period with
149
158
  # BrickletCurrent25#set_analog_value_callback_period.
150
159
  def get_analog_value
151
- send_request FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S'
160
+ check_validity
161
+
162
+ send_request FUNCTION_GET_ANALOG_VALUE, [], '', 10, 'S'
152
163
  end
153
164
 
154
165
  # Sets the period with which the CALLBACK_CURRENT callback is triggered
@@ -157,12 +168,16 @@ module Tinkerforge
157
168
  # The CALLBACK_CURRENT callback is only triggered if the current has changed since
158
169
  # the last triggering.
159
170
  def set_current_callback_period(period)
160
- send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 0, ''
171
+ check_validity
172
+
173
+ send_request FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 8, ''
161
174
  end
162
175
 
163
176
  # Returns the period as set by BrickletCurrent25#set_current_callback_period.
164
177
  def get_current_callback_period
165
- send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 4, 'L'
178
+ check_validity
179
+
180
+ send_request FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 12, 'L'
166
181
  end
167
182
 
168
183
  # Sets the period with which the CALLBACK_ANALOG_VALUE callback is triggered
@@ -171,12 +186,16 @@ module Tinkerforge
171
186
  # The CALLBACK_ANALOG_VALUE callback is only triggered if the analog value has
172
187
  # changed since the last triggering.
173
188
  def set_analog_value_callback_period(period)
174
- send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, ''
189
+ check_validity
190
+
191
+ send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 8, ''
175
192
  end
176
193
 
177
194
  # Returns the period as set by BrickletCurrent25#set_analog_value_callback_period.
178
195
  def get_analog_value_callback_period
179
- send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L'
196
+ check_validity
197
+
198
+ send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 12, 'L'
180
199
  end
181
200
 
182
201
  # Sets the thresholds for the CALLBACK_CURRENT_REACHED callback.
@@ -191,12 +210,16 @@ module Tinkerforge
191
210
  # "'<'", "Callback is triggered when the current is smaller than the min value (max is ignored)"
192
211
  # "'>'", "Callback is triggered when the current is greater than the min value (max is ignored)"
193
212
  def set_current_callback_threshold(option, min, max)
194
- send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, ''
213
+ check_validity
214
+
215
+ send_request FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 8, ''
195
216
  end
196
217
 
197
218
  # Returns the threshold as set by BrickletCurrent25#set_current_callback_threshold.
198
219
  def get_current_callback_threshold
199
- send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 5, 'k s s'
220
+ check_validity
221
+
222
+ send_request FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 13, 'k s s'
200
223
  end
201
224
 
202
225
  # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
@@ -211,12 +234,16 @@ module Tinkerforge
211
234
  # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
212
235
  # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
213
236
  def set_analog_value_callback_threshold(option, min, max)
214
- send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, ''
237
+ check_validity
238
+
239
+ send_request FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, ''
215
240
  end
216
241
 
217
242
  # Returns the threshold as set by BrickletCurrent25#set_analog_value_callback_threshold.
218
243
  def get_analog_value_callback_threshold
219
- send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S'
244
+ check_validity
245
+
246
+ send_request FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 13, 'k S S'
220
247
  end
221
248
 
222
249
  # Sets the period with which the threshold callbacks
@@ -231,24 +258,30 @@ module Tinkerforge
231
258
  #
232
259
  # keep being reached.
233
260
  def set_debounce_period(debounce)
234
- send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, ''
261
+ check_validity
262
+
263
+ send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
235
264
  end
236
265
 
237
266
  # Returns the debounce period as set by BrickletCurrent25#set_debounce_period.
238
267
  def get_debounce_period
239
- send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L'
268
+ check_validity
269
+
270
+ send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
240
271
  end
241
272
 
242
273
  # Returns the UID, the UID where the Bricklet is connected to,
243
274
  # the position, the hardware and firmware version as well as the
244
275
  # device identifier.
245
276
  #
246
- # The position can be 'a', 'b', 'c' or 'd'.
277
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
278
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
279
+ # position 'z'.
247
280
  #
248
281
  # The device identifier numbers can be found :ref:`here <device_identifier>`.
249
282
  # |device_identifier_constant|
250
283
  def get_identity
251
- send_request FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S'
284
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
252
285
  end
253
286
 
254
287
  # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
@@ -0,0 +1,521 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2021-05-06. #
4
+ # #
5
+ # Ruby Bindings Version 2.1.29 #
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 one brushed DC motor with up to 28V and 5A (peak)
16
+ class BrickletDCV2 < Device
17
+ DEVICE_IDENTIFIER = 2165 # :nodoc:
18
+ DEVICE_DISPLAY_NAME = 'DC Bricklet 2.0' # :nodoc:
19
+
20
+ # This callback is triggered if either the current consumption
21
+ # is too high (above 5A) or the temperature of the driver chip is too high
22
+ # (above 175°C). These two possibilities are essentially the same, since the
23
+ # temperature will reach this threshold immediately if the motor consumes too
24
+ # much current. In case of a voltage below 3.3V (external or stack) this
25
+ # callback is triggered as well.
26
+ #
27
+ # If this callback is triggered, the driver chip gets disabled at the same time.
28
+ # That means, BrickletDCV2#set_enabled has to be called to drive the motor again.
29
+ #
30
+ # .. note::
31
+ # This callback only works in Drive/Brake mode (see BrickletDCV2#set_drive_mode). In
32
+ # Drive/Coast mode it is unfortunately impossible to reliably read the
33
+ # overcurrent/overtemperature signal from the driver chip.
34
+ CALLBACK_EMERGENCY_SHUTDOWN = 22
35
+
36
+ # This callback is triggered whenever a set velocity is reached. For example:
37
+ # If a velocity of 0 is present, acceleration is set to 5000 and velocity
38
+ # to 10000, the CALLBACK_VELOCITY_REACHED callback will be triggered after about
39
+ # 2 seconds, when the set velocity is actually reached.
40
+ #
41
+ # .. note::
42
+ # Since we can't get any feedback from the DC motor, this only works if the
43
+ # acceleration (see BrickletDCV2#set_motion) is set smaller or equal to the
44
+ # maximum acceleration of the motor. Otherwise the motor will lag behind the
45
+ # control value and the callback will be triggered too early.
46
+ CALLBACK_VELOCITY_REACHED = 23
47
+
48
+ # This callback is triggered with the period that is set by
49
+ # BrickletDCV2#set_current_velocity_callback_configuration. The parameter is the *current*
50
+ # velocity used by the motor.
51
+ #
52
+ # The CALLBACK_CURRENT_VELOCITY callback is only triggered after the set period
53
+ # if there is a change in the velocity.
54
+ CALLBACK_CURRENT_VELOCITY = 24
55
+
56
+ FUNCTION_SET_ENABLED = 1 # :nodoc:
57
+ FUNCTION_GET_ENABLED = 2 # :nodoc:
58
+ FUNCTION_SET_VELOCITY = 3 # :nodoc:
59
+ FUNCTION_GET_VELOCITY = 4 # :nodoc:
60
+ FUNCTION_GET_CURRENT_VELOCITY = 5 # :nodoc:
61
+ FUNCTION_SET_MOTION = 6 # :nodoc:
62
+ FUNCTION_GET_MOTION = 7 # :nodoc:
63
+ FUNCTION_FULL_BRAKE = 8 # :nodoc:
64
+ FUNCTION_SET_DRIVE_MODE = 9 # :nodoc:
65
+ FUNCTION_GET_DRIVE_MODE = 10 # :nodoc:
66
+ FUNCTION_SET_PWM_FREQUENCY = 11 # :nodoc:
67
+ FUNCTION_GET_PWM_FREQUENCY = 12 # :nodoc:
68
+ FUNCTION_GET_POWER_STATISTICS = 13 # :nodoc:
69
+ FUNCTION_SET_ERROR_LED_CONFIG = 14 # :nodoc:
70
+ FUNCTION_GET_ERROR_LED_CONFIG = 15 # :nodoc:
71
+ FUNCTION_SET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION = 16 # :nodoc:
72
+ FUNCTION_GET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION = 17 # :nodoc:
73
+ FUNCTION_SET_VELOCITY_REACHED_CALLBACK_CONFIGURATION = 18 # :nodoc:
74
+ FUNCTION_GET_VELOCITY_REACHED_CALLBACK_CONFIGURATION = 19 # :nodoc:
75
+ FUNCTION_SET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION = 20 # :nodoc:
76
+ FUNCTION_GET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION = 21 # :nodoc:
77
+ FUNCTION_GET_SPITFP_ERROR_COUNT = 234 # :nodoc:
78
+ FUNCTION_SET_BOOTLOADER_MODE = 235 # :nodoc:
79
+ FUNCTION_GET_BOOTLOADER_MODE = 236 # :nodoc:
80
+ FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237 # :nodoc:
81
+ FUNCTION_WRITE_FIRMWARE = 238 # :nodoc:
82
+ FUNCTION_SET_STATUS_LED_CONFIG = 239 # :nodoc:
83
+ FUNCTION_GET_STATUS_LED_CONFIG = 240 # :nodoc:
84
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
85
+ FUNCTION_RESET = 243 # :nodoc:
86
+ FUNCTION_WRITE_UID = 248 # :nodoc:
87
+ FUNCTION_READ_UID = 249 # :nodoc:
88
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
89
+
90
+ DRIVE_MODE_DRIVE_BRAKE = 0 # :nodoc:
91
+ DRIVE_MODE_DRIVE_COAST = 1 # :nodoc:
92
+ ERROR_LED_CONFIG_OFF = 0 # :nodoc:
93
+ ERROR_LED_CONFIG_ON = 1 # :nodoc:
94
+ ERROR_LED_CONFIG_SHOW_HEARTBEAT = 2 # :nodoc:
95
+ ERROR_LED_CONFIG_SHOW_ERROR = 3 # :nodoc:
96
+ BOOTLOADER_MODE_BOOTLOADER = 0 # :nodoc:
97
+ BOOTLOADER_MODE_FIRMWARE = 1 # :nodoc:
98
+ BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2 # :nodoc:
99
+ BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3 # :nodoc:
100
+ BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4 # :nodoc:
101
+ BOOTLOADER_STATUS_OK = 0 # :nodoc:
102
+ BOOTLOADER_STATUS_INVALID_MODE = 1 # :nodoc:
103
+ BOOTLOADER_STATUS_NO_CHANGE = 2 # :nodoc:
104
+ BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT = 3 # :nodoc:
105
+ BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT = 4 # :nodoc:
106
+ BOOTLOADER_STATUS_CRC_MISMATCH = 5 # :nodoc:
107
+ STATUS_LED_CONFIG_OFF = 0 # :nodoc:
108
+ STATUS_LED_CONFIG_ON = 1 # :nodoc:
109
+ STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2 # :nodoc:
110
+ STATUS_LED_CONFIG_SHOW_STATUS = 3 # :nodoc:
111
+
112
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
113
+ # the IP Connection <tt>ipcon</tt>.
114
+ def initialize(uid, ipcon)
115
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
116
+
117
+ @api_version = [2, 0, 0]
118
+
119
+ @response_expected[FUNCTION_SET_ENABLED] = RESPONSE_EXPECTED_FALSE
120
+ @response_expected[FUNCTION_GET_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
121
+ @response_expected[FUNCTION_SET_VELOCITY] = RESPONSE_EXPECTED_FALSE
122
+ @response_expected[FUNCTION_GET_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
123
+ @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
124
+ @response_expected[FUNCTION_SET_MOTION] = RESPONSE_EXPECTED_FALSE
125
+ @response_expected[FUNCTION_GET_MOTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
126
+ @response_expected[FUNCTION_FULL_BRAKE] = RESPONSE_EXPECTED_FALSE
127
+ @response_expected[FUNCTION_SET_DRIVE_MODE] = RESPONSE_EXPECTED_FALSE
128
+ @response_expected[FUNCTION_GET_DRIVE_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
129
+ @response_expected[FUNCTION_SET_PWM_FREQUENCY] = RESPONSE_EXPECTED_FALSE
130
+ @response_expected[FUNCTION_GET_PWM_FREQUENCY] = RESPONSE_EXPECTED_ALWAYS_TRUE
131
+ @response_expected[FUNCTION_GET_POWER_STATISTICS] = RESPONSE_EXPECTED_ALWAYS_TRUE
132
+ @response_expected[FUNCTION_SET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
133
+ @response_expected[FUNCTION_GET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
134
+ @response_expected[FUNCTION_SET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
135
+ @response_expected[FUNCTION_GET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
136
+ @response_expected[FUNCTION_SET_VELOCITY_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
137
+ @response_expected[FUNCTION_GET_VELOCITY_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
138
+ @response_expected[FUNCTION_SET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
139
+ @response_expected[FUNCTION_GET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
140
+ @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
141
+ @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
142
+ @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
143
+ @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE
144
+ @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE
145
+ @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
146
+ @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
147
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
148
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
149
+ @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE
150
+ @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
151
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
152
+
153
+ @callback_formats[CALLBACK_EMERGENCY_SHUTDOWN] = [8, '']
154
+ @callback_formats[CALLBACK_VELOCITY_REACHED] = [10, 's']
155
+ @callback_formats[CALLBACK_CURRENT_VELOCITY] = [10, 's']
156
+
157
+ @ipcon.add_device self
158
+ end
159
+
160
+ # Enables/Disables the driver chip. The driver parameters can be configured
161
+ # (velocity, acceleration, etc) before it is enabled.
162
+ def set_enabled(enabled)
163
+ check_validity
164
+
165
+ send_request FUNCTION_SET_ENABLED, [enabled], '?', 8, ''
166
+ end
167
+
168
+ # Returns *true* if the driver chip is enabled, *false* otherwise.
169
+ def get_enabled
170
+ check_validity
171
+
172
+ send_request FUNCTION_GET_ENABLED, [], '', 9, '?'
173
+ end
174
+
175
+ # Sets the velocity of the motor. Whereas -32767 is full speed backward,
176
+ # 0 is stop and 32767 is full speed forward. Depending on the
177
+ # acceleration (see BrickletDCV2#set_motion), the motor is not immediately
178
+ # brought to the velocity but smoothly accelerated.
179
+ #
180
+ # The velocity describes the duty cycle of the PWM with which the motor is
181
+ # controlled, e.g. a velocity of 3277 sets a PWM with a 10% duty cycle.
182
+ # You can not only control the duty cycle of the PWM but also the frequency,
183
+ # see BrickletDCV2#set_pwm_frequency.
184
+ def set_velocity(velocity)
185
+ check_validity
186
+
187
+ send_request FUNCTION_SET_VELOCITY, [velocity], 's', 8, ''
188
+ end
189
+
190
+ # Returns the velocity as set by BrickletDCV2#set_velocity.
191
+ def get_velocity
192
+ check_validity
193
+
194
+ send_request FUNCTION_GET_VELOCITY, [], '', 10, 's'
195
+ end
196
+
197
+ # Returns the *current* velocity of the motor. This value is different
198
+ # from BrickletDCV2#get_velocity whenever the motor is currently accelerating
199
+ # to a goal set by BrickletDCV2#set_velocity.
200
+ def get_current_velocity
201
+ check_validity
202
+
203
+ send_request FUNCTION_GET_CURRENT_VELOCITY, [], '', 10, 's'
204
+ end
205
+
206
+ # Sets the acceleration and deceleration of the motor. It is given in *velocity/s*.
207
+ # An acceleration of 10000 means, that every second the velocity is increased
208
+ # by 10000 (or about 30% duty cycle).
209
+ #
210
+ # For example: If the current velocity is 0 and you want to accelerate to a
211
+ # velocity of 16000 (about 50% duty cycle) in 10 seconds, you should set
212
+ # an acceleration of 1600.
213
+ #
214
+ # If acceleration and deceleration is set to 0, there is no speed ramping, i.e. a
215
+ # new velocity is immediately given to the motor.
216
+ def set_motion(acceleration, deceleration)
217
+ check_validity
218
+
219
+ send_request FUNCTION_SET_MOTION, [acceleration, deceleration], 'S S', 8, ''
220
+ end
221
+
222
+ # Returns the acceleration/deceleration as set by BrickletDCV2#set_motion.
223
+ def get_motion
224
+ check_validity
225
+
226
+ send_request FUNCTION_GET_MOTION, [], '', 12, 'S S'
227
+ end
228
+
229
+ # Executes an active full brake.
230
+ #
231
+ # .. warning::
232
+ # This function is for emergency purposes,
233
+ # where an immediate brake is necessary. Depending on the current velocity and
234
+ # the strength of the motor, a full brake can be quite violent.
235
+ #
236
+ # Call BrickletDCV2#set_velocity with 0 if you just want to stop the motor.
237
+ def full_brake
238
+ check_validity
239
+
240
+ send_request FUNCTION_FULL_BRAKE, [], '', 8, ''
241
+ end
242
+
243
+ # Sets the drive mode. Possible modes are:
244
+ #
245
+ # * 0 = Drive/Brake
246
+ # * 1 = Drive/Coast
247
+ #
248
+ # These modes are different kinds of motor controls.
249
+ #
250
+ # In Drive/Brake mode, the motor is always either driving or braking. There
251
+ # is no freewheeling. Advantages are: A more linear correlation between
252
+ # PWM and velocity, more exact accelerations and the possibility to drive
253
+ # with slower velocities.
254
+ #
255
+ # In Drive/Coast mode, the motor is always either driving or freewheeling.
256
+ # Advantages are: Less current consumption and less demands on the motor and
257
+ # driver chip.
258
+ def set_drive_mode(mode)
259
+ check_validity
260
+
261
+ send_request FUNCTION_SET_DRIVE_MODE, [mode], 'C', 8, ''
262
+ end
263
+
264
+ # Returns the drive mode, as set by BrickletDCV2#set_drive_mode.
265
+ def get_drive_mode
266
+ check_validity
267
+
268
+ send_request FUNCTION_GET_DRIVE_MODE, [], '', 9, 'C'
269
+ end
270
+
271
+ # Sets the frequency of the PWM with which the motor is driven.
272
+ # Often a high frequency
273
+ # is less noisy and the motor runs smoother. However, with a low frequency
274
+ # there are less switches and therefore fewer switching losses. Also with
275
+ # most motors lower frequencies enable higher torque.
276
+ #
277
+ # If you have no idea what all this means, just ignore this function and use
278
+ # the default frequency, it will very likely work fine.
279
+ def set_pwm_frequency(frequency)
280
+ check_validity
281
+
282
+ send_request FUNCTION_SET_PWM_FREQUENCY, [frequency], 'S', 8, ''
283
+ end
284
+
285
+ # Returns the PWM frequency as set by BrickletDCV2#set_pwm_frequency.
286
+ def get_pwm_frequency
287
+ check_validity
288
+
289
+ send_request FUNCTION_GET_PWM_FREQUENCY, [], '', 10, 'S'
290
+ end
291
+
292
+ # Returns input voltage and current usage of the driver.
293
+ def get_power_statistics
294
+ check_validity
295
+
296
+ send_request FUNCTION_GET_POWER_STATISTICS, [], '', 12, 'S S'
297
+ end
298
+
299
+ # Configures the error LED to be either turned off, turned on, blink in
300
+ # heartbeat mode or show an error.
301
+ #
302
+ # If the LED is configured to show errors it has three different states:
303
+ #
304
+ # * Off: No error present.
305
+ # * 1s interval blinking: Input voltage too low (below 6V).
306
+ # * 250ms interval blinking: Overtemperature or overcurrent.
307
+ def set_error_led_config(config)
308
+ check_validity
309
+
310
+ send_request FUNCTION_SET_ERROR_LED_CONFIG, [config], 'C', 8, ''
311
+ end
312
+
313
+ # Returns the LED configuration as set by BrickletDCV2#set_error_led_config
314
+ def get_error_led_config
315
+ check_validity
316
+
317
+ send_request FUNCTION_GET_ERROR_LED_CONFIG, [], '', 9, 'C'
318
+ end
319
+
320
+ # Enable/Disable CALLBACK_EMERGENCY_SHUTDOWN callback.
321
+ def set_emergency_shutdown_callback_configuration(enabled)
322
+ check_validity
323
+
324
+ send_request FUNCTION_SET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION, [enabled], '?', 8, ''
325
+ end
326
+
327
+ # Returns the callback configuration as set by
328
+ # BrickletDCV2#set_emergency_shutdown_callback_configuration.
329
+ def get_emergency_shutdown_callback_configuration
330
+ check_validity
331
+
332
+ send_request FUNCTION_GET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION, [], '', 9, '?'
333
+ end
334
+
335
+ # Enable/Disable CALLBACK_VELOCITY_REACHED callback.
336
+ def set_velocity_reached_callback_configuration(enabled)
337
+ check_validity
338
+
339
+ send_request FUNCTION_SET_VELOCITY_REACHED_CALLBACK_CONFIGURATION, [enabled], '?', 8, ''
340
+ end
341
+
342
+ # Returns the callback configuration as set by
343
+ # BrickletDCV2#set_velocity_reached_callback_configuration.
344
+ def get_velocity_reached_callback_configuration
345
+ check_validity
346
+
347
+ send_request FUNCTION_GET_VELOCITY_REACHED_CALLBACK_CONFIGURATION, [], '', 9, '?'
348
+ end
349
+
350
+ # The period is the period with which the CALLBACK_CURRENT_VELOCITY
351
+ # callback is triggered periodically. A value of 0 turns the callback off.
352
+ #
353
+ # If the `value has to change`-parameter is set to true, the callback is only
354
+ # triggered after the value has changed. If the value didn't change within the
355
+ # period, the callback is triggered immediately on change.
356
+ #
357
+ # If it is set to false, the callback is continuously triggered with the period,
358
+ # independent of the value.
359
+ def set_current_velocity_callback_configuration(period, value_has_to_change)
360
+ check_validity
361
+
362
+ send_request FUNCTION_SET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION, [period, value_has_to_change], 'L ?', 8, ''
363
+ end
364
+
365
+ # Returns the callback configuration as set by
366
+ # BrickletDCV2#set_current_velocity_callback_configuration.
367
+ def get_current_velocity_callback_configuration
368
+ check_validity
369
+
370
+ send_request FUNCTION_GET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION, [], '', 13, 'L ?'
371
+ end
372
+
373
+ # Returns the error count for the communication between Brick and Bricklet.
374
+ #
375
+ # The errors are divided into
376
+ #
377
+ # * ACK checksum errors,
378
+ # * message checksum errors,
379
+ # * framing errors and
380
+ # * overflow errors.
381
+ #
382
+ # The errors counts are for errors that occur on the Bricklet side. All
383
+ # Bricks have a similar function that returns the errors on the Brick side.
384
+ def get_spitfp_error_count
385
+ check_validity
386
+
387
+ send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
388
+ end
389
+
390
+ # Sets the bootloader mode and returns the status after the requested
391
+ # mode change was instigated.
392
+ #
393
+ # You can change from bootloader mode to firmware mode and vice versa. A change
394
+ # from bootloader mode to firmware mode will only take place if the entry function,
395
+ # device identifier and CRC are present and correct.
396
+ #
397
+ # This function is used by Brick Viewer during flashing. It should not be
398
+ # necessary to call it in a normal user program.
399
+ def set_bootloader_mode(mode)
400
+ check_validity
401
+
402
+ send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
403
+ end
404
+
405
+ # Returns the current bootloader mode, see BrickletDCV2#set_bootloader_mode.
406
+ def get_bootloader_mode
407
+ check_validity
408
+
409
+ send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
410
+ end
411
+
412
+ # Sets the firmware pointer for BrickletDCV2#write_firmware. The pointer has
413
+ # to be increased by chunks of size 64. The data is written to flash
414
+ # every 4 chunks (which equals to one page of size 256).
415
+ #
416
+ # This function is used by Brick Viewer during flashing. It should not be
417
+ # necessary to call it in a normal user program.
418
+ def set_write_firmware_pointer(pointer)
419
+ check_validity
420
+
421
+ send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
422
+ end
423
+
424
+ # Writes 64 Bytes of firmware at the position as written by
425
+ # BrickletDCV2#set_write_firmware_pointer before. The firmware is written
426
+ # to flash every 4 chunks.
427
+ #
428
+ # You can only write firmware in bootloader mode.
429
+ #
430
+ # This function is used by Brick Viewer during flashing. It should not be
431
+ # necessary to call it in a normal user program.
432
+ def write_firmware(data)
433
+ check_validity
434
+
435
+ send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
436
+ end
437
+
438
+ # Sets the status LED configuration. By default the LED shows
439
+ # communication traffic between Brick and Bricklet, it flickers once
440
+ # for every 10 received data packets.
441
+ #
442
+ # You can also turn the LED permanently on/off or show a heartbeat.
443
+ #
444
+ # If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
445
+ def set_status_led_config(config)
446
+ check_validity
447
+
448
+ send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
449
+ end
450
+
451
+ # Returns the configuration as set by BrickletDCV2#set_status_led_config
452
+ def get_status_led_config
453
+ check_validity
454
+
455
+ send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
456
+ end
457
+
458
+ # Returns the temperature as measured inside the microcontroller. The
459
+ # value returned is not the ambient temperature!
460
+ #
461
+ # The temperature is only proportional to the real temperature and it has bad
462
+ # accuracy. Practically it is only useful as an indicator for
463
+ # temperature changes.
464
+ def get_chip_temperature
465
+ check_validity
466
+
467
+ send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
468
+ end
469
+
470
+ # Calling this function will reset the Bricklet. All configurations
471
+ # will be lost.
472
+ #
473
+ # After a reset you have to create new device objects,
474
+ # calling functions on the existing ones will result in
475
+ # undefined behavior!
476
+ def reset
477
+ check_validity
478
+
479
+ send_request FUNCTION_RESET, [], '', 8, ''
480
+ end
481
+
482
+ # Writes a new UID into flash. If you want to set a new UID
483
+ # you have to decode the Base58 encoded UID string into an
484
+ # integer first.
485
+ #
486
+ # We recommend that you use Brick Viewer to change the UID.
487
+ def write_uid(uid)
488
+ check_validity
489
+
490
+ send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
491
+ end
492
+
493
+ # Returns the current UID as an integer. Encode as
494
+ # Base58 to get the usual string version.
495
+ def read_uid
496
+ check_validity
497
+
498
+ send_request FUNCTION_READ_UID, [], '', 12, 'L'
499
+ end
500
+
501
+ # Returns the UID, the UID where the Bricklet is connected to,
502
+ # the position, the hardware and firmware version as well as the
503
+ # device identifier.
504
+ #
505
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
506
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
507
+ # position 'z'.
508
+ #
509
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
510
+ # |device_identifier_constant|
511
+ def get_identity
512
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
513
+ end
514
+
515
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
516
+ def register_callback(id, &block)
517
+ callback = block
518
+ @registered_callbacks[id] = callback
519
+ end
520
+ end
521
+ end