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,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
+ # Dual-Axis Joystick with Button
14
+ class BrickletJoystick < Device
15
+ DEVICE_IDENTIFIER = 210 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletJoystick#set_position_callback_period. The parameter is the position of the
19
+ # Joystick.
20
+ #
21
+ # CALLBACK_POSITION is only triggered if the position has changed since the
22
+ # last triggering.
23
+ CALLBACK_POSITION = 15
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletJoystick#set_analog_value_callback_period. The parameters are the analog values
27
+ # of the Joystick.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the values have changed since the
30
+ # last triggering.
31
+ CALLBACK_ANALOG_VALUE = 16
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletJoystick#set_position_callback_threshold is reached.
35
+ # The parameters are the position of the Joystick.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletJoystick#set_debounce_period.
39
+ CALLBACK_POSITION_REACHED = 17
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletJoystick#set_analog_value_callback_threshold is reached.
43
+ # The parameters are the analog values of the Joystick.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletJoystick#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 18
48
+
49
+ # This callback is triggered when the button is pressed.
50
+ CALLBACK_PRESSED = 19
51
+
52
+ # This callback is triggered when the button is released.
53
+ CALLBACK_RELEASED = 20
54
+
55
+ FUNCTION_GET_POSITION = 1 # :nodoc:
56
+ FUNCTION_IS_PRESSED = 2 # :nodoc:
57
+ FUNCTION_GET_ANALOG_VALUE = 3 # :nodoc:
58
+ FUNCTION_CALIBRATE = 4 # :nodoc:
59
+ FUNCTION_SET_POSITION_CALLBACK_PERIOD = 5 # :nodoc:
60
+ FUNCTION_GET_POSITION_CALLBACK_PERIOD = 6 # :nodoc:
61
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 7 # :nodoc:
62
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 8 # :nodoc:
63
+ FUNCTION_SET_POSITION_CALLBACK_THRESHOLD = 9 # :nodoc:
64
+ FUNCTION_GET_POSITION_CALLBACK_THRESHOLD = 10 # :nodoc:
65
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 11 # :nodoc:
66
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 12 # :nodoc:
67
+ FUNCTION_SET_DEBOUNCE_PERIOD = 13 # :nodoc:
68
+ FUNCTION_GET_DEBOUNCE_PERIOD = 14 # :nodoc:
69
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
70
+
71
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
72
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
73
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
74
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
75
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
76
+
77
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
78
+ # the IP Connection <tt>ipcon</tt>.
79
+ def initialize(uid, ipcon)
80
+ super uid, ipcon
81
+
82
+ @api_version = [2, 0, 0]
83
+
84
+ @response_expected[FUNCTION_GET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
85
+ @response_expected[FUNCTION_IS_PRESSED] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
87
+ @response_expected[FUNCTION_CALIBRATE] = RESPONSE_EXPECTED_FALSE
88
+ @response_expected[FUNCTION_SET_POSITION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
89
+ @response_expected[FUNCTION_GET_POSITION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
90
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
91
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
92
+ @response_expected[FUNCTION_SET_POSITION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
93
+ @response_expected[FUNCTION_GET_POSITION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
94
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
95
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
96
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
97
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
98
+ @response_expected[CALLBACK_POSITION] = RESPONSE_EXPECTED_ALWAYS_FALSE
99
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
100
+ @response_expected[CALLBACK_POSITION_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
101
+ @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
102
+ @response_expected[CALLBACK_PRESSED] = RESPONSE_EXPECTED_ALWAYS_FALSE
103
+ @response_expected[CALLBACK_RELEASED] = RESPONSE_EXPECTED_ALWAYS_FALSE
104
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
105
+
106
+ @callback_formats[CALLBACK_POSITION] = 's s'
107
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S S'
108
+ @callback_formats[CALLBACK_POSITION_REACHED] = 's s'
109
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S S'
110
+ @callback_formats[CALLBACK_PRESSED] = ''
111
+ @callback_formats[CALLBACK_RELEASED] = ''
112
+ end
113
+
114
+ # Returns the position of the Joystick. The value ranges between -100 and
115
+ # 100 for both axis. The middle position of the joystick is x=0, y=0. The
116
+ # returned values are averaged and calibrated (see BrickletJoystick#calibrate).
117
+ #
118
+ # If you want to get the position periodically, it is recommended to use the
119
+ # callback CALLBACK_POSITION and set the period with
120
+ # BrickletJoystick#set_position_callback_period.
121
+ def get_position
122
+ send_request(FUNCTION_GET_POSITION, [], '', 4, 's s')
123
+ end
124
+
125
+ # Returns *true* if the button is pressed and *false* otherwise.
126
+ #
127
+ # It is recommended to use the CALLBACK_PRESSED and CALLBACK_RELEASED callbacks
128
+ # to handle the button.
129
+ def is_pressed
130
+ send_request(FUNCTION_IS_PRESSED, [], '', 1, '?')
131
+ end
132
+
133
+ # Returns the values as read by a 12-bit analog-to-digital converter.
134
+ # The values are between 0 and 4095 for both axis.
135
+ #
136
+ # .. note::
137
+ # The values returned by BrickletJoystick#get_position are averaged over several samples
138
+ # to yield less noise, while BrickletJoystick#get_analog_value gives back raw
139
+ # unfiltered analog values. The only reason to use BrickletJoystick#get_analog_value is,
140
+ # if you need the full resolution of the analog-to-digital converter.
141
+ #
142
+ # If you want the analog values periodically, it is recommended to use the
143
+ # callback CALLBACK_ANALOG_VALUE and set the period with
144
+ # BrickletJoystick#set_analog_value_callback_period.
145
+ def get_analog_value
146
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 4, 'S S')
147
+ end
148
+
149
+ # Calibrates the middle position of the Joystick. If your Joystick Bricklet
150
+ # does not return x=0 and y=0 in the middle position, call this function
151
+ # while the Joystick is standing still in the middle position.
152
+ #
153
+ # The resulting calibration will be saved on the EEPROM of the Joystick
154
+ # Bricklet, thus you only have to calibrate it once.
155
+ def calibrate
156
+ send_request(FUNCTION_CALIBRATE, [], '', 0, '')
157
+ end
158
+
159
+ # Sets the period in ms with which the CALLBACK_POSITION callback is triggered
160
+ # periodically. A value of 0 turns the callback off.
161
+ #
162
+ # CALLBACK_POSITION is only triggered if the position has changed since the
163
+ # last triggering.
164
+ #
165
+ # The default value is 0.
166
+ def set_position_callback_period(period)
167
+ send_request(FUNCTION_SET_POSITION_CALLBACK_PERIOD, [period], 'L', 0, '')
168
+ end
169
+
170
+ # Returns the period as set by BrickletJoystick#set_position_callback_period.
171
+ def get_position_callback_period
172
+ send_request(FUNCTION_GET_POSITION_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 values have 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 BrickletJoystick#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_POSITION_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 position is *outside* the min and max values"
199
+ # "'i'", "Callback is triggered when the position is *inside* the min and max values"
200
+ # "'<'", "Callback is triggered when the position is smaller than the min values (max is ignored)"
201
+ # "'>'", "Callback is triggered when the position is greater than the min values (max is ignored)"
202
+ #
203
+ # The default value is ('x', 0, 0, 0, 0).
204
+ def set_position_callback_threshold(option, min_x, max_x, min_y, max_y)
205
+ send_request(FUNCTION_SET_POSITION_CALLBACK_THRESHOLD, [option, min_x, max_x, min_y, max_y], 'k s s s s', 0, '')
206
+ end
207
+
208
+ # Returns the threshold as set by BrickletJoystick#set_position_callback_threshold.
209
+ def get_position_callback_threshold
210
+ send_request(FUNCTION_GET_POSITION_CALLBACK_THRESHOLD, [], '', 9, 'k s s 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 values are *outside* the min and max values"
221
+ # "'i'", "Callback is triggered when the analog values are *inside* the min and max values"
222
+ # "'<'", "Callback is triggered when the analog values are smaller than the min values (max is ignored)"
223
+ # "'>'", "Callback is triggered when the analog values are greater than the min values (max is ignored)"
224
+ #
225
+ # The default value is ('x', 0, 0, 0, 0).
226
+ def set_analog_value_callback_threshold(option, min_x, max_x, min_y, max_y)
227
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min_x, max_x, min_y, max_y], 'k S S S S', 0, '')
228
+ end
229
+
230
+ # Returns the threshold as set by BrickletJoystick#set_analog_value_callback_threshold.
231
+ def get_analog_value_callback_threshold
232
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 9, 'k S S S S')
233
+ end
234
+
235
+ # Sets the period in ms with which the threshold callbacks
236
+ #
237
+ # CALLBACK_POSITION_REACHED, CALLBACK_ANALOG_VALUE_REACHED
238
+ #
239
+ # are triggered, if the thresholds
240
+ #
241
+ # BrickletJoystick#set_position_callback_threshold, BrickletJoystick#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 BrickletJoystick#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
@@ -0,0 +1,175 @@
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 a LCD with 2 lines a 16 characters
14
+ class BrickletLCD16x2 < Device
15
+ DEVICE_IDENTIFIER = 211 # :nodoc:
16
+
17
+ # This callback is triggered when a button is pressed. The parameter is
18
+ # the number of the button (0 to 2).
19
+ CALLBACK_BUTTON_PRESSED = 9
20
+
21
+ # This callback is triggered when a button is released. The parameter is
22
+ # the number of the button (0 to 2).
23
+ CALLBACK_BUTTON_RELEASED = 10
24
+
25
+ FUNCTION_WRITE_LINE = 1 # :nodoc:
26
+ FUNCTION_CLEAR_DISPLAY = 2 # :nodoc:
27
+ FUNCTION_BACKLIGHT_ON = 3 # :nodoc:
28
+ FUNCTION_BACKLIGHT_OFF = 4 # :nodoc:
29
+ FUNCTION_IS_BACKLIGHT_ON = 5 # :nodoc:
30
+ FUNCTION_SET_CONFIG = 6 # :nodoc:
31
+ FUNCTION_GET_CONFIG = 7 # :nodoc:
32
+ FUNCTION_IS_BUTTON_PRESSED = 8 # :nodoc:
33
+ FUNCTION_SET_CUSTOM_CHARACTER = 11 # :nodoc:
34
+ FUNCTION_GET_CUSTOM_CHARACTER = 12 # :nodoc:
35
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
36
+
37
+
38
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
39
+ # the IP Connection <tt>ipcon</tt>.
40
+ def initialize(uid, ipcon)
41
+ super uid, ipcon
42
+
43
+ @api_version = [2, 0, 0]
44
+
45
+ @response_expected[FUNCTION_WRITE_LINE] = RESPONSE_EXPECTED_FALSE
46
+ @response_expected[FUNCTION_CLEAR_DISPLAY] = RESPONSE_EXPECTED_FALSE
47
+ @response_expected[FUNCTION_BACKLIGHT_ON] = RESPONSE_EXPECTED_FALSE
48
+ @response_expected[FUNCTION_BACKLIGHT_OFF] = RESPONSE_EXPECTED_FALSE
49
+ @response_expected[FUNCTION_IS_BACKLIGHT_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
50
+ @response_expected[FUNCTION_SET_CONFIG] = RESPONSE_EXPECTED_FALSE
51
+ @response_expected[FUNCTION_GET_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
52
+ @response_expected[FUNCTION_IS_BUTTON_PRESSED] = RESPONSE_EXPECTED_ALWAYS_TRUE
53
+ @response_expected[CALLBACK_BUTTON_PRESSED] = RESPONSE_EXPECTED_ALWAYS_FALSE
54
+ @response_expected[CALLBACK_BUTTON_RELEASED] = RESPONSE_EXPECTED_ALWAYS_FALSE
55
+ @response_expected[FUNCTION_SET_CUSTOM_CHARACTER] = RESPONSE_EXPECTED_FALSE
56
+ @response_expected[FUNCTION_GET_CUSTOM_CHARACTER] = RESPONSE_EXPECTED_ALWAYS_TRUE
57
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
58
+
59
+ @callback_formats[CALLBACK_BUTTON_PRESSED] = 'C'
60
+ @callback_formats[CALLBACK_BUTTON_RELEASED] = 'C'
61
+ end
62
+
63
+ # Writes text to a specific line (0 to 1) with a specific position
64
+ # (0 to 15). The text can have a maximum of 16 characters.
65
+ #
66
+ # For example: (0, 5, "Hello") will write *Hello* in the middle of the
67
+ # first line of the display.
68
+ #
69
+ # The display uses a special charset that includes all ASCII characters except
70
+ # backslash and tilde. The LCD charset also includes several other non-ASCII characters, see
71
+ # the `charset specification <https://github.com/Tinkerforge/lcd-16x2-bricklet/raw/master/datasheets/standard_charset.pdf>`__
72
+ # for details. The Unicode example above shows how to specify non-ASCII characters
73
+ # and how to translate from Unicode to the LCD charset.
74
+ def write_line(line, position, text)
75
+ send_request(FUNCTION_WRITE_LINE, [line, position, text], 'C C Z16', 0, '')
76
+ end
77
+
78
+ # Deletes all characters from the display.
79
+ def clear_display
80
+ send_request(FUNCTION_CLEAR_DISPLAY, [], '', 0, '')
81
+ end
82
+
83
+ # Turns the backlight on.
84
+ def backlight_on
85
+ send_request(FUNCTION_BACKLIGHT_ON, [], '', 0, '')
86
+ end
87
+
88
+ # Turns the backlight off.
89
+ def backlight_off
90
+ send_request(FUNCTION_BACKLIGHT_OFF, [], '', 0, '')
91
+ end
92
+
93
+ # Returns *true* if the backlight is on and *false* otherwise.
94
+ def is_backlight_on
95
+ send_request(FUNCTION_IS_BACKLIGHT_ON, [], '', 1, '?')
96
+ end
97
+
98
+ # Configures if the cursor (shown as "_") should be visible and if it
99
+ # should be blinking (shown as a blinking block). The cursor position
100
+ # is one character behind the the last text written with
101
+ # BrickletLCD16x2#write_line.
102
+ #
103
+ # The default is (false, false).
104
+ def set_config(cursor, blinking)
105
+ send_request(FUNCTION_SET_CONFIG, [cursor, blinking], '? ?', 0, '')
106
+ end
107
+
108
+ # Returns the configuration as set by BrickletLCD16x2#set_config.
109
+ def get_config
110
+ send_request(FUNCTION_GET_CONFIG, [], '', 2, '? ?')
111
+ end
112
+
113
+ # Returns *true* if the button (0 to 2) is pressed. If you want to react
114
+ # on button presses and releases it is recommended to use the
115
+ # CALLBACK_BUTTON_PRESSED and CALLBACK_BUTTON_RELEASED callbacks.
116
+ def is_button_pressed(button)
117
+ send_request(FUNCTION_IS_BUTTON_PRESSED, [button], 'C', 1, '?')
118
+ end
119
+
120
+ # The LCD 16x2 Bricklet can store up to 8 custom characters. The characters
121
+ # consist of 5x8 pixels and can be addressed with the index 0-7. To describe
122
+ # the pixels, the first 5 bits of 8 bytes are used. For example, to make
123
+ # a custom character "H", you should transfer the following:
124
+ #
125
+ # * character[0] = 0b00010001 (decimal value 17)
126
+ # * character[1] = 0b00010001 (decimal value 17)
127
+ # * character[2] = 0b00010001 (decimal value 17)
128
+ # * character[3] = 0b00011111 (decimal value 31)
129
+ # * character[4] = 0b00010001 (decimal value 17)
130
+ # * character[5] = 0b00010001 (decimal value 17)
131
+ # * character[6] = 0b00010001 (decimal value 17)
132
+ # * character[7] = 0b00000000 (decimal value 0)
133
+ #
134
+ # The characters can later be written with BrickletLCD16x2#write_line by using the
135
+ # characters with the byte representation 8 to 15.
136
+ #
137
+ # You can play around with the custom characters in Brick Viewer version
138
+ # >= 2.0.1.
139
+ #
140
+ # Custom characters are stored by the LCD in RAM, so they have to be set
141
+ # after each startup.
142
+ #
143
+ # .. versionadded:: 2.0.1~(Plugin)
144
+ def set_custom_character(index, character)
145
+ send_request(FUNCTION_SET_CUSTOM_CHARACTER, [index, character], 'C C8', 0, '')
146
+ end
147
+
148
+ # Returns the custom character for a given index, as set with
149
+ # BrickletLCD16x2#set_custom_character.
150
+ #
151
+ # .. versionadded:: 2.0.1~(Plugin)
152
+ def get_custom_character(index)
153
+ send_request(FUNCTION_GET_CUSTOM_CHARACTER, [index], 'C', 8, 'C8')
154
+ end
155
+
156
+ # Returns the UID, the UID where the Bricklet is connected to,
157
+ # the position, the hardware and firmware version as well as the
158
+ # device identifier.
159
+ #
160
+ # The position can be 'a', 'b', 'c' or 'd'.
161
+ #
162
+ # The device identifiers can be found :ref:`here <device_identifier>`.
163
+ #
164
+ # .. versionadded:: 2.0.0~(Plugin)
165
+ def get_identity
166
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
167
+ end
168
+
169
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
170
+ def register_callback(id, &block)
171
+ callback = block
172
+ @registered_callbacks[id] = callback
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,231 @@
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 a LCD with 4 lines a 20 characters
14
+ class BrickletLCD20x4 < Device
15
+ DEVICE_IDENTIFIER = 212 # :nodoc:
16
+
17
+ # This callback is triggered when a button is pressed. The parameter is
18
+ # the number of the button (0 to 2 or 0 to 3 with hardware version >= 1.2).
19
+ CALLBACK_BUTTON_PRESSED = 9
20
+
21
+ # This callback is triggered when a button is released. The parameter is
22
+ # the number of the button (0 to 2 or 0 to 3 with hardware version >= 1.2).
23
+ CALLBACK_BUTTON_RELEASED = 10
24
+
25
+ FUNCTION_WRITE_LINE = 1 # :nodoc:
26
+ FUNCTION_CLEAR_DISPLAY = 2 # :nodoc:
27
+ FUNCTION_BACKLIGHT_ON = 3 # :nodoc:
28
+ FUNCTION_BACKLIGHT_OFF = 4 # :nodoc:
29
+ FUNCTION_IS_BACKLIGHT_ON = 5 # :nodoc:
30
+ FUNCTION_SET_CONFIG = 6 # :nodoc:
31
+ FUNCTION_GET_CONFIG = 7 # :nodoc:
32
+ FUNCTION_IS_BUTTON_PRESSED = 8 # :nodoc:
33
+ FUNCTION_SET_CUSTOM_CHARACTER = 11 # :nodoc:
34
+ FUNCTION_GET_CUSTOM_CHARACTER = 12 # :nodoc:
35
+ FUNCTION_SET_DEFAULT_TEXT = 13 # :nodoc:
36
+ FUNCTION_GET_DEFAULT_TEXT = 14 # :nodoc:
37
+ FUNCTION_SET_DEFAULT_TEXT_COUNTER = 15 # :nodoc:
38
+ FUNCTION_GET_DEFAULT_TEXT_COUNTER = 16 # :nodoc:
39
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
40
+
41
+
42
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
43
+ # the IP Connection <tt>ipcon</tt>.
44
+ def initialize(uid, ipcon)
45
+ super uid, ipcon
46
+
47
+ @api_version = [2, 0, 0]
48
+
49
+ @response_expected[FUNCTION_WRITE_LINE] = RESPONSE_EXPECTED_FALSE
50
+ @response_expected[FUNCTION_CLEAR_DISPLAY] = RESPONSE_EXPECTED_FALSE
51
+ @response_expected[FUNCTION_BACKLIGHT_ON] = RESPONSE_EXPECTED_FALSE
52
+ @response_expected[FUNCTION_BACKLIGHT_OFF] = RESPONSE_EXPECTED_FALSE
53
+ @response_expected[FUNCTION_IS_BACKLIGHT_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
54
+ @response_expected[FUNCTION_SET_CONFIG] = RESPONSE_EXPECTED_FALSE
55
+ @response_expected[FUNCTION_GET_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
56
+ @response_expected[FUNCTION_IS_BUTTON_PRESSED] = RESPONSE_EXPECTED_ALWAYS_TRUE
57
+ @response_expected[CALLBACK_BUTTON_PRESSED] = RESPONSE_EXPECTED_ALWAYS_FALSE
58
+ @response_expected[CALLBACK_BUTTON_RELEASED] = RESPONSE_EXPECTED_ALWAYS_FALSE
59
+ @response_expected[FUNCTION_SET_CUSTOM_CHARACTER] = RESPONSE_EXPECTED_FALSE
60
+ @response_expected[FUNCTION_GET_CUSTOM_CHARACTER] = RESPONSE_EXPECTED_ALWAYS_TRUE
61
+ @response_expected[FUNCTION_SET_DEFAULT_TEXT] = RESPONSE_EXPECTED_FALSE
62
+ @response_expected[FUNCTION_GET_DEFAULT_TEXT] = RESPONSE_EXPECTED_ALWAYS_TRUE
63
+ @response_expected[FUNCTION_SET_DEFAULT_TEXT_COUNTER] = RESPONSE_EXPECTED_FALSE
64
+ @response_expected[FUNCTION_GET_DEFAULT_TEXT_COUNTER] = RESPONSE_EXPECTED_ALWAYS_TRUE
65
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
66
+
67
+ @callback_formats[CALLBACK_BUTTON_PRESSED] = 'C'
68
+ @callback_formats[CALLBACK_BUTTON_RELEASED] = 'C'
69
+ end
70
+
71
+ # Writes text to a specific line (0 to 3) with a specific position
72
+ # (0 to 19). The text can have a maximum of 20 characters.
73
+ #
74
+ # For example: (0, 7, "Hello") will write *Hello* in the middle of the
75
+ # first line of the display.
76
+ #
77
+ # The display uses a special charset that includes all ASCII characters except
78
+ # backslash and tilde. The LCD charset also includes several other non-ASCII characters, see
79
+ # the `charset specification <https://github.com/Tinkerforge/lcd-20x4-bricklet/raw/master/datasheets/standard_charset.pdf>`__
80
+ # for details. The Unicode example above shows how to specify non-ASCII characters
81
+ # and how to translate from Unicode to the LCD charset.
82
+ def write_line(line, position, text)
83
+ send_request(FUNCTION_WRITE_LINE, [line, position, text], 'C C Z20', 0, '')
84
+ end
85
+
86
+ # Deletes all characters from the display.
87
+ def clear_display
88
+ send_request(FUNCTION_CLEAR_DISPLAY, [], '', 0, '')
89
+ end
90
+
91
+ # Turns the backlight on.
92
+ def backlight_on
93
+ send_request(FUNCTION_BACKLIGHT_ON, [], '', 0, '')
94
+ end
95
+
96
+ # Turns the backlight off.
97
+ def backlight_off
98
+ send_request(FUNCTION_BACKLIGHT_OFF, [], '', 0, '')
99
+ end
100
+
101
+ # Returns *true* if the backlight is on and *false* otherwise.
102
+ def is_backlight_on
103
+ send_request(FUNCTION_IS_BACKLIGHT_ON, [], '', 1, '?')
104
+ end
105
+
106
+ # Configures if the cursor (shown as "_") should be visible and if it
107
+ # should be blinking (shown as a blinking block). The cursor position
108
+ # is one character behind the the last text written with
109
+ # BrickletLCD20x4#write_line.
110
+ #
111
+ # The default is (false, false).
112
+ def set_config(cursor, blinking)
113
+ send_request(FUNCTION_SET_CONFIG, [cursor, blinking], '? ?', 0, '')
114
+ end
115
+
116
+ # Returns the configuration as set by BrickletLCD20x4#set_config.
117
+ def get_config
118
+ send_request(FUNCTION_GET_CONFIG, [], '', 2, '? ?')
119
+ end
120
+
121
+ # Returns *true* if the button (0 to 2 or 0 to 3 with hardware version >= 1.2)
122
+ # is pressed. If you want to react
123
+ # on button presses and releases it is recommended to use the
124
+ # CALLBACK_BUTTON_PRESSED and CALLBACK_BUTTON_RELEASED callbacks.
125
+ def is_button_pressed(button)
126
+ send_request(FUNCTION_IS_BUTTON_PRESSED, [button], 'C', 1, '?')
127
+ end
128
+
129
+ # The LCD 20x4 Bricklet can store up to 8 custom characters. The characters
130
+ # consist of 5x8 pixels and can be addressed with the index 0-7. To describe
131
+ # the pixels, the first 5 bits of 8 bytes are used. For example, to make
132
+ # a custom character "H", you should transfer the following:
133
+ #
134
+ # * character[0] = 0b00010001 (decimal value 17)
135
+ # * character[1] = 0b00010001 (decimal value 17)
136
+ # * character[2] = 0b00010001 (decimal value 17)
137
+ # * character[3] = 0b00011111 (decimal value 31)
138
+ # * character[4] = 0b00010001 (decimal value 17)
139
+ # * character[5] = 0b00010001 (decimal value 17)
140
+ # * character[6] = 0b00010001 (decimal value 17)
141
+ # * character[7] = 0b00000000 (decimal value 0)
142
+ #
143
+ # The characters can later be written with BrickletLCD20x4#write_line by using the
144
+ # characters with the byte representation 8 to 15.
145
+ #
146
+ # You can play around with the custom characters in Brick Viewer version
147
+ # >= 2.0.1.
148
+ #
149
+ # Custom characters are stored by the LCD in RAM, so they have to be set
150
+ # after each startup.
151
+ #
152
+ # .. versionadded:: 2.0.1~(Plugin)
153
+ def set_custom_character(index, character)
154
+ send_request(FUNCTION_SET_CUSTOM_CHARACTER, [index, character], 'C C8', 0, '')
155
+ end
156
+
157
+ # Returns the custom character for a given index, as set with
158
+ # BrickletLCD20x4#set_custom_character.
159
+ #
160
+ # .. versionadded:: 2.0.1~(Plugin)
161
+ def get_custom_character(index)
162
+ send_request(FUNCTION_GET_CUSTOM_CHARACTER, [index], 'C', 8, 'C8')
163
+ end
164
+
165
+ # Sets the default text for lines 0-3. The max number of characters
166
+ # per line is 20.
167
+ #
168
+ # The default text is shown on the LCD, if the default text counter
169
+ # expires, see BrickletLCD20x4#set_default_text_counter.
170
+ #
171
+ # .. versionadded:: 2.0.2~(Plugin)
172
+ def set_default_text(line, text)
173
+ send_request(FUNCTION_SET_DEFAULT_TEXT, [line, text], 'C Z20', 0, '')
174
+ end
175
+
176
+ # Returns the default text for a given line (0-3) as set by
177
+ # BrickletLCD20x4#set_default_text.
178
+ #
179
+ # .. versionadded:: 2.0.2~(Plugin)
180
+ def get_default_text(line)
181
+ send_request(FUNCTION_GET_DEFAULT_TEXT, [line], 'C', 20, 'Z20')
182
+ end
183
+
184
+ # Sets the default text counter in ms. This counter is decremented each
185
+ # ms by the LCD firmware. If the counter reaches 0, the default text
186
+ # (see BrickletLCD20x4#set_default_text) is shown on the LCD.
187
+ #
188
+ # This functionality can be used to show a default text if the controlling
189
+ # program crashes or the connection is interrupted.
190
+ #
191
+ # A possible approach is to call BrickletLCD20x4#set_default_text_counter every
192
+ # minute with the parameter 1000*60*2 (2 minutes). In this case the
193
+ # default text will be shown no later than 2 minutes after the
194
+ # controlling program crashes.
195
+ #
196
+ # A negative counter turns the default text functionality off.
197
+ #
198
+ # The default is -1.
199
+ #
200
+ # .. versionadded:: 2.0.2~(Plugin)
201
+ def set_default_text_counter(counter)
202
+ send_request(FUNCTION_SET_DEFAULT_TEXT_COUNTER, [counter], 'l', 0, '')
203
+ end
204
+
205
+ # Returns the current value of the default text counter.
206
+ #
207
+ # .. versionadded:: 2.0.2~(Plugin)
208
+ def get_default_text_counter
209
+ send_request(FUNCTION_GET_DEFAULT_TEXT_COUNTER, [], '', 4, 'l')
210
+ end
211
+
212
+ # Returns the UID, the UID where the Bricklet is connected to,
213
+ # the position, the hardware and firmware version as well as the
214
+ # device identifier.
215
+ #
216
+ # The position can be 'a', 'b', 'c' or 'd'.
217
+ #
218
+ # The device identifiers can be found :ref:`here <device_identifier>`.
219
+ #
220
+ # .. versionadded:: 2.0.0~(Plugin)
221
+ def get_identity
222
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
223
+ end
224
+
225
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
226
+ def register_callback(id, &block)
227
+ callback = block
228
+ @registered_callbacks[id] = callback
229
+ end
230
+ end
231
+ end