tinkerforge 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
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,127 @@
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 controlling two relays
14
+ class BrickletDualRelay < Device
15
+ DEVICE_IDENTIFIER = 26 # :nodoc:
16
+
17
+ # This callback is triggered whenever a monoflop timer reaches 0. The
18
+ # parameter contain the relay (1 or 2) and the current state of the relay
19
+ # (the state after the monoflop).
20
+ #
21
+ # .. versionadded:: 1.1.1~(Plugin)
22
+ CALLBACK_MONOFLOP_DONE = 5
23
+
24
+ FUNCTION_SET_STATE = 1 # :nodoc:
25
+ FUNCTION_GET_STATE = 2 # :nodoc:
26
+ FUNCTION_SET_MONOFLOP = 3 # :nodoc:
27
+ FUNCTION_GET_MONOFLOP = 4 # :nodoc:
28
+ FUNCTION_SET_SELECTED_STATE = 6 # :nodoc:
29
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
30
+
31
+
32
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
33
+ # the IP Connection <tt>ipcon</tt>.
34
+ def initialize(uid, ipcon)
35
+ super uid, ipcon
36
+
37
+ @api_version = [2, 0, 0]
38
+
39
+ @response_expected[FUNCTION_SET_STATE] = RESPONSE_EXPECTED_FALSE
40
+ @response_expected[FUNCTION_GET_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
41
+ @response_expected[FUNCTION_SET_MONOFLOP] = RESPONSE_EXPECTED_FALSE
42
+ @response_expected[FUNCTION_GET_MONOFLOP] = RESPONSE_EXPECTED_ALWAYS_TRUE
43
+ @response_expected[CALLBACK_MONOFLOP_DONE] = RESPONSE_EXPECTED_ALWAYS_FALSE
44
+ @response_expected[FUNCTION_SET_SELECTED_STATE] = RESPONSE_EXPECTED_FALSE
45
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
46
+
47
+ @callback_formats[CALLBACK_MONOFLOP_DONE] = 'C ?'
48
+ end
49
+
50
+ # Sets the state of the relays, *true* means on and *false* means off.
51
+ # For example: (true, false) turns relay 1 on and relay 2 off.
52
+ #
53
+ # If you just want to set one of the relays and don't know the current state
54
+ # of the other relay, you can get the state with BrickletDualRelay#get_state or you
55
+ # can use BrickletDualRelay#set_selected_state.
56
+ #
57
+ # Running monoflop timers will be overwritten if this function is called.
58
+ #
59
+ # The default value is (*false*, *false*).
60
+ def set_state(relay1, relay2)
61
+ send_request(FUNCTION_SET_STATE, [relay1, relay2], '? ?', 0, '')
62
+ end
63
+
64
+ # Returns the state of the relays, *true* means on and *false* means off.
65
+ def get_state
66
+ send_request(FUNCTION_GET_STATE, [], '', 2, '? ?')
67
+ end
68
+
69
+ # The first parameter can be 1 or 2 (relay 1 or relay 2). The second parameter
70
+ # is the desired state of the relay (*true* means on and *false* means off).
71
+ # The third parameter indicates the time (in ms) that the relay should hold
72
+ # the state.
73
+ #
74
+ # If this function is called with the parameters (1, true, 1500):
75
+ # Relay 1 will turn on and in 1.5s it will turn off again.
76
+ #
77
+ # A monoflop can be used as a failsafe mechanism. For example: Lets assume you
78
+ # have a RS485 bus and a Dual Relay Bricklet connected to one of the slave
79
+ # stacks. You can now call this function every second, with a time parameter
80
+ # of two seconds. The relay will be on all the time. If now the RS485
81
+ # connection is lost, the relay will turn off in at most two seconds.
82
+ #
83
+ # .. versionadded:: 1.1.1~(Plugin)
84
+ def set_monoflop(relay, state, time)
85
+ send_request(FUNCTION_SET_MONOFLOP, [relay, state, time], 'C ? L', 0, '')
86
+ end
87
+
88
+ # Returns (for the given relay) the current state and the time as set by
89
+ # BrickletDualRelay#set_monoflop as well as the remaining time until the state flips.
90
+ #
91
+ # If the timer is not running currently, the remaining time will be returned
92
+ # as 0.
93
+ #
94
+ # .. versionadded:: 1.1.1~(Plugin)
95
+ def get_monoflop(relay)
96
+ send_request(FUNCTION_GET_MONOFLOP, [relay], 'C', 9, '? L L')
97
+ end
98
+
99
+ # Sets the state of the selected relay (1 or 2), *true* means on and *false* means off.
100
+ #
101
+ # The other relay remains untouched.
102
+ #
103
+ # .. versionadded:: 2.0.0~(Plugin)
104
+ def set_selected_state(relay, state)
105
+ send_request(FUNCTION_SET_SELECTED_STATE, [relay, state], 'C ?', 0, '')
106
+ end
107
+
108
+ # Returns the UID, the UID where the Bricklet is connected to,
109
+ # the position, the hardware and firmware version as well as the
110
+ # device identifier.
111
+ #
112
+ # The position can be 'a', 'b', 'c' or 'd'.
113
+ #
114
+ # The device identifiers can be found :ref:`here <device_identifier>`.
115
+ #
116
+ # .. versionadded:: 2.0.0~(Plugin)
117
+ def get_identity
118
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
119
+ end
120
+
121
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
122
+ def register_callback(id, &block)
123
+ callback = block
124
+ @registered_callbacks[id] = callback
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,301 @@
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 receiving GPS position
14
+ class BrickletGPS < Device
15
+ DEVICE_IDENTIFIER = 222 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletGPS#set_coordinates_callback_period. The parameters are the same
19
+ # as for BrickletGPS#get_coordinates.
20
+ #
21
+ # CALLBACK_COORDINATES is only triggered if the coordinates changed since the
22
+ # last triggering and if there is currently a fix as indicated by
23
+ # BrickletGPS#get_status.
24
+ CALLBACK_COORDINATES = 17
25
+
26
+ # This callback is triggered periodically with the period that is set by
27
+ # BrickletGPS#set_status_callback_period. The parameters are the same
28
+ # as for BrickletGPS#get_status.
29
+ #
30
+ # CALLBACK_STATUS is only triggered if the status changed since the
31
+ # last triggering.
32
+ CALLBACK_STATUS = 18
33
+
34
+ # This callback is triggered periodically with the period that is set by
35
+ # BrickletGPS#set_altitude_callback_period. The parameters are the same
36
+ # as for BrickletGPS#get_altitude.
37
+ #
38
+ # CALLBACK_ALTITUDE is only triggered if the altitude changed since the
39
+ # last triggering and if there is currently a fix as indicated by
40
+ # BrickletGPS#get_status.
41
+ CALLBACK_ALTITUDE = 19
42
+
43
+ # This callback is triggered periodically with the period that is set by
44
+ # BrickletGPS#set_motion_callback_period. The parameters are the same
45
+ # as for BrickletGPS#get_motion.
46
+ #
47
+ # CALLBACK_MOTION is only triggered if the motion changed since the
48
+ # last triggering and if there is currently a fix as indicated by
49
+ # BrickletGPS#get_status.
50
+ CALLBACK_MOTION = 20
51
+
52
+ # This callback is triggered periodically with the period that is set by
53
+ # BrickletGPS#set_date_time_callback_period. The parameters are the same
54
+ # as for BrickletGPS#get_date_time.
55
+ #
56
+ # CALLBACK_DATE_TIME is only triggered if the date or time changed since the
57
+ # last triggering.
58
+ CALLBACK_DATE_TIME = 21
59
+
60
+ FUNCTION_GET_COORDINATES = 1 # :nodoc:
61
+ FUNCTION_GET_STATUS = 2 # :nodoc:
62
+ FUNCTION_GET_ALTITUDE = 3 # :nodoc:
63
+ FUNCTION_GET_MOTION = 4 # :nodoc:
64
+ FUNCTION_GET_DATE_TIME = 5 # :nodoc:
65
+ FUNCTION_RESTART = 6 # :nodoc:
66
+ FUNCTION_SET_COORDINATES_CALLBACK_PERIOD = 7 # :nodoc:
67
+ FUNCTION_GET_COORDINATES_CALLBACK_PERIOD = 8 # :nodoc:
68
+ FUNCTION_SET_STATUS_CALLBACK_PERIOD = 9 # :nodoc:
69
+ FUNCTION_GET_STATUS_CALLBACK_PERIOD = 10 # :nodoc:
70
+ FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD = 11 # :nodoc:
71
+ FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD = 12 # :nodoc:
72
+ FUNCTION_SET_DATE_TIME_CALLBACK_PERIOD = 13 # :nodoc:
73
+ FUNCTION_GET_DATE_TIME_CALLBACK_PERIOD = 14 # :nodoc:
74
+ FUNCTION_SET_MOTION_CALLBACK_PERIOD = 15 # :nodoc:
75
+ FUNCTION_GET_MOTION_CALLBACK_PERIOD = 16 # :nodoc:
76
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
77
+
78
+ FIX_NO_FIX = 1 # :nodoc:
79
+ FIX_2D_FIX = 2 # :nodoc:
80
+ FIX_3D_FIX = 3 # :nodoc:
81
+ RESTART_TYPE_HOT_START = 0 # :nodoc:
82
+ RESTART_TYPE_WARM_START = 1 # :nodoc:
83
+ RESTART_TYPE_COLD_START = 2 # :nodoc:
84
+ RESTART_TYPE_FACTORY_RESET = 3 # :nodoc:
85
+
86
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
87
+ # the IP Connection <tt>ipcon</tt>.
88
+ def initialize(uid, ipcon)
89
+ super uid, ipcon
90
+
91
+ @api_version = [2, 0, 0]
92
+
93
+ @response_expected[FUNCTION_GET_COORDINATES] = RESPONSE_EXPECTED_ALWAYS_TRUE
94
+ @response_expected[FUNCTION_GET_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE
95
+ @response_expected[FUNCTION_GET_ALTITUDE] = RESPONSE_EXPECTED_ALWAYS_TRUE
96
+ @response_expected[FUNCTION_GET_MOTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
97
+ @response_expected[FUNCTION_GET_DATE_TIME] = RESPONSE_EXPECTED_ALWAYS_TRUE
98
+ @response_expected[FUNCTION_RESTART] = RESPONSE_EXPECTED_FALSE
99
+ @response_expected[FUNCTION_SET_COORDINATES_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
100
+ @response_expected[FUNCTION_GET_COORDINATES_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
101
+ @response_expected[FUNCTION_SET_STATUS_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
102
+ @response_expected[FUNCTION_GET_STATUS_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+ @response_expected[FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
104
+ @response_expected[FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
105
+ @response_expected[FUNCTION_SET_DATE_TIME_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
106
+ @response_expected[FUNCTION_GET_DATE_TIME_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
107
+ @response_expected[FUNCTION_SET_MOTION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
108
+ @response_expected[FUNCTION_GET_MOTION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
109
+ @response_expected[CALLBACK_COORDINATES] = RESPONSE_EXPECTED_ALWAYS_FALSE
110
+ @response_expected[CALLBACK_STATUS] = RESPONSE_EXPECTED_ALWAYS_FALSE
111
+ @response_expected[CALLBACK_ALTITUDE] = RESPONSE_EXPECTED_ALWAYS_FALSE
112
+ @response_expected[CALLBACK_MOTION] = RESPONSE_EXPECTED_ALWAYS_FALSE
113
+ @response_expected[CALLBACK_DATE_TIME] = RESPONSE_EXPECTED_ALWAYS_FALSE
114
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
115
+
116
+ @callback_formats[CALLBACK_COORDINATES] = 'L k L k S S S S'
117
+ @callback_formats[CALLBACK_STATUS] = 'C C C'
118
+ @callback_formats[CALLBACK_ALTITUDE] = 'L L'
119
+ @callback_formats[CALLBACK_MOTION] = 'L L'
120
+ @callback_formats[CALLBACK_DATE_TIME] = 'L L'
121
+ end
122
+
123
+ # Returns the GPS coordinates. Latitude and longitude are given in the
124
+ # DD.dddddd° format, the value 57123468 means 57.123468°.
125
+ # The parameter ns and ew are the cardinal directions for
126
+ # latitude and longitude. Possible values for ns and ew are 'N', 'S', 'E'
127
+ # and 'W' (north, south, east and west).
128
+ #
129
+ # PDOP, HDOP and VDOP are the dilution of precision (DOP) values. They specify
130
+ # the additional multiplicative effect of GPS satellite geometry on GPS
131
+ # precision. See
132
+ # `here <http://en.wikipedia.org/wiki/Dilution_of_precision_(GPS)>`__
133
+ # for more information. The values are give in hundredths.
134
+ #
135
+ # EPE is the "Estimated Position Error". The EPE is given in cm. This is not the
136
+ # absolute maximum error, it is the error with a specific confidence. See
137
+ # `here <http://www.nps.gov/gis/gps/WhatisEPE.html>`__ for more information.
138
+ #
139
+ # This data is only valid if there is currently a fix as indicated by
140
+ # BrickletGPS#get_status.
141
+ def get_coordinates
142
+ send_request(FUNCTION_GET_COORDINATES, [], '', 18, 'L k L k S S S S')
143
+ end
144
+
145
+ # Returns the current fix status, the number of satellites that are in view and
146
+ # the number of satellites that are currently used.
147
+ #
148
+ # Possible fix status values can be:
149
+ #
150
+ # "Value", "Description"
151
+ #
152
+ # "1", "No Fix"
153
+ # "2", "2D Fix"
154
+ # "3", "3D Fix"
155
+ def get_status
156
+ send_request(FUNCTION_GET_STATUS, [], '', 3, 'C C C')
157
+ end
158
+
159
+ # Returns the current altitude and corresponding geoidal separation.
160
+ #
161
+ # Both values are given in cm.
162
+ #
163
+ # This data is only valid if there is currently a fix as indicated by
164
+ # BrickletGPS#get_status.
165
+ def get_altitude
166
+ send_request(FUNCTION_GET_ALTITUDE, [], '', 8, 'L L')
167
+ end
168
+
169
+ # Returns the current course and speed. Course is given in hundredths degree
170
+ # and speed is given in hundredths km/h. A course of 0° means the Bricklet is
171
+ # traveling north bound and 90° means it is traveling east bound.
172
+ #
173
+ # Please note that this only returns useful values if an actual movement
174
+ # is present.
175
+ #
176
+ # This data is only valid if there is currently a fix as indicated by
177
+ # BrickletGPS#get_status.
178
+ def get_motion
179
+ send_request(FUNCTION_GET_MOTION, [], '', 8, 'L L')
180
+ end
181
+
182
+ # Returns the current date and time. The date is
183
+ # given in the format ddmmyy and the time is given
184
+ # in the format hhmmss.sss. For example, 140713 means
185
+ # 14.05.13 as date and 195923568 means 19:59:23.568 as time.
186
+ def get_date_time
187
+ send_request(FUNCTION_GET_DATE_TIME, [], '', 8, 'L L')
188
+ end
189
+
190
+ # Restarts the GPS Bricklet, the following restart types are available:
191
+ #
192
+ # "Value", "Description"
193
+ #
194
+ # "0", "Hot start (use all available data in the NV store)"
195
+ # "1", "Warm start (don't use ephemeris at restart)"
196
+ # "2", "Cold start (don't use time, position, almanacs and ephemeris at restart)"
197
+ # "3", "Factory reset (clear all system/user configurations at restart)"
198
+ def restart(restart_type)
199
+ send_request(FUNCTION_RESTART, [restart_type], 'C', 0, '')
200
+ end
201
+
202
+ # Sets the period in ms with which the CALLBACK_COORDINATES callback is triggered
203
+ # periodically. A value of 0 turns the callback off.
204
+ #
205
+ # CALLBACK_COORDINATES is only triggered if the coordinates changed since the
206
+ # last triggering.
207
+ #
208
+ # The default value is 0.
209
+ def set_coordinates_callback_period(period)
210
+ send_request(FUNCTION_SET_COORDINATES_CALLBACK_PERIOD, [period], 'L', 0, '')
211
+ end
212
+
213
+ # Returns the period as set by BrickletGPS#set_coordinates_callback_period.
214
+ def get_coordinates_callback_period
215
+ send_request(FUNCTION_GET_COORDINATES_CALLBACK_PERIOD, [], '', 4, 'L')
216
+ end
217
+
218
+ # Sets the period in ms with which the CALLBACK_STATUS callback is triggered
219
+ # periodically. A value of 0 turns the callback off.
220
+ #
221
+ # CALLBACK_STATUS is only triggered if the status changed since the
222
+ # last triggering.
223
+ #
224
+ # The default value is 0.
225
+ def set_status_callback_period(period)
226
+ send_request(FUNCTION_SET_STATUS_CALLBACK_PERIOD, [period], 'L', 0, '')
227
+ end
228
+
229
+ # Returns the period as set by BrickletGPS#set_status_callback_period.
230
+ def get_status_callback_period
231
+ send_request(FUNCTION_GET_STATUS_CALLBACK_PERIOD, [], '', 4, 'L')
232
+ end
233
+
234
+ # Sets the period in ms with which the CALLBACK_ALTITUDE callback is triggered
235
+ # periodically. A value of 0 turns the callback off.
236
+ #
237
+ # CALLBACK_ALTITUDE is only triggered if the altitude changed since the
238
+ # last triggering.
239
+ #
240
+ # The default value is 0.
241
+ def set_altitude_callback_period(period)
242
+ send_request(FUNCTION_SET_ALTITUDE_CALLBACK_PERIOD, [period], 'L', 0, '')
243
+ end
244
+
245
+ # Returns the period as set by BrickletGPS#set_altitude_callback_period.
246
+ def get_altitude_callback_period
247
+ send_request(FUNCTION_GET_ALTITUDE_CALLBACK_PERIOD, [], '', 4, 'L')
248
+ end
249
+
250
+ # Sets the period in ms with which the CALLBACK_DATE_TIME callback is triggered
251
+ # periodically. A value of 0 turns the callback off.
252
+ #
253
+ # CALLBACK_DATE_TIME is only triggered if the date or time changed since the
254
+ # last triggering.
255
+ #
256
+ # The default value is 0.
257
+ def set_date_time_callback_period(period)
258
+ send_request(FUNCTION_SET_DATE_TIME_CALLBACK_PERIOD, [period], 'L', 0, '')
259
+ end
260
+
261
+ # Returns the period as set by BrickletGPS#set_date_time_callback_period.
262
+ def get_date_time_callback_period
263
+ send_request(FUNCTION_GET_DATE_TIME_CALLBACK_PERIOD, [], '', 4, 'L')
264
+ end
265
+
266
+ # Sets the period in ms with which the CALLBACK_MOTION callback is triggered
267
+ # periodically. A value of 0 turns the callback off.
268
+ #
269
+ # CALLBACK_MOTION is only triggered if the motion changed since the
270
+ # last triggering.
271
+ #
272
+ # The default value is 0.
273
+ def set_motion_callback_period(period)
274
+ send_request(FUNCTION_SET_MOTION_CALLBACK_PERIOD, [period], 'L', 0, '')
275
+ end
276
+
277
+ # Returns the period as set by BrickletGPS#set_motion_callback_period.
278
+ def get_motion_callback_period
279
+ send_request(FUNCTION_GET_MOTION_CALLBACK_PERIOD, [], '', 4, 'L')
280
+ end
281
+
282
+ # Returns the UID, the UID where the Bricklet is connected to,
283
+ # the position, the hardware and firmware version as well as the
284
+ # device identifier.
285
+ #
286
+ # The position can be 'a', 'b', 'c' or 'd'.
287
+ #
288
+ # The device identifiers can be found :ref:`here <device_identifier>`.
289
+ #
290
+ # .. versionadded:: 2.0.0~(Plugin)
291
+ def get_identity
292
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
293
+ end
294
+
295
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
296
+ def register_callback(id, &block)
297
+ callback = block
298
+ @registered_callbacks[id] = callback
299
+ end
300
+ end
301
+ end
@@ -0,0 +1,245 @@
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 Humidity
14
+ class BrickletHumidity < Device
15
+ DEVICE_IDENTIFIER = 27 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletHumidity#set_humidity_callback_period. The parameter is the humidity of the
19
+ # sensor.
20
+ #
21
+ # CALLBACK_HUMIDITY is only triggered if the humidity has changed since the
22
+ # last triggering.
23
+ CALLBACK_HUMIDITY = 13
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletHumidity#set_analog_value_callback_period. The parameter is the analog value of the
27
+ # sensor.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the humidity has changed since the
30
+ # last triggering.
31
+ CALLBACK_ANALOG_VALUE = 14
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletHumidity#set_humidity_callback_threshold is reached.
35
+ # The parameter is the humidity of the sensor.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletHumidity#set_debounce_period.
39
+ CALLBACK_HUMIDITY_REACHED = 15
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletHumidity#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 BrickletHumidity#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 16
48
+
49
+ FUNCTION_GET_HUMIDITY = 1 # :nodoc:
50
+ FUNCTION_GET_ANALOG_VALUE = 2 # :nodoc:
51
+ FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD = 3 # :nodoc:
52
+ FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD = 4 # :nodoc:
53
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 5 # :nodoc:
54
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 6 # :nodoc:
55
+ FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD = 7 # :nodoc:
56
+ FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD = 8 # :nodoc:
57
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 9 # :nodoc:
58
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 10 # :nodoc:
59
+ FUNCTION_SET_DEBOUNCE_PERIOD = 11 # :nodoc:
60
+ FUNCTION_GET_DEBOUNCE_PERIOD = 12 # :nodoc:
61
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
62
+
63
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
64
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
65
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
66
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
67
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
68
+
69
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
70
+ # the IP Connection <tt>ipcon</tt>.
71
+ def initialize(uid, ipcon)
72
+ super uid, ipcon
73
+
74
+ @api_version = [2, 0, 0]
75
+
76
+ @response_expected[FUNCTION_GET_HUMIDITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
77
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
78
+ @response_expected[FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
79
+ @response_expected[FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
80
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
81
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
82
+ @response_expected[FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
83
+ @response_expected[FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
84
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
85
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
87
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
88
+ @response_expected[CALLBACK_HUMIDITY] = RESPONSE_EXPECTED_ALWAYS_FALSE
89
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
90
+ @response_expected[CALLBACK_HUMIDITY_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
91
+ @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
92
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
93
+
94
+ @callback_formats[CALLBACK_HUMIDITY] = 'S'
95
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
96
+ @callback_formats[CALLBACK_HUMIDITY_REACHED] = 'S'
97
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
98
+ end
99
+
100
+ # Returns the humidity of the sensor. The value
101
+ # has a range of 0 to 1000 and is given in %RH/10 (Relative Humidity),
102
+ # i.e. a value of 421 means that a humidity of 42.1 %RH is measured.
103
+ #
104
+ # If you want to get the humidity periodically, it is recommended to use the
105
+ # callback CALLBACK_HUMIDITY and set the period with
106
+ # BrickletHumidity#set_humidity_callback_period.
107
+ def get_humidity
108
+ send_request(FUNCTION_GET_HUMIDITY, [], '', 2, 'S')
109
+ end
110
+
111
+ # Returns the value as read by a 12-bit analog-to-digital converter.
112
+ # The value is between 0 and 4095.
113
+ #
114
+ # .. note::
115
+ # The value returned by BrickletHumidity#get_humidity is averaged over several samples
116
+ # to yield less noise, while BrickletHumidity#get_analog_value gives back raw
117
+ # unfiltered analog values. The returned humidity value is calibrated for
118
+ # room temperatures, if you use the sensor in extreme cold or extreme
119
+ # warm environments, you might want to calculate the humidity from
120
+ # the analog value yourself. See the `HIH 5030 datasheet
121
+ # <https://github.com/Tinkerforge/humidity-bricklet/raw/master/datasheets/hih-5030.pdf>`__.
122
+ #
123
+ # If you want the analog value periodically, it is recommended to use the
124
+ # callback CALLBACK_ANALOG_VALUE and set the period with
125
+ # BrickletHumidity#set_analog_value_callback_period.
126
+ def get_analog_value
127
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S')
128
+ end
129
+
130
+ # Sets the period in ms with which the CALLBACK_HUMIDITY callback is triggered
131
+ # periodically. A value of 0 turns the callback off.
132
+ #
133
+ # CALLBACK_HUMIDITY is only triggered if the humidity has changed since the
134
+ # last triggering.
135
+ #
136
+ # The default value is 0.
137
+ def set_humidity_callback_period(period)
138
+ send_request(FUNCTION_SET_HUMIDITY_CALLBACK_PERIOD, [period], 'L', 0, '')
139
+ end
140
+
141
+ # Returns the period as set by BrickletHumidity#set_humidity_callback_period.
142
+ def get_humidity_callback_period
143
+ send_request(FUNCTION_GET_HUMIDITY_CALLBACK_PERIOD, [], '', 4, 'L')
144
+ end
145
+
146
+ # Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered
147
+ # periodically. A value of 0 turns the callback off.
148
+ #
149
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
150
+ # last triggering.
151
+ #
152
+ # The default value is 0.
153
+ def set_analog_value_callback_period(period)
154
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '')
155
+ end
156
+
157
+ # Returns the period as set by BrickletHumidity#set_analog_value_callback_period.
158
+ def get_analog_value_callback_period
159
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L')
160
+ end
161
+
162
+ # Sets the thresholds for the CALLBACK_HUMIDITY_REACHED callback.
163
+ #
164
+ # The following options are possible:
165
+ #
166
+ # "Option", "Description"
167
+ #
168
+ # "'x'", "Callback is turned off"
169
+ # "'o'", "Callback is triggered when the humidity is *outside* the min and max values"
170
+ # "'i'", "Callback is triggered when the humidity is *inside* the min and max values"
171
+ # "'<'", "Callback is triggered when the humidity is smaller than the min value (max is ignored)"
172
+ # "'>'", "Callback is triggered when the humidity is greater than the min value (max is ignored)"
173
+ #
174
+ # The default value is ('x', 0, 0).
175
+ def set_humidity_callback_threshold(option, min, max)
176
+ send_request(FUNCTION_SET_HUMIDITY_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
177
+ end
178
+
179
+ # Returns the threshold as set by BrickletHumidity#set_humidity_callback_threshold.
180
+ def get_humidity_callback_threshold
181
+ send_request(FUNCTION_GET_HUMIDITY_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
182
+ end
183
+
184
+ # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
185
+ #
186
+ # The following options are possible:
187
+ #
188
+ # "Option", "Description"
189
+ #
190
+ # "'x'", "Callback is turned off"
191
+ # "'o'", "Callback is triggered when the analog value is *outside* the min and max values"
192
+ # "'i'", "Callback is triggered when the analog value is *inside* the min and max values"
193
+ # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
194
+ # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
195
+ #
196
+ # The default value is ('x', 0, 0).
197
+ def set_analog_value_callback_threshold(option, min, max)
198
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
199
+ end
200
+
201
+ # Returns the threshold as set by BrickletHumidity#set_analog_value_callback_threshold.
202
+ def get_analog_value_callback_threshold
203
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
204
+ end
205
+
206
+ # Sets the period in ms with which the threshold callbacks
207
+ #
208
+ # CALLBACK_HUMIDITY_REACHED, CALLBACK_ANALOG_VALUE_REACHED
209
+ #
210
+ # are triggered, if the thresholds
211
+ #
212
+ # BrickletHumidity#set_humidity_callback_threshold, BrickletHumidity#set_analog_value_callback_threshold
213
+ #
214
+ # keep being reached.
215
+ #
216
+ # The default value is 100.
217
+ def set_debounce_period(debounce)
218
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
219
+ end
220
+
221
+ # Returns the debounce period as set by BrickletHumidity#set_debounce_period.
222
+ def get_debounce_period
223
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
224
+ end
225
+
226
+ # Returns the UID, the UID where the Bricklet is connected to,
227
+ # the position, the hardware and firmware version as well as the
228
+ # device identifier.
229
+ #
230
+ # The position can be 'a', 'b', 'c' or 'd'.
231
+ #
232
+ # The device identifiers can be found :ref:`here <device_identifier>`.
233
+ #
234
+ # .. versionadded:: 2.0.0~(Plugin)
235
+ def get_identity
236
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
237
+ end
238
+
239
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
240
+ def register_callback(id, &block)
241
+ callback = block
242
+ @registered_callbacks[id] = callback
243
+ end
244
+ end
245
+ end