tinkerforge 2.1.22 → 2.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. checksums.yaml +5 -5
  2. data/lib/tinkerforge/brick_dc.rb +157 -76
  3. data/lib/tinkerforge/brick_hat.rb +115 -32
  4. data/lib/tinkerforge/brick_hat_zero.rb +119 -21
  5. data/lib/tinkerforge/brick_imu.rb +192 -87
  6. data/lib/tinkerforge/brick_imu_v2.rb +220 -119
  7. data/lib/tinkerforge/brick_master.rb +498 -198
  8. data/lib/tinkerforge/brick_red.rb +197 -74
  9. data/lib/tinkerforge/brick_servo.rb +187 -103
  10. data/lib/tinkerforge/brick_silent_stepper.rb +249 -169
  11. data/lib/tinkerforge/brick_stepper.rb +214 -102
  12. data/lib/tinkerforge/bricklet_accelerometer.rb +61 -36
  13. data/lib/tinkerforge/bricklet_accelerometer_v2.rb +167 -48
  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 +77 -49
  31. data/lib/tinkerforge/bricklet_color_v2.rb +493 -0
  32. data/lib/tinkerforge/bricklet_compass.rb +397 -0
  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 +335 -0
  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 +416 -0
  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 +101 -53
  77. data/lib/tinkerforge/bricklet_lcd_128x64.rb +241 -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 +371 -0
  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 +97 -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_piezo_buzzer.rb +19 -13
  102. data/lib/tinkerforge/bricklet_piezo_speaker.rb +22 -19
  103. data/lib/tinkerforge/bricklet_piezo_speaker_v2.rb +84 -57
  104. data/lib/tinkerforge/bricklet_ptc.rb +76 -51
  105. data/lib/tinkerforge/bricklet_ptc_v2.rb +96 -54
  106. data/lib/tinkerforge/bricklet_real_time_clock.rb +45 -36
  107. data/lib/tinkerforge/bricklet_real_time_clock_v2.rb +78 -47
  108. data/lib/tinkerforge/bricklet_remote_switch.rb +38 -29
  109. data/lib/tinkerforge/bricklet_remote_switch_v2.rb +86 -49
  110. data/lib/tinkerforge/bricklet_rgb_led.rb +17 -8
  111. data/lib/tinkerforge/bricklet_rgb_led_button.rb +61 -30
  112. data/lib/tinkerforge/bricklet_rgb_led_matrix.rb +78 -33
  113. data/lib/tinkerforge/bricklet_rgb_led_v2.rb +51 -20
  114. data/lib/tinkerforge/bricklet_rotary_encoder.rb +40 -25
  115. data/lib/tinkerforge/bricklet_rotary_encoder_v2.rb +60 -27
  116. data/lib/tinkerforge/bricklet_rotary_poti.rb +55 -37
  117. data/lib/tinkerforge/bricklet_rotary_poti_v2.rb +290 -0
  118. data/lib/tinkerforge/bricklet_rs232.rb +89 -28
  119. data/lib/tinkerforge/bricklet_rs232_v2.rb +121 -47
  120. data/lib/tinkerforge/bricklet_rs485.rb +303 -207
  121. data/lib/tinkerforge/bricklet_segment_display_4x7.rb +24 -14
  122. data/lib/tinkerforge/bricklet_segment_display_4x7_v2.rb +75 -36
  123. data/lib/tinkerforge/bricklet_solid_state_relay.rb +24 -13
  124. data/lib/tinkerforge/bricklet_solid_state_relay_v2.rb +58 -25
  125. data/lib/tinkerforge/bricklet_sound_intensity.rb +36 -24
  126. data/lib/tinkerforge/bricklet_sound_pressure_level.rb +77 -41
  127. data/lib/tinkerforge/bricklet_temperature.rb +43 -28
  128. data/lib/tinkerforge/bricklet_temperature_ir.rb +63 -47
  129. data/lib/tinkerforge/bricklet_temperature_ir_v2.rb +75 -53
  130. data/lib/tinkerforge/bricklet_temperature_v2.rb +62 -31
  131. data/lib/tinkerforge/bricklet_thermal_imaging.rb +118 -68
  132. data/lib/tinkerforge/bricklet_thermocouple.rb +46 -30
  133. data/lib/tinkerforge/bricklet_thermocouple_v2.rb +65 -30
  134. data/lib/tinkerforge/bricklet_tilt.rb +23 -10
  135. data/lib/tinkerforge/bricklet_uv_light.rb +37 -24
  136. data/lib/tinkerforge/bricklet_uv_light_v2.rb +87 -46
  137. data/lib/tinkerforge/bricklet_voltage.rb +54 -37
  138. data/lib/tinkerforge/bricklet_voltage_current.rb +94 -85
  139. data/lib/tinkerforge/bricklet_voltage_current_v2.rb +103 -77
  140. data/lib/tinkerforge/bricklet_xmc1400_breakout.rb +410 -0
  141. data/lib/tinkerforge/device_display_names.rb +165 -0
  142. data/lib/tinkerforge/ip_connection.rb +155 -33
  143. data/lib/tinkerforge/version.rb +1 -1
  144. metadata +14 -4
@@ -1,14 +1,16 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2019-05-21. #
3
+ # This file was automatically generated on 2020-11-02. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.22 #
5
+ # Ruby Bindings Version 2.1.27 #
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
  # 4-channel digital input/output
14
16
  class BrickletIO4 < Device
@@ -59,7 +61,7 @@ module Tinkerforge
59
61
  # Creates an object with the unique device ID <tt>uid</tt> and adds it to
60
62
  # the IP Connection <tt>ipcon</tt>.
61
63
  def initialize(uid, ipcon)
62
- super uid, ipcon
64
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
63
65
 
64
66
  @api_version = [2, 0, 1]
65
67
 
@@ -79,9 +81,10 @@ module Tinkerforge
79
81
  @response_expected[FUNCTION_GET_EDGE_COUNT_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
80
82
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
81
83
 
82
- @callback_formats[CALLBACK_INTERRUPT] = 'C C'
83
- @callback_formats[CALLBACK_MONOFLOP_DONE] = 'C C'
84
+ @callback_formats[CALLBACK_INTERRUPT] = [10, 'C C']
85
+ @callback_formats[CALLBACK_MONOFLOP_DONE] = [10, 'C C']
84
86
 
87
+ @ipcon.add_device self
85
88
  end
86
89
 
87
90
  # Sets the output value (high or low) with a bitmask (4bit). A 1 in the bitmask
@@ -96,14 +99,18 @@ module Tinkerforge
96
99
  # This function does nothing for pins that are configured as input.
97
100
  # Pull-up resistors can be switched on with BrickletIO4#set_configuration.
98
101
  def set_value(value_mask)
99
- send_request FUNCTION_SET_VALUE, [value_mask], 'C', 0, ''
102
+ check_validity
103
+
104
+ send_request FUNCTION_SET_VALUE, [value_mask], 'C', 8, ''
100
105
  end
101
106
 
102
107
  # Returns a bitmask of the values that are currently measured.
103
108
  # This function works if the pin is configured to input
104
109
  # as well as if it is configured to output.
105
110
  def get_value
106
- send_request FUNCTION_GET_VALUE, [], '', 1, 'C'
111
+ check_validity
112
+
113
+ send_request FUNCTION_GET_VALUE, [], '', 9, 'C'
107
114
  end
108
115
 
109
116
  # Configures the value and direction of the specified pins. Possible directions
@@ -124,10 +131,10 @@ module Tinkerforge
124
131
  #
125
132
  # Running monoflop timers for the specified pins will be aborted if this
126
133
  # function is called.
127
- #
128
- # The default configuration is input with pull-up.
129
134
  def set_configuration(selection_mask, direction, value)
130
- send_request FUNCTION_SET_CONFIGURATION, [selection_mask, direction, value], 'C k ?', 0, ''
135
+ check_validity
136
+
137
+ send_request FUNCTION_SET_CONFIGURATION, [selection_mask, direction, value], 'C k ?', 8, ''
131
138
  end
132
139
 
133
140
  # Returns a value bitmask and a direction bitmask. A 1 in the direction bitmask
@@ -141,23 +148,27 @@ module Tinkerforge
141
148
  # * pin 2 is configured as output high and
142
149
  # * pin 3 is are configured as output low.
143
150
  def get_configuration
144
- send_request FUNCTION_GET_CONFIGURATION, [], '', 2, 'C C'
151
+ check_validity
152
+
153
+ send_request FUNCTION_GET_CONFIGURATION, [], '', 10, 'C C'
145
154
  end
146
155
 
147
- # Sets the debounce period of the CALLBACK_INTERRUPT callback in ms.
156
+ # Sets the debounce period of the CALLBACK_INTERRUPT callback.
148
157
  #
149
158
  # For example: If you set this value to 100, you will get the interrupt
150
159
  # maximal every 100ms. This is necessary if something that bounces is
151
160
  # connected to the IO-4 Bricklet, such as a button.
152
- #
153
- # The default value is 100.
154
161
  def set_debounce_period(debounce)
155
- send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, ''
162
+ check_validity
163
+
164
+ send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
156
165
  end
157
166
 
158
167
  # Returns the debounce period as set by BrickletIO4#set_debounce_period.
159
168
  def get_debounce_period
160
- send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L'
169
+ check_validity
170
+
171
+ send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
161
172
  end
162
173
 
163
174
  # Sets the pins on which an interrupt is activated with a bitmask.
@@ -169,12 +180,16 @@ module Tinkerforge
169
180
  #
170
181
  # The interrupt is delivered with the CALLBACK_INTERRUPT callback.
171
182
  def set_interrupt(interrupt_mask)
172
- send_request FUNCTION_SET_INTERRUPT, [interrupt_mask], 'C', 0, ''
183
+ check_validity
184
+
185
+ send_request FUNCTION_SET_INTERRUPT, [interrupt_mask], 'C', 8, ''
173
186
  end
174
187
 
175
188
  # Returns the interrupt bitmask as set by BrickletIO4#set_interrupt.
176
189
  def get_interrupt
177
- send_request FUNCTION_GET_INTERRUPT, [], '', 1, 'C'
190
+ check_validity
191
+
192
+ send_request FUNCTION_GET_INTERRUPT, [], '', 9, 'C'
178
193
  end
179
194
 
180
195
  # Configures a monoflop of the pins specified by the first parameter as 4 bit
@@ -184,7 +199,7 @@ module Tinkerforge
184
199
  # The second parameter is a bitmask with the desired value of the specified
185
200
  # output pins. A 1 in the bitmask means high and a 0 in the bitmask means low.
186
201
  #
187
- # The third parameter indicates the time (in ms) that the pins should hold
202
+ # The third parameter indicates the time that the pins should hold
188
203
  # the value.
189
204
  #
190
205
  # If this function is called with the parameters (9, 1, 1500) or
@@ -197,7 +212,9 @@ module Tinkerforge
197
212
  # of two seconds and pin 0 set to high. Pin 0 will be high all the time. If now
198
213
  # the RS485 connection is lost, then pin 0 will get low in at most two seconds.
199
214
  def set_monoflop(selection_mask, value_mask, time)
200
- send_request FUNCTION_SET_MONOFLOP, [selection_mask, value_mask, time], 'C C L', 0, ''
215
+ check_validity
216
+
217
+ send_request FUNCTION_SET_MONOFLOP, [selection_mask, value_mask, time], 'C C L', 8, ''
201
218
  end
202
219
 
203
220
  # Returns (for the given pin) the current value and the time as set by
@@ -206,7 +223,9 @@ module Tinkerforge
206
223
  # If the timer is not running currently, the remaining time will be returned
207
224
  # as 0.
208
225
  def get_monoflop(pin)
209
- send_request FUNCTION_GET_MONOFLOP, [pin], 'C', 9, 'C L L'
226
+ check_validity
227
+
228
+ send_request FUNCTION_GET_MONOFLOP, [pin], 'C', 17, 'C L L'
210
229
  end
211
230
 
212
231
  # Sets the output value (high or low) with a bitmask, according to
@@ -223,7 +242,9 @@ module Tinkerforge
223
242
  # This function does nothing for pins that are configured as input.
224
243
  # Pull-up resistors can be switched on with BrickletIO4#set_configuration.
225
244
  def set_selected_values(selection_mask, value_mask)
226
- send_request FUNCTION_SET_SELECTED_VALUES, [selection_mask, value_mask], 'C C', 0, ''
245
+ check_validity
246
+
247
+ send_request FUNCTION_SET_SELECTED_VALUES, [selection_mask, value_mask], 'C C', 8, ''
227
248
  end
228
249
 
229
250
  # Returns the current value of the edge counter for the selected pin. You can
@@ -234,7 +255,9 @@ module Tinkerforge
234
255
  #
235
256
  # .. versionadded:: 2.0.1$nbsp;(Plugin)
236
257
  def get_edge_count(pin, reset_counter)
237
- send_request FUNCTION_GET_EDGE_COUNT, [pin, reset_counter], 'C ?', 4, 'L'
258
+ check_validity
259
+
260
+ send_request FUNCTION_GET_EDGE_COUNT, [pin, reset_counter], 'C ?', 12, 'L'
238
261
  end
239
262
 
240
263
  # Configures the edge counter for the selected pins.
@@ -246,18 +269,16 @@ module Tinkerforge
246
269
  # * 1 = falling
247
270
  # * 2 = both
248
271
  #
249
- # The debounce time is given in ms.
250
- #
251
272
  # Configuring an edge counter resets its value to 0.
252
273
  #
253
274
  # If you don't know what any of this means, just leave it at default. The
254
275
  # default configuration is very likely OK for you.
255
276
  #
256
- # Default values: 0 (edge type) and 100ms (debounce time)
257
- #
258
277
  # .. versionadded:: 2.0.1$nbsp;(Plugin)
259
278
  def set_edge_count_config(selection_mask, edge_type, debounce)
260
- send_request FUNCTION_SET_EDGE_COUNT_CONFIG, [selection_mask, edge_type, debounce], 'C C C', 0, ''
279
+ check_validity
280
+
281
+ send_request FUNCTION_SET_EDGE_COUNT_CONFIG, [selection_mask, edge_type, debounce], 'C C C', 8, ''
261
282
  end
262
283
 
263
284
  # Returns the edge type and debounce time for the selected pin as set by
@@ -265,19 +286,23 @@ module Tinkerforge
265
286
  #
266
287
  # .. versionadded:: 2.0.1$nbsp;(Plugin)
267
288
  def get_edge_count_config(pin)
268
- send_request FUNCTION_GET_EDGE_COUNT_CONFIG, [pin], 'C', 2, 'C C'
289
+ check_validity
290
+
291
+ send_request FUNCTION_GET_EDGE_COUNT_CONFIG, [pin], 'C', 10, 'C C'
269
292
  end
270
293
 
271
294
  # Returns the UID, the UID where the Bricklet is connected to,
272
295
  # the position, the hardware and firmware version as well as the
273
296
  # device identifier.
274
297
  #
275
- # The position can be 'a', 'b', 'c' or 'd'.
298
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
299
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
300
+ # position 'z'.
276
301
  #
277
302
  # The device identifier numbers can be found :ref:`here <device_identifier>`.
278
303
  # |device_identifier_constant|
279
304
  def get_identity
280
- send_request FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S'
305
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
281
306
  end
282
307
 
283
308
  # 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-05-21. #
3
+ # This file was automatically generated on 2020-11-02. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.22 #
5
+ # Ruby Bindings Version 2.1.27 #
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
  # 4-channel digital input/output
14
16
  class BrickletIO4V2 < Device
@@ -89,7 +91,7 @@ module Tinkerforge
89
91
  # Creates an object with the unique device ID <tt>uid</tt> and adds it to
90
92
  # the IP Connection <tt>ipcon</tt>.
91
93
  def initialize(uid, ipcon)
92
- super uid, ipcon
94
+ super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
93
95
 
94
96
  @api_version = [2, 0, 0]
95
97
 
@@ -122,10 +124,11 @@ module Tinkerforge
122
124
  @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
123
125
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
124
126
 
125
- @callback_formats[CALLBACK_INPUT_VALUE] = 'C ? ?'
126
- @callback_formats[CALLBACK_ALL_INPUT_VALUE] = '?4 ?4'
127
- @callback_formats[CALLBACK_MONOFLOP_DONE] = 'C ?'
127
+ @callback_formats[CALLBACK_INPUT_VALUE] = [11, 'C ? ?']
128
+ @callback_formats[CALLBACK_ALL_INPUT_VALUE] = [10, '?4 ?4']
129
+ @callback_formats[CALLBACK_MONOFLOP_DONE] = [10, 'C ?']
128
130
 
131
+ @ipcon.add_device self
129
132
  end
130
133
 
131
134
  # Sets the output value of all four channels. A value of *true* or *false* outputs
@@ -142,14 +145,18 @@ module Tinkerforge
142
145
  # This function does nothing for channels that are configured as input. Pull-up
143
146
  # resistors can be switched on with BrickletIO4V2#set_configuration.
144
147
  def set_value(value)
145
- send_request FUNCTION_SET_VALUE, [value], '?4', 0, ''
148
+ check_validity
149
+
150
+ send_request FUNCTION_SET_VALUE, [value], '?4', 8, ''
146
151
  end
147
152
 
148
153
  # Returns the logic levels that are currently measured on the channels.
149
154
  # This function works if the channel is configured as input as well as if it is
150
155
  # configured as output.
151
156
  def get_value
152
- send_request FUNCTION_GET_VALUE, [], '', 4, '?4'
157
+ check_validity
158
+
159
+ send_request FUNCTION_GET_VALUE, [], '', 9, '?4'
153
160
  end
154
161
 
155
162
  # Sets the output value of a specific channel without affecting the other channels.
@@ -161,7 +168,9 @@ module Tinkerforge
161
168
  # This function does nothing for channels that are configured as input. Pull-up
162
169
  # resistors can be switched on with BrickletIO4V2#set_configuration.
163
170
  def set_selected_value(channel, value)
164
- send_request FUNCTION_SET_SELECTED_VALUE, [channel, value], 'C ?', 0, ''
171
+ check_validity
172
+
173
+ send_request FUNCTION_SET_SELECTED_VALUE, [channel, value], 'C ?', 8, ''
165
174
  end
166
175
 
167
176
  # Configures the value and direction of a specific channel. Possible directions
@@ -182,20 +191,22 @@ module Tinkerforge
182
191
  #
183
192
  # A running monoflop timer or PWM for the specific channel will be aborted if this
184
193
  # function is called.
185
- #
186
- # The default configuration is input with pull-up.
187
194
  def set_configuration(channel, direction, value)
188
- send_request FUNCTION_SET_CONFIGURATION, [channel, direction, value], 'C k ?', 0, ''
195
+ check_validity
196
+
197
+ send_request FUNCTION_SET_CONFIGURATION, [channel, direction, value], 'C k ?', 8, ''
189
198
  end
190
199
 
191
200
  # Returns the channel configuration as set by BrickletIO4V2#set_configuration.
192
201
  def get_configuration(channel)
193
- send_request FUNCTION_GET_CONFIGURATION, [channel], 'C', 2, 'k ?'
202
+ check_validity
203
+
204
+ send_request FUNCTION_GET_CONFIGURATION, [channel], 'C', 10, 'k ?'
194
205
  end
195
206
 
196
207
  # This callback can be configured per channel.
197
208
  #
198
- # The period in ms is the period with which the CALLBACK_INPUT_VALUE
209
+ # The period is the period with which the CALLBACK_INPUT_VALUE
199
210
  # callback is triggered periodically. A value of 0 turns the callback off.
200
211
  #
201
212
  # If the `value has to change`-parameter is set to true, the callback is only
@@ -204,19 +215,21 @@ module Tinkerforge
204
215
  #
205
216
  # If it is set to false, the callback is continuously triggered with the period,
206
217
  # independent of the value.
207
- #
208
- # The default value is (0, false).
209
218
  def set_input_value_callback_configuration(channel, period, value_has_to_change)
210
- send_request FUNCTION_SET_INPUT_VALUE_CALLBACK_CONFIGURATION, [channel, period, value_has_to_change], 'C L ?', 0, ''
219
+ check_validity
220
+
221
+ send_request FUNCTION_SET_INPUT_VALUE_CALLBACK_CONFIGURATION, [channel, period, value_has_to_change], 'C L ?', 8, ''
211
222
  end
212
223
 
213
224
  # Returns the callback configuration for the given channel as set by
214
225
  # BrickletIO4V2#set_input_value_callback_configuration.
215
226
  def get_input_value_callback_configuration(channel)
216
- send_request FUNCTION_GET_INPUT_VALUE_CALLBACK_CONFIGURATION, [channel], 'C', 5, 'L ?'
227
+ check_validity
228
+
229
+ send_request FUNCTION_GET_INPUT_VALUE_CALLBACK_CONFIGURATION, [channel], 'C', 13, 'L ?'
217
230
  end
218
231
 
219
- # The period in ms is the period with which the CALLBACK_ALL_INPUT_VALUE
232
+ # The period is the period with which the CALLBACK_ALL_INPUT_VALUE
220
233
  # callback is triggered periodically. A value of 0 turns the callback off.
221
234
  #
222
235
  # If the `value has to change`-parameter is set to true, the callback is only
@@ -225,20 +238,22 @@ module Tinkerforge
225
238
  #
226
239
  # If it is set to false, the callback is continuously triggered with the period,
227
240
  # independent of the value.
228
- #
229
- # The default value is (0, false).
230
241
  def set_all_input_value_callback_configuration(period, value_has_to_change)
231
- send_request FUNCTION_SET_ALL_INPUT_VALUE_CALLBACK_CONFIGURATION, [period, value_has_to_change], 'L ?', 0, ''
242
+ check_validity
243
+
244
+ send_request FUNCTION_SET_ALL_INPUT_VALUE_CALLBACK_CONFIGURATION, [period, value_has_to_change], 'L ?', 8, ''
232
245
  end
233
246
 
234
247
  # Returns the callback configuration as set by
235
248
  # BrickletIO4V2#set_all_input_value_callback_configuration.
236
249
  def get_all_input_value_callback_configuration
237
- send_request FUNCTION_GET_ALL_INPUT_VALUE_CALLBACK_CONFIGURATION, [], '', 5, 'L ?'
250
+ check_validity
251
+
252
+ send_request FUNCTION_GET_ALL_INPUT_VALUE_CALLBACK_CONFIGURATION, [], '', 13, 'L ?'
238
253
  end
239
254
 
240
255
  # The first parameter is the desired state of the channel (*true* means output *high*
241
- # and *false* means output *low*). The second parameter indicates the time (in ms) that
256
+ # and *false* means output *low*). The second parameter indicates the time that
242
257
  # the channel should hold the state.
243
258
  #
244
259
  # If this function is called with the parameters (true, 1500):
@@ -252,7 +267,9 @@ module Tinkerforge
252
267
  # of two seconds. The channel will be *high* all the time. If now the RS485
253
268
  # connection is lost, the channel will turn *low* in at most two seconds.
254
269
  def set_monoflop(channel, value, time)
255
- send_request FUNCTION_SET_MONOFLOP, [channel, value, time], 'C ? L', 0, ''
270
+ check_validity
271
+
272
+ send_request FUNCTION_SET_MONOFLOP, [channel, value, time], 'C ? L', 8, ''
256
273
  end
257
274
 
258
275
  # Returns (for the given channel) the current value and the time as set by
@@ -261,7 +278,9 @@ module Tinkerforge
261
278
  # If the timer is not running currently, the remaining time will be returned
262
279
  # as 0.
263
280
  def get_monoflop(channel)
264
- send_request FUNCTION_GET_MONOFLOP, [channel], 'C', 9, '? L L'
281
+ check_validity
282
+
283
+ send_request FUNCTION_GET_MONOFLOP, [channel], 'C', 17, '? L L'
265
284
  end
266
285
 
267
286
  # Returns the current value of the edge counter for the selected channel. You can
@@ -269,8 +288,13 @@ module Tinkerforge
269
288
  #
270
289
  # If you set the reset counter to *true*, the count is set back to 0
271
290
  # directly after it is read.
291
+ #
292
+ # .. note::
293
+ # Calling this function is only allowed for channels configured as input.
272
294
  def get_edge_count(channel, reset_counter)
273
- send_request FUNCTION_GET_EDGE_COUNT, [channel, reset_counter], 'C ?', 4, 'L'
295
+ check_validity
296
+
297
+ send_request FUNCTION_GET_EDGE_COUNT, [channel, reset_counter], 'C ?', 12, 'L'
274
298
  end
275
299
 
276
300
  # Configures the edge counter for a specific channel.
@@ -278,49 +302,53 @@ module Tinkerforge
278
302
  # The edge type parameter configures if rising edges, falling edges or
279
303
  # both are counted if the channel is configured for input. Possible edge types are:
280
304
  #
281
- # * 0 = rising (default)
305
+ # * 0 = rising
282
306
  # * 1 = falling
283
307
  # * 2 = both
284
308
  #
285
- # The debounce time is given in ms.
286
- #
287
309
  # Configuring an edge counter resets its value to 0.
288
310
  #
289
311
  # If you don't know what any of this means, just leave it at default. The
290
312
  # default configuration is very likely OK for you.
291
313
  #
292
- # Default values: 0 (edge type) and 100ms (debounce time)
314
+ # .. note::
315
+ # Calling this function is only allowed for channels configured as input.
293
316
  def set_edge_count_configuration(channel, edge_type, debounce)
294
- send_request FUNCTION_SET_EDGE_COUNT_CONFIGURATION, [channel, edge_type, debounce], 'C C C', 0, ''
317
+ check_validity
318
+
319
+ send_request FUNCTION_SET_EDGE_COUNT_CONFIGURATION, [channel, edge_type, debounce], 'C C C', 8, ''
295
320
  end
296
321
 
297
322
  # Returns the edge type and debounce time for the selected channel as set by
298
323
  # BrickletIO4V2#set_edge_count_configuration.
324
+ #
325
+ # .. note::
326
+ # Calling this function is only allowed for channels configured as input.
299
327
  def get_edge_count_configuration(channel)
300
- send_request FUNCTION_GET_EDGE_COUNT_CONFIGURATION, [channel], 'C', 2, 'C C'
328
+ check_validity
329
+
330
+ send_request FUNCTION_GET_EDGE_COUNT_CONFIGURATION, [channel], 'C', 10, 'C C'
301
331
  end
302
332
 
303
- # Activates a PWM for the given channel with the frequency given in 1/10Hz and the duty
304
- # cycle given in 1/100%.
333
+ # Activates a PWM for the given channel.
305
334
  #
306
335
  # You need to set the channel to output before you call this function, otherwise it will
307
- # be ignored. To turn the PWM off again, you can set the frequency to 0 or any other
336
+ # report an invalid parameter error. To turn the PWM off again, you can set the frequency to 0 or any other
308
337
  # function that changes a value of the channel (e.g. BrickletIO4V2#set_selected_value).
309
338
  #
310
- # The maximum frequency value is 320000000 (32MHz). The maximum duty cycle value is
311
- # 10000 (100%).
312
- #
313
339
  # A running monoflop timer for the given channel will be aborted if this function
314
340
  # is called.
315
- #
316
- # The default values are 0, 0.
317
341
  def set_pwm_configuration(channel, frequency, duty_cycle)
318
- send_request FUNCTION_SET_PWM_CONFIGURATION, [channel, frequency, duty_cycle], 'C L S', 0, ''
342
+ check_validity
343
+
344
+ send_request FUNCTION_SET_PWM_CONFIGURATION, [channel, frequency, duty_cycle], 'C L S', 8, ''
319
345
  end
320
346
 
321
347
  # Returns the PWM configuration as set by BrickletIO4V2#set_pwm_configuration.
322
348
  def get_pwm_configuration(channel)
323
- send_request FUNCTION_GET_PWM_CONFIGURATION, [channel], 'C', 6, 'L S'
349
+ check_validity
350
+
351
+ send_request FUNCTION_GET_PWM_CONFIGURATION, [channel], 'C', 14, 'L S'
324
352
  end
325
353
 
326
354
  # Returns the error count for the communication between Brick and Bricklet.
@@ -335,7 +363,9 @@ module Tinkerforge
335
363
  # The errors counts are for errors that occur on the Bricklet side. All
336
364
  # Bricks have a similar function that returns the errors on the Brick side.
337
365
  def get_spitfp_error_count
338
- send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 16, 'L L L L'
366
+ check_validity
367
+
368
+ send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
339
369
  end
340
370
 
341
371
  # Sets the bootloader mode and returns the status after the requested
@@ -348,12 +378,16 @@ module Tinkerforge
348
378
  # This function is used by Brick Viewer during flashing. It should not be
349
379
  # necessary to call it in a normal user program.
350
380
  def set_bootloader_mode(mode)
351
- send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 1, 'C'
381
+ check_validity
382
+
383
+ send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
352
384
  end
353
385
 
354
386
  # Returns the current bootloader mode, see BrickletIO4V2#set_bootloader_mode.
355
387
  def get_bootloader_mode
356
- send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 1, 'C'
388
+ check_validity
389
+
390
+ send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
357
391
  end
358
392
 
359
393
  # Sets the firmware pointer for BrickletIO4V2#write_firmware. The pointer has
@@ -363,7 +397,9 @@ module Tinkerforge
363
397
  # This function is used by Brick Viewer during flashing. It should not be
364
398
  # necessary to call it in a normal user program.
365
399
  def set_write_firmware_pointer(pointer)
366
- send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 0, ''
400
+ check_validity
401
+
402
+ send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
367
403
  end
368
404
 
369
405
  # Writes 64 Bytes of firmware at the position as written by
@@ -375,7 +411,9 @@ module Tinkerforge
375
411
  # This function is used by Brick Viewer during flashing. It should not be
376
412
  # necessary to call it in a normal user program.
377
413
  def write_firmware(data)
378
- send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 1, 'C'
414
+ check_validity
415
+
416
+ send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
379
417
  end
380
418
 
381
419
  # Sets the status LED configuration. By default the LED shows
@@ -386,22 +424,28 @@ module Tinkerforge
386
424
  #
387
425
  # If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
388
426
  def set_status_led_config(config)
389
- send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 0, ''
427
+ check_validity
428
+
429
+ send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
390
430
  end
391
431
 
392
432
  # Returns the configuration as set by BrickletIO4V2#set_status_led_config
393
433
  def get_status_led_config
394
- send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 1, 'C'
434
+ check_validity
435
+
436
+ send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
395
437
  end
396
438
 
397
- # Returns the temperature in °C as measured inside the microcontroller. The
439
+ # Returns the temperature as measured inside the microcontroller. The
398
440
  # value returned is not the ambient temperature!
399
441
  #
400
442
  # The temperature is only proportional to the real temperature and it has bad
401
443
  # accuracy. Practically it is only useful as an indicator for
402
444
  # temperature changes.
403
445
  def get_chip_temperature
404
- send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's'
446
+ check_validity
447
+
448
+ send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
405
449
  end
406
450
 
407
451
  # Calling this function will reset the Bricklet. All configurations
@@ -411,7 +455,9 @@ module Tinkerforge
411
455
  # calling functions on the existing ones will result in
412
456
  # undefined behavior!
413
457
  def reset
414
- send_request FUNCTION_RESET, [], '', 0, ''
458
+ check_validity
459
+
460
+ send_request FUNCTION_RESET, [], '', 8, ''
415
461
  end
416
462
 
417
463
  # Writes a new UID into flash. If you want to set a new UID
@@ -420,25 +466,31 @@ module Tinkerforge
420
466
  #
421
467
  # We recommend that you use Brick Viewer to change the UID.
422
468
  def write_uid(uid)
423
- send_request FUNCTION_WRITE_UID, [uid], 'L', 0, ''
469
+ check_validity
470
+
471
+ send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
424
472
  end
425
473
 
426
474
  # Returns the current UID as an integer. Encode as
427
475
  # Base58 to get the usual string version.
428
476
  def read_uid
429
- send_request FUNCTION_READ_UID, [], '', 4, 'L'
477
+ check_validity
478
+
479
+ send_request FUNCTION_READ_UID, [], '', 12, 'L'
430
480
  end
431
481
 
432
482
  # Returns the UID, the UID where the Bricklet is connected to,
433
483
  # the position, the hardware and firmware version as well as the
434
484
  # device identifier.
435
485
  #
436
- # The position can be 'a', 'b', 'c' or 'd'.
486
+ # The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
487
+ # A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
488
+ # position 'z'.
437
489
  #
438
490
  # The device identifier numbers can be found :ref:`here <device_identifier>`.
439
491
  # |device_identifier_constant|
440
492
  def get_identity
441
- send_request FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S'
493
+ send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
442
494
  end
443
495
 
444
496
  # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.