tinkerforge 2.0.11 → 2.0.12
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.
- data/lib/tinkerforge/brick_dc.rb +2 -2
- data/lib/tinkerforge/brick_imu.rb +2 -2
- data/lib/tinkerforge/brick_master.rb +2 -2
- data/lib/tinkerforge/brick_servo.rb +3 -3
- data/lib/tinkerforge/brick_stepper.rb +2 -2
- data/lib/tinkerforge/bricklet_ambient_light.rb +2 -2
- data/lib/tinkerforge/bricklet_analog_in.rb +2 -2
- data/lib/tinkerforge/bricklet_analog_out.rb +2 -2
- data/lib/tinkerforge/bricklet_barometer.rb +2 -2
- data/lib/tinkerforge/bricklet_current12.rb +2 -2
- data/lib/tinkerforge/bricklet_current25.rb +2 -2
- data/lib/tinkerforge/bricklet_distance_ir.rb +2 -2
- data/lib/tinkerforge/bricklet_distance_us.rb +183 -0
- data/lib/tinkerforge/bricklet_dual_button.rb +123 -0
- data/lib/tinkerforge/bricklet_dual_relay.rb +2 -2
- data/lib/tinkerforge/bricklet_gps.rb +2 -2
- data/lib/tinkerforge/bricklet_hall_effect.rb +163 -0
- data/lib/tinkerforge/bricklet_humidity.rb +2 -2
- data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +3 -3
- data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +2 -2
- data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +2 -2
- data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +2 -2
- data/lib/tinkerforge/bricklet_io16.rb +2 -2
- data/lib/tinkerforge/bricklet_io4.rb +2 -2
- data/lib/tinkerforge/bricklet_joystick.rb +2 -2
- data/lib/tinkerforge/bricklet_lcd_16x2.rb +2 -2
- data/lib/tinkerforge/bricklet_lcd_20x4.rb +2 -2
- data/lib/tinkerforge/bricklet_led_strip.rb +134 -0
- data/lib/tinkerforge/bricklet_line.rb +160 -0
- data/lib/tinkerforge/bricklet_linear_poti.rb +2 -2
- data/lib/tinkerforge/bricklet_moisture.rb +180 -0
- data/lib/tinkerforge/bricklet_motion_detector.rb +73 -0
- data/lib/tinkerforge/bricklet_multi_touch.rb +143 -0
- data/lib/tinkerforge/bricklet_piezo_buzzer.rb +2 -2
- data/lib/tinkerforge/bricklet_piezo_speaker.rb +107 -0
- data/lib/tinkerforge/bricklet_ptc.rb +2 -2
- data/lib/tinkerforge/bricklet_remote_switch.rb +104 -0
- data/lib/tinkerforge/bricklet_rotary_encoder.rb +179 -0
- data/lib/tinkerforge/bricklet_rotary_poti.rb +2 -2
- data/lib/tinkerforge/bricklet_segment_display_4x7.rb +110 -0
- data/lib/tinkerforge/bricklet_sound_intensity.rb +160 -0
- data/lib/tinkerforge/bricklet_temperature.rb +2 -2
- data/lib/tinkerforge/bricklet_temperature_ir.rb +2 -2
- data/lib/tinkerforge/bricklet_tilt.rb +99 -0
- data/lib/tinkerforge/bricklet_voltage.rb +2 -2
- data/lib/tinkerforge/bricklet_voltage_current.rb +3 -3
- data/lib/tinkerforge/version.rb +1 -1
- metadata +16 -2
data/lib/tinkerforge/brick_dc.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -212,7 +212,7 @@ module Tinkerforge
|
|
212
212
|
end
|
213
213
|
|
214
214
|
# Sets the output voltages with which the servos are driven in mV.
|
215
|
-
# The minimum output voltage is
|
215
|
+
# The minimum output voltage is 2000mV and the maximum output voltage is
|
216
216
|
# 9000mV.
|
217
217
|
#
|
218
218
|
# .. note::
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
2
2
|
#############################################################
|
3
|
-
# This file was automatically generated on 2013-
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
4
|
# #
|
5
|
-
# Bindings Version 2.0.
|
5
|
+
# Bindings Version 2.0.12 #
|
6
6
|
# #
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
#############################################################
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
|
+
# #
|
5
|
+
# Bindings Version 2.0.12 #
|
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 distance via ultrasound
|
14
|
+
class BrickletDistanceUS < Device
|
15
|
+
DEVICE_IDENTIFIER = 229 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered periodically with the period that is set by
|
18
|
+
# BrickletDistanceUS#set_distance_callback_period. The parameter is the distance value
|
19
|
+
# of the sensor.
|
20
|
+
#
|
21
|
+
# CALLBACK_DISTANCE is only triggered if the distance value has changed since the
|
22
|
+
# last triggering.
|
23
|
+
CALLBACK_DISTANCE = 8
|
24
|
+
|
25
|
+
# This callback is triggered when the threshold as set by
|
26
|
+
# BrickletDistanceUS#set_distance_callback_threshold is reached.
|
27
|
+
# The parameter is the distance value of the sensor.
|
28
|
+
#
|
29
|
+
# If the threshold keeps being reached, the callback is triggered periodically
|
30
|
+
# with the period as set by BrickletDistanceUS#set_debounce_period.
|
31
|
+
CALLBACK_DISTANCE_REACHED = 9
|
32
|
+
|
33
|
+
FUNCTION_GET_DISTANCE_VALUE = 1 # :nodoc:
|
34
|
+
FUNCTION_SET_DISTANCE_CALLBACK_PERIOD = 2 # :nodoc:
|
35
|
+
FUNCTION_GET_DISTANCE_CALLBACK_PERIOD = 3 # :nodoc:
|
36
|
+
FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD = 4 # :nodoc:
|
37
|
+
FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD = 5 # :nodoc:
|
38
|
+
FUNCTION_SET_DEBOUNCE_PERIOD = 6 # :nodoc:
|
39
|
+
FUNCTION_GET_DEBOUNCE_PERIOD = 7 # :nodoc:
|
40
|
+
FUNCTION_SET_MOVING_AVERAGE = 10 # :nodoc:
|
41
|
+
FUNCTION_GET_MOVING_AVERAGE = 11 # :nodoc:
|
42
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
43
|
+
|
44
|
+
THRESHOLD_OPTION_OFF = 'x' # :nodoc:
|
45
|
+
THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
|
46
|
+
THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
|
47
|
+
THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
|
48
|
+
THRESHOLD_OPTION_GREATER = '>' # :nodoc:
|
49
|
+
|
50
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
51
|
+
# the IP Connection <tt>ipcon</tt>.
|
52
|
+
def initialize(uid, ipcon)
|
53
|
+
super uid, ipcon
|
54
|
+
|
55
|
+
@api_version = [2, 0, 0]
|
56
|
+
|
57
|
+
@response_expected[FUNCTION_GET_DISTANCE_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
58
|
+
@response_expected[FUNCTION_SET_DISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
|
59
|
+
@response_expected[FUNCTION_GET_DISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
60
|
+
@response_expected[FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
|
61
|
+
@response_expected[FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
62
|
+
@response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
|
63
|
+
@response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
64
|
+
@response_expected[CALLBACK_DISTANCE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
65
|
+
@response_expected[CALLBACK_DISTANCE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
66
|
+
@response_expected[FUNCTION_SET_MOVING_AVERAGE] = RESPONSE_EXPECTED_FALSE
|
67
|
+
@response_expected[FUNCTION_GET_MOVING_AVERAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
68
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
69
|
+
|
70
|
+
@callback_formats[CALLBACK_DISTANCE] = 'S'
|
71
|
+
@callback_formats[CALLBACK_DISTANCE_REACHED] = 'S'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns the current distance value measured by the sensor. The value has a
|
75
|
+
# range of 0 to 4095. A small value corresponds to a small distance, a big
|
76
|
+
# value corresponds to a big distance. The relation between the measured distance
|
77
|
+
# value and the actual distance is affected by the 5V supply voltage (deviations
|
78
|
+
# in the supply voltage result in deviations in the distance values) and is
|
79
|
+
# non-linear (resolution is bigger at close range).
|
80
|
+
#
|
81
|
+
# If you want to get the distance value periodically, it is recommended to
|
82
|
+
# use the callback CALLBACK_DISTANCE and set the period with
|
83
|
+
# BrickletDistanceUS#set_distance_callback_period.
|
84
|
+
def get_distance_value
|
85
|
+
send_request(FUNCTION_GET_DISTANCE_VALUE, [], '', 2, 'S')
|
86
|
+
end
|
87
|
+
|
88
|
+
# Sets the period in ms with which the CALLBACK_DISTANCE callback is triggered
|
89
|
+
# periodically. A value of 0 turns the callback off.
|
90
|
+
#
|
91
|
+
# CALLBACK_DISTANCE is only triggered if the distance value has changed since the
|
92
|
+
# last triggering.
|
93
|
+
#
|
94
|
+
# The default value is 0.
|
95
|
+
def set_distance_callback_period(period)
|
96
|
+
send_request(FUNCTION_SET_DISTANCE_CALLBACK_PERIOD, [period], 'L', 0, '')
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns the period as set by BrickletDistanceUS#set_distance_callback_period.
|
100
|
+
def get_distance_callback_period
|
101
|
+
send_request(FUNCTION_GET_DISTANCE_CALLBACK_PERIOD, [], '', 4, 'L')
|
102
|
+
end
|
103
|
+
|
104
|
+
# Sets the thresholds for the CALLBACK_DISTANCE_REACHED callback.
|
105
|
+
#
|
106
|
+
# The following options are possible:
|
107
|
+
#
|
108
|
+
# "Option", "Description"
|
109
|
+
#
|
110
|
+
# "'x'", "Callback is turned off"
|
111
|
+
# "'o'", "Callback is triggered when the distance value is *outside* the min and max values"
|
112
|
+
# "'i'", "Callback is triggered when the distance value is *inside* the min and max values"
|
113
|
+
# "'<'", "Callback is triggered when the distance value is smaller than the min value (max is ignored)"
|
114
|
+
# "'>'", "Callback is triggered when the distance value is greater than the min value (max is ignored)"
|
115
|
+
#
|
116
|
+
# The default value is ('x', 0, 0).
|
117
|
+
def set_distance_callback_threshold(option, min, max)
|
118
|
+
send_request(FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
|
119
|
+
end
|
120
|
+
|
121
|
+
# Returns the threshold as set by BrickletDistanceUS#set_distance_callback_threshold.
|
122
|
+
def get_distance_callback_threshold
|
123
|
+
send_request(FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
|
124
|
+
end
|
125
|
+
|
126
|
+
# Sets the period in ms with which the threshold callbacks
|
127
|
+
#
|
128
|
+
# * CALLBACK_DISTANCE_REACHED,
|
129
|
+
#
|
130
|
+
# are triggered, if the thresholds
|
131
|
+
#
|
132
|
+
# * BrickletDistanceUS#set_distance_callback_threshold,
|
133
|
+
#
|
134
|
+
# keep being reached.
|
135
|
+
#
|
136
|
+
# The default value is 100.
|
137
|
+
def set_debounce_period(debounce)
|
138
|
+
send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns the debounce period as set by BrickletDistanceUS#set_debounce_period.
|
142
|
+
def get_debounce_period
|
143
|
+
send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
|
144
|
+
end
|
145
|
+
|
146
|
+
# Sets the length of a `moving averaging <http://en.wikipedia.org/wiki/Moving_average>`__
|
147
|
+
# for the distance value.
|
148
|
+
#
|
149
|
+
# Setting the length to 0 will turn the averaging completely off. With less
|
150
|
+
# averaging, there is more noise on the data.
|
151
|
+
#
|
152
|
+
# The range for the averaging is 0-100.
|
153
|
+
#
|
154
|
+
# The default value is 20.
|
155
|
+
def set_moving_average(average)
|
156
|
+
send_request(FUNCTION_SET_MOVING_AVERAGE, [average], 'C', 0, '')
|
157
|
+
end
|
158
|
+
|
159
|
+
# Returns the length moving average as set by BrickletDistanceUS#set_moving_average.
|
160
|
+
def get_moving_average
|
161
|
+
send_request(FUNCTION_GET_MOVING_AVERAGE, [], '', 1, 'C')
|
162
|
+
end
|
163
|
+
|
164
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
165
|
+
# the position, the hardware and firmware version as well as the
|
166
|
+
# device identifier.
|
167
|
+
#
|
168
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
169
|
+
#
|
170
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
171
|
+
#
|
172
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
173
|
+
def get_identity
|
174
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
175
|
+
end
|
176
|
+
|
177
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
178
|
+
def register_callback(id, &block)
|
179
|
+
callback = block
|
180
|
+
@registered_callbacks[id] = callback
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
#############################################################
|
3
|
+
# This file was automatically generated on 2013-11-27. #
|
4
|
+
# #
|
5
|
+
# Bindings Version 2.0.12 #
|
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 with two buttons and two LEDs
|
14
|
+
class BrickletDualButton < Device
|
15
|
+
DEVICE_IDENTIFIER = 230 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is called whenever a button is pressed.
|
18
|
+
#
|
19
|
+
# Possible states for buttons are:
|
20
|
+
#
|
21
|
+
# * 0 = pressed
|
22
|
+
# * 1 = released
|
23
|
+
#
|
24
|
+
# Possible states for LEDs are:
|
25
|
+
#
|
26
|
+
# * 0 = AutoToggleOn: Auto toggle enabled and LED on.
|
27
|
+
# * 1 = AutoToggleOff: Auto toggle enabled and LED off.
|
28
|
+
# * 2 = On: LED on (auto toggle is disabled).
|
29
|
+
# * 3 = Off: LED off (auto toggle is disabled).
|
30
|
+
CALLBACK_STATE_CHANGED = 4
|
31
|
+
|
32
|
+
FUNCTION_SET_LED_STATE = 1 # :nodoc:
|
33
|
+
FUNCTION_GET_LED_STATE = 2 # :nodoc:
|
34
|
+
FUNCTION_GET_BUTTON_STATE = 3 # :nodoc:
|
35
|
+
FUNCTION_SET_SELECTED_LED_STATE = 5 # :nodoc:
|
36
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
37
|
+
|
38
|
+
LED_STATE_AUTO_TOGGLE_ON = 0 # :nodoc:
|
39
|
+
LED_STATE_AUTO_TOGGLE_OFF = 1 # :nodoc:
|
40
|
+
LED_STATE_ON = 2 # :nodoc:
|
41
|
+
LED_STATE_OFF = 3 # :nodoc:
|
42
|
+
BUTTON_STATE_PRESSED = 0 # :nodoc:
|
43
|
+
BUTTON_STATE_RELEASED = 1 # :nodoc:
|
44
|
+
LED_LEFT = 0 # :nodoc:
|
45
|
+
LED_RIGHT = 1 # :nodoc:
|
46
|
+
|
47
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
48
|
+
# the IP Connection <tt>ipcon</tt>.
|
49
|
+
def initialize(uid, ipcon)
|
50
|
+
super uid, ipcon
|
51
|
+
|
52
|
+
@api_version = [2, 0, 0]
|
53
|
+
|
54
|
+
@response_expected[FUNCTION_SET_LED_STATE] = RESPONSE_EXPECTED_FALSE
|
55
|
+
@response_expected[FUNCTION_GET_LED_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
56
|
+
@response_expected[FUNCTION_GET_BUTTON_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
57
|
+
@response_expected[CALLBACK_STATE_CHANGED] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
58
|
+
@response_expected[FUNCTION_SET_SELECTED_LED_STATE] = RESPONSE_EXPECTED_FALSE
|
59
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
60
|
+
|
61
|
+
@callback_formats[CALLBACK_STATE_CHANGED] = 'C C C C'
|
62
|
+
end
|
63
|
+
|
64
|
+
# Sets the state of the LEDs. Possible states are:
|
65
|
+
#
|
66
|
+
# * 0 = AutoToggleOn: Enables auto toggle with initially enabled LED.
|
67
|
+
# * 1 = AutoToggleOff: Activates auto toggle with initially disabled LED.
|
68
|
+
# * 2 = On: Enables LED (auto toggle is disabled).
|
69
|
+
# * 3 = Off: Disables LED (auto toggle is disabled).
|
70
|
+
#
|
71
|
+
# In auto toggle mode the LED is toggled automatically at each press of a button.
|
72
|
+
#
|
73
|
+
# If you just want to set one of the LEDs and don't know the current state
|
74
|
+
# of the other LED, you can get the state with BrickletDualButton#get_led_state or you
|
75
|
+
# can use BrickletDualButton#set_selected_led_state.
|
76
|
+
#
|
77
|
+
# The default value is (1, 1).
|
78
|
+
def set_led_state(led_l, led_r)
|
79
|
+
send_request(FUNCTION_SET_LED_STATE, [led_l, led_r], 'C C', 0, '')
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the current state of the LEDs, as set by BrickletDualButton#set_led_state.
|
83
|
+
def get_led_state
|
84
|
+
send_request(FUNCTION_GET_LED_STATE, [], '', 2, 'C C')
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns the current state for both buttons. Possible states are:
|
88
|
+
#
|
89
|
+
# * 0 = pressed
|
90
|
+
# * 1 = released
|
91
|
+
def get_button_state
|
92
|
+
send_request(FUNCTION_GET_BUTTON_STATE, [], '', 2, 'C C')
|
93
|
+
end
|
94
|
+
|
95
|
+
# Sets the state of the selected LED (0 or 1).
|
96
|
+
#
|
97
|
+
# The other LED remains untouched.
|
98
|
+
#
|
99
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
100
|
+
def set_selected_led_state(led, state)
|
101
|
+
send_request(FUNCTION_SET_SELECTED_LED_STATE, [led, state], 'C C', 0, '')
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
105
|
+
# the position, the hardware and firmware version as well as the
|
106
|
+
# device identifier.
|
107
|
+
#
|
108
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
109
|
+
#
|
110
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
111
|
+
#
|
112
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
113
|
+
def get_identity
|
114
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
115
|
+
end
|
116
|
+
|
117
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
118
|
+
def register_callback(id, &block)
|
119
|
+
callback = block
|
120
|
+
@registered_callbacks[id] = callback
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|