tinkerforge 2.0.7

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 (35) hide show
  1. data/lib/tinkerforge.rb +5 -0
  2. data/lib/tinkerforge/brick_dc.rb +359 -0
  3. data/lib/tinkerforge/brick_imu.rb +512 -0
  4. data/lib/tinkerforge/brick_master.rb +1120 -0
  5. data/lib/tinkerforge/brick_servo.rb +475 -0
  6. data/lib/tinkerforge/brick_stepper.rb +556 -0
  7. data/lib/tinkerforge/bricklet_ambient_light.rb +246 -0
  8. data/lib/tinkerforge/bricklet_analog_in.rb +273 -0
  9. data/lib/tinkerforge/bricklet_analog_out.rb +90 -0
  10. data/lib/tinkerforge/bricklet_barometer.rb +313 -0
  11. data/lib/tinkerforge/bricklet_current12.rb +274 -0
  12. data/lib/tinkerforge/bricklet_current25.rb +274 -0
  13. data/lib/tinkerforge/bricklet_distance_ir.rb +274 -0
  14. data/lib/tinkerforge/bricklet_dual_relay.rb +127 -0
  15. data/lib/tinkerforge/bricklet_gps.rb +301 -0
  16. data/lib/tinkerforge/bricklet_humidity.rb +245 -0
  17. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +165 -0
  18. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +177 -0
  19. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +177 -0
  20. data/lib/tinkerforge/bricklet_io16.rb +237 -0
  21. data/lib/tinkerforge/bricklet_io4.rb +236 -0
  22. data/lib/tinkerforge/bricklet_joystick.rb +274 -0
  23. data/lib/tinkerforge/bricklet_lcd_16x2.rb +175 -0
  24. data/lib/tinkerforge/bricklet_lcd_20x4.rb +231 -0
  25. data/lib/tinkerforge/bricklet_linear_poti.rb +241 -0
  26. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +84 -0
  27. data/lib/tinkerforge/bricklet_ptc.rb +277 -0
  28. data/lib/tinkerforge/bricklet_rotary_poti.rb +241 -0
  29. data/lib/tinkerforge/bricklet_temperature.rb +188 -0
  30. data/lib/tinkerforge/bricklet_temperature_ir.rb +275 -0
  31. data/lib/tinkerforge/bricklet_voltage.rb +241 -0
  32. data/lib/tinkerforge/bricklet_voltage_current.rb +386 -0
  33. data/lib/tinkerforge/ip_connection.rb +1027 -0
  34. data/lib/tinkerforge/version.rb +4 -0
  35. metadata +98 -0
@@ -0,0 +1,90 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
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 generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for output of voltage between 0 and 5V
14
+ class BrickletAnalogOut < Device
15
+ DEVICE_IDENTIFIER = 220 # :nodoc:
16
+
17
+ FUNCTION_SET_VOLTAGE = 1 # :nodoc:
18
+ FUNCTION_GET_VOLTAGE = 2 # :nodoc:
19
+ FUNCTION_SET_MODE = 3 # :nodoc:
20
+ FUNCTION_GET_MODE = 4 # :nodoc:
21
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
22
+
23
+ MODE_ANALOG_VALUE = 0 # :nodoc:
24
+ MODE_1K_TO_GROUND = 1 # :nodoc:
25
+ MODE_100K_TO_GROUND = 2 # :nodoc:
26
+ MODE_500K_TO_GROUND = 3 # :nodoc:
27
+
28
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
29
+ # the IP Connection <tt>ipcon</tt>.
30
+ def initialize(uid, ipcon)
31
+ super uid, ipcon
32
+
33
+ @api_version = [2, 0, 0]
34
+
35
+ @response_expected[FUNCTION_SET_VOLTAGE] = RESPONSE_EXPECTED_FALSE
36
+ @response_expected[FUNCTION_GET_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
37
+ @response_expected[FUNCTION_SET_MODE] = RESPONSE_EXPECTED_FALSE
38
+ @response_expected[FUNCTION_GET_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
39
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
40
+
41
+ end
42
+
43
+ # Sets the voltage in mV. The possible range is 0V to 5V (0-5000).
44
+ # Calling this function will set the mode to 0 (see BrickletAnalogOut#set_mode).
45
+ #
46
+ # The default value is 0 (with mode 1).
47
+ def set_voltage(voltage)
48
+ send_request(FUNCTION_SET_VOLTAGE, [voltage], 'S', 0, '')
49
+ end
50
+
51
+ # Returns the voltage as set by BrickletAnalogOut#set_voltage.
52
+ def get_voltage
53
+ send_request(FUNCTION_GET_VOLTAGE, [], '', 2, 'S')
54
+ end
55
+
56
+ # Sets the mode of the analog value. Possible modes:
57
+ #
58
+ # * 0: Normal Mode (Analog value as set by BrickletAnalogOut#set_voltage is applied)
59
+ # * 1: 1k Ohm resistor to ground
60
+ # * 2: 100k Ohm resistor to ground
61
+ # * 3: 500k Ohm resistor to ground
62
+ #
63
+ # Setting the mode to 0 will result in an output voltage of 0. You can jump
64
+ # to a higher output voltage directly by calling BrickletAnalogOut#set_voltage.
65
+ #
66
+ # The default mode is 1.
67
+ def set_mode(mode)
68
+ send_request(FUNCTION_SET_MODE, [mode], 'C', 0, '')
69
+ end
70
+
71
+ # Returns the mode as set by BrickletAnalogOut#set_mode.
72
+ def get_mode
73
+ send_request(FUNCTION_GET_MODE, [], '', 1, 'C')
74
+ end
75
+
76
+ # Returns the UID, the UID where the Bricklet is connected to,
77
+ # the position, the hardware and firmware version as well as the
78
+ # device identifier.
79
+ #
80
+ # The position can be 'a', 'b', 'c' or 'd'.
81
+ #
82
+ # The device identifiers can be found :ref:`here <device_identifier>`.
83
+ #
84
+ # .. versionadded:: 2.0.0~(Plugin)
85
+ def get_identity
86
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,313 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
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 generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for sensing air pressure and altitude changes
14
+ class BrickletBarometer < Device
15
+ DEVICE_IDENTIFIER = 221 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletBarometer#set_air_pressure_callback_period. The parameter is the air pressure of the
19
+ # air pressure sensor.
20
+ #
21
+ # CALLBACK_AIR_PRESSURE is only triggered if the air pressure has changed since the
22
+ # last triggering.
23
+ CALLBACK_AIR_PRESSURE = 15
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletBarometer#set_altitude_callback_period. The parameter is the altitude of the
27
+ # air pressure sensor.
28
+ #
29
+ # CALLBACK_ALTITUDE is only triggered if the altitude has changed since the
30
+ # last triggering.
31
+ CALLBACK_ALTITUDE = 16
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletBarometer#set_air_pressure_callback_threshold is reached.
35
+ # The parameter is the air pressure of the air pressure sensor.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletBarometer#set_debounce_period.
39
+ CALLBACK_AIR_PRESSURE_REACHED = 17
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletBarometer#set_altitude_callback_threshold is reached.
43
+ # The parameter is the altitude of the air pressure sensor.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletBarometer#set_debounce_period.
47
+ CALLBACK_ALTITUDE_REACHED = 18
48
+
49
+ FUNCTION_GET_AIR_PRESSURE = 1 # :nodoc:
50
+ FUNCTION_GET_ALTITUDE = 2 # :nodoc:
51
+ FUNCTION_SET_AIR_PRESSURE_CALLBACK_PERIOD = 3 # :nodoc:
52
+ FUNCTION_GET_AIR_PRESSURE_CALLBACK_PERIOD = 4 # :nodoc:
53
+ FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD = 5 # :nodoc:
54
+ FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD = 6 # :nodoc:
55
+ FUNCTION_SET_AIR_PRESSURE_CALLBACK_THRESHOLD = 7 # :nodoc:
56
+ FUNCTION_GET_AIR_PRESSURE_CALLBACK_THRESHOLD = 8 # :nodoc:
57
+ FUNCTION_SET_ALTITUDE_CALLBACK_THRESHOLD = 9 # :nodoc:
58
+ FUNCTION_GET_ALTITUDE_CALLBACK_THRESHOLD = 10 # :nodoc:
59
+ FUNCTION_SET_DEBOUNCE_PERIOD = 11 # :nodoc:
60
+ FUNCTION_GET_DEBOUNCE_PERIOD = 12 # :nodoc:
61
+ FUNCTION_SET_REFERENCE_AIR_PRESSURE = 13 # :nodoc:
62
+ FUNCTION_GET_CHIP_TEMPERATURE = 14 # :nodoc:
63
+ FUNCTION_GET_REFERENCE_AIR_PRESSURE = 19 # :nodoc:
64
+ FUNCTION_SET_AVERAGING = 20 # :nodoc:
65
+ FUNCTION_GET_AVERAGING = 21 # :nodoc:
66
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
67
+
68
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
69
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
70
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
71
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
72
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
73
+
74
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
75
+ # the IP Connection <tt>ipcon</tt>.
76
+ def initialize(uid, ipcon)
77
+ super uid, ipcon
78
+
79
+ @api_version = [2, 0, 1]
80
+
81
+ @response_expected[FUNCTION_GET_AIR_PRESSURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
82
+ @response_expected[FUNCTION_GET_ALTITUDE] = RESPONSE_EXPECTED_ALWAYS_TRUE
83
+ @response_expected[FUNCTION_SET_AIR_PRESSURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
84
+ @response_expected[FUNCTION_GET_AIR_PRESSURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
85
+ @response_expected[FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
86
+ @response_expected[FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
87
+ @response_expected[FUNCTION_SET_AIR_PRESSURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
88
+ @response_expected[FUNCTION_GET_AIR_PRESSURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
89
+ @response_expected[FUNCTION_SET_ALTITUDE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
90
+ @response_expected[FUNCTION_GET_ALTITUDE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
91
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
92
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
93
+ @response_expected[FUNCTION_SET_REFERENCE_AIR_PRESSURE] = RESPONSE_EXPECTED_FALSE
94
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
95
+ @response_expected[CALLBACK_AIR_PRESSURE] = RESPONSE_EXPECTED_ALWAYS_FALSE
96
+ @response_expected[CALLBACK_ALTITUDE] = RESPONSE_EXPECTED_ALWAYS_FALSE
97
+ @response_expected[CALLBACK_AIR_PRESSURE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
98
+ @response_expected[CALLBACK_ALTITUDE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
99
+ @response_expected[FUNCTION_GET_REFERENCE_AIR_PRESSURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
100
+ @response_expected[FUNCTION_SET_AVERAGING] = RESPONSE_EXPECTED_FALSE
101
+ @response_expected[FUNCTION_GET_AVERAGING] = RESPONSE_EXPECTED_ALWAYS_TRUE
102
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+
104
+ @callback_formats[CALLBACK_AIR_PRESSURE] = 'l'
105
+ @callback_formats[CALLBACK_ALTITUDE] = 'l'
106
+ @callback_formats[CALLBACK_AIR_PRESSURE_REACHED] = 'l'
107
+ @callback_formats[CALLBACK_ALTITUDE_REACHED] = 'l'
108
+ end
109
+
110
+ # Returns the air pressure of the air pressure sensor. The value
111
+ # has a range of 10000 to 1200000 and is given in mbar/1000, i.e. a value
112
+ # of 1001092 means that an air pressure of 1001.092 mbar is measured.
113
+ #
114
+ # If you want to get the air pressure periodically, it is recommended to use the
115
+ # callback CALLBACK_AIR_PRESSURE and set the period with
116
+ # BrickletBarometer#set_air_pressure_callback_period.
117
+ def get_air_pressure
118
+ send_request(FUNCTION_GET_AIR_PRESSURE, [], '', 4, 'l')
119
+ end
120
+
121
+ # Returns the relative altitude of the air pressure sensor. The value is given in
122
+ # cm and is calculated based on the difference between the current air pressure
123
+ # and the reference air pressure that can be set with BrickletBarometer#set_reference_air_pressure.
124
+ #
125
+ # If you want to get the altitude periodically, it is recommended to use the
126
+ # callback CALLBACK_ALTITUDE and set the period with
127
+ # BrickletBarometer#set_altitude_callback_period.
128
+ def get_altitude
129
+ send_request(FUNCTION_GET_ALTITUDE, [], '', 4, 'l')
130
+ end
131
+
132
+ # Sets the period in ms with which the CALLBACK_AIR_PRESSURE callback is triggered
133
+ # periodically. A value of 0 turns the callback off.
134
+ #
135
+ # CALLBACK_AIR_PRESSURE is only triggered if the air pressure has changed since the
136
+ # last triggering.
137
+ #
138
+ # The default value is 0.
139
+ def set_air_pressure_callback_period(period)
140
+ send_request(FUNCTION_SET_AIR_PRESSURE_CALLBACK_PERIOD, [period], 'L', 0, '')
141
+ end
142
+
143
+ # Returns the period as set by BrickletBarometer#set_air_pressure_callback_period.
144
+ def get_air_pressure_callback_period
145
+ send_request(FUNCTION_GET_AIR_PRESSURE_CALLBACK_PERIOD, [], '', 4, 'L')
146
+ end
147
+
148
+ # Sets the period in ms with which the CALLBACK_ALTITUDE callback is triggered
149
+ # periodically. A value of 0 turns the callback off.
150
+ #
151
+ # CALLBACK_ALTITUDE is only triggered if the altitude has changed since the
152
+ # last triggering.
153
+ #
154
+ # The default value is 0.
155
+ def set_altitude_callback_period(period)
156
+ send_request(FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD, [period], 'L', 0, '')
157
+ end
158
+
159
+ # Returns the period as set by BrickletBarometer#set_altitude_callback_period.
160
+ def get_altitude_callback_period
161
+ send_request(FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD, [], '', 4, 'L')
162
+ end
163
+
164
+ # Sets the thresholds for the CALLBACK_AIR_PRESSURE_REACHED callback.
165
+ #
166
+ # The following options are possible:
167
+ #
168
+ # "Option", "Description"
169
+ #
170
+ # "'x'", "Callback is turned off"
171
+ # "'o'", "Callback is triggered when the air pressure is *outside* the min and max values"
172
+ # "'i'", "Callback is triggered when the air pressure is *inside* the min and max values"
173
+ # "'<'", "Callback is triggered when the air pressure is smaller than the min value (max is ignored)"
174
+ # "'>'", "Callback is triggered when the air pressure is greater than the min value (max is ignored)"
175
+ #
176
+ # The default value is ('x', 0, 0).
177
+ def set_air_pressure_callback_threshold(option, min, max)
178
+ send_request(FUNCTION_SET_AIR_PRESSURE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
179
+ end
180
+
181
+ # Returns the threshold as set by BrickletBarometer#set_air_pressure_callback_threshold.
182
+ def get_air_pressure_callback_threshold
183
+ send_request(FUNCTION_GET_AIR_PRESSURE_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
184
+ end
185
+
186
+ # Sets the thresholds for the CALLBACK_ALTITUDE_REACHED callback.
187
+ #
188
+ # The following options are possible:
189
+ #
190
+ # "Option", "Description"
191
+ #
192
+ # "'x'", "Callback is turned off"
193
+ # "'o'", "Callback is triggered when the altitude is *outside* the min and max values"
194
+ # "'i'", "Callback is triggered when the altitude is *inside* the min and max values"
195
+ # "'<'", "Callback is triggered when the altitude is smaller than the min value (max is ignored)"
196
+ # "'>'", "Callback is triggered when the altitude is greater than the min value (max is ignored)"
197
+ #
198
+ # The default value is ('x', 0, 0).
199
+ def set_altitude_callback_threshold(option, min, max)
200
+ send_request(FUNCTION_SET_ALTITUDE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
201
+ end
202
+
203
+ # Returns the threshold as set by BrickletBarometer#set_altitude_callback_threshold.
204
+ def get_altitude_callback_threshold
205
+ send_request(FUNCTION_GET_ALTITUDE_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
206
+ end
207
+
208
+ # Sets the period in ms with which the threshold callbacks
209
+ #
210
+ # CALLBACK_AIR_PRESSURE_REACHED, CALLBACK_ALTITUDE_REACHED
211
+ #
212
+ # are triggered, if the thresholds
213
+ #
214
+ # BrickletBarometer#set_air_pressure_callback_threshold, BrickletBarometer#set_altitude_callback_threshold
215
+ #
216
+ # keep being reached.
217
+ #
218
+ # The default value is 100.
219
+ def set_debounce_period(debounce)
220
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
221
+ end
222
+
223
+ # Returns the debounce period as set by BrickletBarometer#set_debounce_period.
224
+ def get_debounce_period
225
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
226
+ end
227
+
228
+ # Sets the reference air pressure in mbar/1000 for the altitude calculation.
229
+ # Setting the reference to the current air pressure results in a calculated
230
+ # altitude of 0cm. Passing 0 is a shortcut for passing the current air pressure as
231
+ # reference.
232
+ #
233
+ # Well known reference values are the Q codes
234
+ # `QNH <http://en.wikipedia.org/wiki/QNH>`__ and
235
+ # `QFE <http://en.wikipedia.org/wiki/Mean_sea_level_pressure#Mean_sea_level_pressure>`__
236
+ # used in aviation.
237
+ #
238
+ # The default value is 1013.25mbar.
239
+ #
240
+ # .. versionadded:: 1.1.0~(Plugin)
241
+ def set_reference_air_pressure(air_pressure)
242
+ send_request(FUNCTION_SET_REFERENCE_AIR_PRESSURE, [air_pressure], 'l', 0, '')
243
+ end
244
+
245
+ # Returns the temperature of the air pressure sensor. The value
246
+ # has a range of -4000 to 8500 and is given in °C/100, i.e. a value
247
+ # of 2007 means that a temperature of 20.07 °C is measured.
248
+ #
249
+ # This temperature is used internally for temperature compensation of the air
250
+ # pressure measurement. It is not as accurate as the temperature measured by the
251
+ # :ref:`temperature_bricklet` or the :ref:`temperature_ir_bricklet`.
252
+ def get_chip_temperature
253
+ send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
254
+ end
255
+
256
+ # Returns the reference air pressure as set by BrickletBarometer#set_reference_air_pressure.
257
+ #
258
+ # .. versionadded:: 1.1.0~(Plugin)
259
+ def get_reference_air_pressure
260
+ send_request(FUNCTION_GET_REFERENCE_AIR_PRESSURE, [], '', 4, 'l')
261
+ end
262
+
263
+ # Sets the different averaging parameters. It is possible to set
264
+ # the length of a normal averaging for the temperature and pressure,
265
+ # as well as an additional length of a
266
+ # `moving average <http://en.wikipedia.org/wiki/Moving_average>`__
267
+ # for the pressure. The moving average is calculated from the normal
268
+ # averages. There is no moving average for the temperature.
269
+ #
270
+ # The maximum length for the pressure average is 10, for the
271
+ # temperature average is 255 and for the moving average is 25.
272
+ #
273
+ # Setting the all three parameters to 0 will turn the averaging
274
+ # completely off. If the averaging is off, there is lots of noise
275
+ # on the data, but the data is without delay. Thus we recommend
276
+ # to turn the averaging off if the Barometer Bricklet data is
277
+ # to be used for sensor fusion with other sensors.
278
+ #
279
+ # The default values are 10 for the normal averages and 25 for the
280
+ # moving average.
281
+ #
282
+ # .. versionadded:: 2.0.1~(Plugin)
283
+ def set_averaging(moving_average_pressure, average_pressure, average_temperature)
284
+ send_request(FUNCTION_SET_AVERAGING, [moving_average_pressure, average_pressure, average_temperature], 'C C C', 0, '')
285
+ end
286
+
287
+ # Returns the averaging configuration as set by BrickletBarometer#set_averaging.
288
+ #
289
+ # .. versionadded:: 2.0.1~(Plugin)
290
+ def get_averaging
291
+ send_request(FUNCTION_GET_AVERAGING, [], '', 3, 'C C C')
292
+ end
293
+
294
+ # Returns the UID, the UID where the Bricklet is connected to,
295
+ # the position, the hardware and firmware version as well as the
296
+ # device identifier.
297
+ #
298
+ # The position can be 'a', 'b', 'c' or 'd'.
299
+ #
300
+ # The device identifiers can be found :ref:`here <device_identifier>`.
301
+ #
302
+ # .. versionadded:: 2.0.0~(Plugin)
303
+ def get_identity
304
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
305
+ end
306
+
307
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
308
+ def register_callback(id, &block)
309
+ callback = block
310
+ @registered_callbacks[id] = callback
311
+ end
312
+ end
313
+ end
@@ -0,0 +1,274 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
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 generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for sensing current of up to 12.5A
14
+ class BrickletCurrent12 < Device
15
+ DEVICE_IDENTIFIER = 23 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletCurrent12#set_current_callback_period. The parameter is the current of the
19
+ # sensor.
20
+ #
21
+ # CALLBACK_CURRENT is only triggered if the current has changed since the
22
+ # last triggering.
23
+ CALLBACK_CURRENT = 15
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletCurrent12#set_analog_value_callback_period. The parameter is the analog value
27
+ # of the sensor.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the current has changed since the
30
+ # last triggering.
31
+ CALLBACK_ANALOG_VALUE = 16
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletCurrent12#set_current_callback_threshold is reached.
35
+ # The parameter is the current of the sensor.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletCurrent12#set_debounce_period.
39
+ CALLBACK_CURRENT_REACHED = 17
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletCurrent12#set_analog_value_callback_threshold is reached.
43
+ # The parameter is the analog value of the sensor.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletCurrent12#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 18
48
+
49
+ # This callback is triggered when an over current is measured
50
+ # (see BrickletCurrent12#is_over_current).
51
+ CALLBACK_OVER_CURRENT = 19
52
+
53
+ FUNCTION_GET_CURRENT = 1 # :nodoc:
54
+ FUNCTION_CALIBRATE = 2 # :nodoc:
55
+ FUNCTION_IS_OVER_CURRENT = 3 # :nodoc:
56
+ FUNCTION_GET_ANALOG_VALUE = 4 # :nodoc:
57
+ FUNCTION_SET_CURRENT_CALLBACK_PERIOD = 5 # :nodoc:
58
+ FUNCTION_GET_CURRENT_CALLBACK_PERIOD = 6 # :nodoc:
59
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 7 # :nodoc:
60
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 8 # :nodoc:
61
+ FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD = 9 # :nodoc:
62
+ FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD = 10 # :nodoc:
63
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 11 # :nodoc:
64
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 12 # :nodoc:
65
+ FUNCTION_SET_DEBOUNCE_PERIOD = 13 # :nodoc:
66
+ FUNCTION_GET_DEBOUNCE_PERIOD = 14 # :nodoc:
67
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
68
+
69
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
70
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
71
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
72
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
73
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
74
+
75
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
76
+ # the IP Connection <tt>ipcon</tt>.
77
+ def initialize(uid, ipcon)
78
+ super uid, ipcon
79
+
80
+ @api_version = [2, 0, 0]
81
+
82
+ @response_expected[FUNCTION_GET_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
83
+ @response_expected[FUNCTION_CALIBRATE] = RESPONSE_EXPECTED_FALSE
84
+ @response_expected[FUNCTION_IS_OVER_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
85
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_SET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
87
+ @response_expected[FUNCTION_GET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
88
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
89
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
90
+ @response_expected[FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
91
+ @response_expected[FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
92
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
93
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
94
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
95
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
96
+ @response_expected[CALLBACK_CURRENT] = RESPONSE_EXPECTED_ALWAYS_FALSE
97
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
98
+ @response_expected[CALLBACK_CURRENT_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
99
+ @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
100
+ @response_expected[CALLBACK_OVER_CURRENT] = RESPONSE_EXPECTED_ALWAYS_FALSE
101
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
102
+
103
+ @callback_formats[CALLBACK_CURRENT] = 's'
104
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
105
+ @callback_formats[CALLBACK_CURRENT_REACHED] = 's'
106
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
107
+ @callback_formats[CALLBACK_OVER_CURRENT] = ''
108
+ end
109
+
110
+ # Returns the current of the sensor. The value is in mA
111
+ # and between -12500mA and 12500mA.
112
+ #
113
+ # If you want to get the current periodically, it is recommended to use the
114
+ # callback CALLBACK_CURRENT and set the period with
115
+ # BrickletCurrent12#set_current_callback_period.
116
+ def get_current
117
+ send_request(FUNCTION_GET_CURRENT, [], '', 2, 's')
118
+ end
119
+
120
+ # Calibrates the 0 value of the sensor. You have to call this function
121
+ # when there is no current present.
122
+ #
123
+ # The zero point of the current sensor
124
+ # is depending on the exact properties of the analog-to-digital converter,
125
+ # the length of the Bricklet cable and the temperature. Thus, if you change
126
+ # the Brick or the environment in which the Bricklet is used, you might
127
+ # have to recalibrate.
128
+ #
129
+ # The resulting calibration will be saved on the EEPROM of the Current
130
+ # Bricklet.
131
+ def calibrate
132
+ send_request(FUNCTION_CALIBRATE, [], '', 0, '')
133
+ end
134
+
135
+ # Returns *true* if more than 12.5A were measured.
136
+ #
137
+ # .. note::
138
+ # To reset this value you have to power cycle the Bricklet.
139
+ def is_over_current
140
+ send_request(FUNCTION_IS_OVER_CURRENT, [], '', 1, '?')
141
+ end
142
+
143
+ # Returns the value as read by a 12-bit analog-to-digital converter.
144
+ # The value is between 0 and 4095.
145
+ #
146
+ # .. note::
147
+ # The value returned by BrickletCurrent12#get_current is averaged over several samples
148
+ # to yield less noise, while BrickletCurrent12#get_analog_value gives back raw
149
+ # unfiltered analog values. The only reason to use BrickletCurrent12#get_analog_value is,
150
+ # if you need the full resolution of the analog-to-digital converter.
151
+ #
152
+ # If you want the analog value periodically, it is recommended to use the
153
+ # callback CALLBACK_ANALOG_VALUE and set the period with
154
+ # BrickletCurrent12#set_analog_value_callback_period.
155
+ def get_analog_value
156
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S')
157
+ end
158
+
159
+ # Sets the period in ms with which the CALLBACK_CURRENT callback is triggered
160
+ # periodically. A value of 0 turns the callback off.
161
+ #
162
+ # CALLBACK_CURRENT is only triggered if the current has changed since the
163
+ # last triggering.
164
+ #
165
+ # The default value is 0.
166
+ def set_current_callback_period(period)
167
+ send_request(FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 0, '')
168
+ end
169
+
170
+ # Returns the period as set by BrickletCurrent12#set_current_callback_period.
171
+ def get_current_callback_period
172
+ send_request(FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 4, 'L')
173
+ end
174
+
175
+ # Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered
176
+ # periodically. A value of 0 turns the callback off.
177
+ #
178
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
179
+ # last triggering.
180
+ #
181
+ # The default value is 0.
182
+ def set_analog_value_callback_period(period)
183
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '')
184
+ end
185
+
186
+ # Returns the period as set by BrickletCurrent12#set_analog_value_callback_period.
187
+ def get_analog_value_callback_period
188
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L')
189
+ end
190
+
191
+ # Sets the thresholds for the CALLBACK_CURRENT_REACHED callback.
192
+ #
193
+ # The following options are possible:
194
+ #
195
+ # "Option", "Description"
196
+ #
197
+ # "'x'", "Callback is turned off"
198
+ # "'o'", "Callback is triggered when the current is *outside* the min and max values"
199
+ # "'i'", "Callback is triggered when the current is *inside* the min and max values"
200
+ # "'<'", "Callback is triggered when the current is smaller than the min value (max is ignored)"
201
+ # "'>'", "Callback is triggered when the current is greater than the min value (max is ignored)"
202
+ #
203
+ # The default value is ('x', 0, 0).
204
+ def set_current_callback_threshold(option, min, max)
205
+ send_request(FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
206
+ end
207
+
208
+ # Returns the threshold as set by BrickletCurrent12#set_current_callback_threshold.
209
+ def get_current_callback_threshold
210
+ send_request(FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
211
+ end
212
+
213
+ # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
214
+ #
215
+ # The following options are possible:
216
+ #
217
+ # "Option", "Description"
218
+ #
219
+ # "'x'", "Callback is turned off"
220
+ # "'o'", "Callback is triggered when the analog value is *outside* the min and max values"
221
+ # "'i'", "Callback is triggered when the analog value is *inside* the min and max values"
222
+ # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
223
+ # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
224
+ #
225
+ # The default value is ('x', 0, 0).
226
+ def set_analog_value_callback_threshold(option, min, max)
227
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
228
+ end
229
+
230
+ # Returns the threshold as set by BrickletCurrent12#set_analog_value_callback_threshold.
231
+ def get_analog_value_callback_threshold
232
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
233
+ end
234
+
235
+ # Sets the period in ms with which the threshold callbacks
236
+ #
237
+ # CALLBACK_CURRENT_REACHED, CALLBACK_ANALOG_VALUE_REACHED
238
+ #
239
+ # are triggered, if the thresholds
240
+ #
241
+ # BrickletCurrent12#set_current_callback_threshold, BrickletCurrent12#set_analog_value_callback_threshold
242
+ #
243
+ # keep being reached.
244
+ #
245
+ # The default value is 100.
246
+ def set_debounce_period(debounce)
247
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
248
+ end
249
+
250
+ # Returns the debounce period as set by BrickletCurrent12#set_debounce_period.
251
+ def get_debounce_period
252
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
253
+ end
254
+
255
+ # Returns the UID, the UID where the Bricklet is connected to,
256
+ # the position, the hardware and firmware version as well as the
257
+ # device identifier.
258
+ #
259
+ # The position can be 'a', 'b', 'c' or 'd'.
260
+ #
261
+ # The device identifiers can be found :ref:`here <device_identifier>`.
262
+ #
263
+ # .. versionadded:: 2.0.0~(Plugin)
264
+ def get_identity
265
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
266
+ end
267
+
268
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
269
+ def register_callback(id, &block)
270
+ callback = block
271
+ @registered_callbacks[id] = callback
272
+ end
273
+ end
274
+ end