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.
- data/lib/tinkerforge.rb +5 -0
- data/lib/tinkerforge/brick_dc.rb +359 -0
- data/lib/tinkerforge/brick_imu.rb +512 -0
- data/lib/tinkerforge/brick_master.rb +1120 -0
- data/lib/tinkerforge/brick_servo.rb +475 -0
- data/lib/tinkerforge/brick_stepper.rb +556 -0
- data/lib/tinkerforge/bricklet_ambient_light.rb +246 -0
- data/lib/tinkerforge/bricklet_analog_in.rb +273 -0
- data/lib/tinkerforge/bricklet_analog_out.rb +90 -0
- data/lib/tinkerforge/bricklet_barometer.rb +313 -0
- data/lib/tinkerforge/bricklet_current12.rb +274 -0
- data/lib/tinkerforge/bricklet_current25.rb +274 -0
- data/lib/tinkerforge/bricklet_distance_ir.rb +274 -0
- data/lib/tinkerforge/bricklet_dual_relay.rb +127 -0
- data/lib/tinkerforge/bricklet_gps.rb +301 -0
- data/lib/tinkerforge/bricklet_humidity.rb +245 -0
- data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +165 -0
- data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +177 -0
- data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +177 -0
- data/lib/tinkerforge/bricklet_io16.rb +237 -0
- data/lib/tinkerforge/bricklet_io4.rb +236 -0
- data/lib/tinkerforge/bricklet_joystick.rb +274 -0
- data/lib/tinkerforge/bricklet_lcd_16x2.rb +175 -0
- data/lib/tinkerforge/bricklet_lcd_20x4.rb +231 -0
- data/lib/tinkerforge/bricklet_linear_poti.rb +241 -0
- data/lib/tinkerforge/bricklet_piezo_buzzer.rb +84 -0
- data/lib/tinkerforge/bricklet_ptc.rb +277 -0
- data/lib/tinkerforge/bricklet_rotary_poti.rb +241 -0
- data/lib/tinkerforge/bricklet_temperature.rb +188 -0
- data/lib/tinkerforge/bricklet_temperature_ir.rb +275 -0
- data/lib/tinkerforge/bricklet_voltage.rb +241 -0
- data/lib/tinkerforge/bricklet_voltage_current.rb +386 -0
- data/lib/tinkerforge/ip_connection.rb +1027 -0
- data/lib/tinkerforge/version.rb +4 -0
- metadata +98 -0
@@ -0,0 +1,237 @@
|
|
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 up to 16 general purpose input/output pins
|
14
|
+
class BrickletIO16 < Device
|
15
|
+
DEVICE_IDENTIFIER = 28 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered whenever a change of the voltage level is detected
|
18
|
+
# on pins where the interrupt was activated with BrickletIO16#set_port_interrupt.
|
19
|
+
#
|
20
|
+
# The values are the port, a bitmask that specifies which interrupts occurred
|
21
|
+
# and the current value bitmask of the port.
|
22
|
+
#
|
23
|
+
# For example:
|
24
|
+
#
|
25
|
+
# * ("a", 1, 1) means that on port a an interrupt on pin 0 occurred and
|
26
|
+
# currently pin 0 is high and pins 1-7 are low.
|
27
|
+
# * ("b", 128, 254) means that on port b interrupts on pins 0 and 7
|
28
|
+
# occurred and currently pin 0 is low and pins 1-7 are high.
|
29
|
+
CALLBACK_INTERRUPT = 9
|
30
|
+
|
31
|
+
# This callback is triggered whenever a monoflop timer reaches 0. The
|
32
|
+
# parameters contain the port, the involved pins and the current value of
|
33
|
+
# the pins (the value after the monoflop).
|
34
|
+
#
|
35
|
+
# .. versionadded:: 1.1.2~(Plugin)
|
36
|
+
CALLBACK_MONOFLOP_DONE = 12
|
37
|
+
|
38
|
+
FUNCTION_SET_PORT = 1 # :nodoc:
|
39
|
+
FUNCTION_GET_PORT = 2 # :nodoc:
|
40
|
+
FUNCTION_SET_PORT_CONFIGURATION = 3 # :nodoc:
|
41
|
+
FUNCTION_GET_PORT_CONFIGURATION = 4 # :nodoc:
|
42
|
+
FUNCTION_SET_DEBOUNCE_PERIOD = 5 # :nodoc:
|
43
|
+
FUNCTION_GET_DEBOUNCE_PERIOD = 6 # :nodoc:
|
44
|
+
FUNCTION_SET_PORT_INTERRUPT = 7 # :nodoc:
|
45
|
+
FUNCTION_GET_PORT_INTERRUPT = 8 # :nodoc:
|
46
|
+
FUNCTION_SET_PORT_MONOFLOP = 10 # :nodoc:
|
47
|
+
FUNCTION_GET_PORT_MONOFLOP = 11 # :nodoc:
|
48
|
+
FUNCTION_SET_SELECTED_VALUES = 13 # :nodoc:
|
49
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
50
|
+
|
51
|
+
DIRECTION_IN = 'i' # :nodoc:
|
52
|
+
DIRECTION_OUT = 'o' # :nodoc:
|
53
|
+
|
54
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
55
|
+
# the IP Connection <tt>ipcon</tt>.
|
56
|
+
def initialize(uid, ipcon)
|
57
|
+
super uid, ipcon
|
58
|
+
|
59
|
+
@api_version = [2, 0, 0]
|
60
|
+
|
61
|
+
@response_expected[FUNCTION_SET_PORT] = RESPONSE_EXPECTED_FALSE
|
62
|
+
@response_expected[FUNCTION_GET_PORT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
63
|
+
@response_expected[FUNCTION_SET_PORT_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
|
64
|
+
@response_expected[FUNCTION_GET_PORT_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
65
|
+
@response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
|
66
|
+
@response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
67
|
+
@response_expected[FUNCTION_SET_PORT_INTERRUPT] = RESPONSE_EXPECTED_TRUE
|
68
|
+
@response_expected[FUNCTION_GET_PORT_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
69
|
+
@response_expected[CALLBACK_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
70
|
+
@response_expected[FUNCTION_SET_PORT_MONOFLOP] = RESPONSE_EXPECTED_FALSE
|
71
|
+
@response_expected[FUNCTION_GET_PORT_MONOFLOP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
72
|
+
@response_expected[CALLBACK_MONOFLOP_DONE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
73
|
+
@response_expected[FUNCTION_SET_SELECTED_VALUES] = RESPONSE_EXPECTED_FALSE
|
74
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
75
|
+
|
76
|
+
@callback_formats[CALLBACK_INTERRUPT] = 'k C C'
|
77
|
+
@callback_formats[CALLBACK_MONOFLOP_DONE] = 'k C C'
|
78
|
+
end
|
79
|
+
|
80
|
+
# Sets the output value (high or low) for a port ("a" or "b") with a bitmask.
|
81
|
+
# The bitmask is 8 bit long, *true* refers to high and *false* refers to low.
|
82
|
+
#
|
83
|
+
# For example: The value 0b00001111 will turn the pins 0-3 high and the
|
84
|
+
# pins 4-7 low for the specified port.
|
85
|
+
#
|
86
|
+
# .. note::
|
87
|
+
# This function does nothing for pins that are configured as input.
|
88
|
+
# Pull-up resistors can be switched on with BrickletIO16#set_port_configuration.
|
89
|
+
def set_port(port, value_mask)
|
90
|
+
send_request(FUNCTION_SET_PORT, [port, value_mask], 'k C', 0, '')
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns a bitmask of the values that are currently measured on the
|
94
|
+
# specified port. This function works if the pin is configured to input
|
95
|
+
# as well as if it is configured to output.
|
96
|
+
def get_port(port)
|
97
|
+
send_request(FUNCTION_GET_PORT, [port], 'k', 1, 'C')
|
98
|
+
end
|
99
|
+
|
100
|
+
# Configures the value and direction of a specified port. Possible directions
|
101
|
+
# are "i" and "o" for input and output.
|
102
|
+
#
|
103
|
+
# If the direction is configured as output, the value is either high or low
|
104
|
+
# (set as *true* or *false*).
|
105
|
+
#
|
106
|
+
# If the direction is configured as input, the value is either pull-up or
|
107
|
+
# default (set as *true* or *false*).
|
108
|
+
#
|
109
|
+
# For example:
|
110
|
+
#
|
111
|
+
# * ("a", 0xFF, 'i', true) will set all pins of port a as input pull-up.
|
112
|
+
# * ("a", 128, 'i', false) will set pin 7 of port a as input default (floating if nothing is connected).
|
113
|
+
# * ("b", 3, 'o', false) will set pins 0 and 1 of port b as output low.
|
114
|
+
# * ("b", 4, 'o', true) will set pin 2 of port b as output high.
|
115
|
+
def set_port_configuration(port, selection_mask, direction, value)
|
116
|
+
send_request(FUNCTION_SET_PORT_CONFIGURATION, [port, selection_mask, direction, value], 'k C k ?', 0, '')
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns a direction bitmask and a value bitmask for the specified port.
|
120
|
+
#
|
121
|
+
# For example: A return value of 0b00001111 and 0b00110011 for
|
122
|
+
# direction and value means that:
|
123
|
+
#
|
124
|
+
# * pins 0 and 1 are configured as input pull-up,
|
125
|
+
# * pins 2 and 3 are configured as input default,
|
126
|
+
# * pins 4 and 5 are configured as output high
|
127
|
+
# * and pins 6 and 7 are configured as output low.
|
128
|
+
def get_port_configuration(port)
|
129
|
+
send_request(FUNCTION_GET_PORT_CONFIGURATION, [port], 'k', 2, 'C C')
|
130
|
+
end
|
131
|
+
|
132
|
+
# Sets the debounce period of the CALLBACK_INTERRUPT callback in ms.
|
133
|
+
#
|
134
|
+
# For example: If you set this value to 100, you will get the interrupt
|
135
|
+
# maximal every 100ms. This is necessary if something that bounces is
|
136
|
+
# connected to the IO-16 Bricklet, such as a button.
|
137
|
+
#
|
138
|
+
# The default value is 100.
|
139
|
+
def set_debounce_period(debounce)
|
140
|
+
send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
|
141
|
+
end
|
142
|
+
|
143
|
+
# Returns the debounce period as set by BrickletIO16#set_debounce_period.
|
144
|
+
def get_debounce_period
|
145
|
+
send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
|
146
|
+
end
|
147
|
+
|
148
|
+
# Sets the pins on which an interrupt is activated with a bitmask.
|
149
|
+
# Interrupts are triggered on changes of the voltage level of the pin,
|
150
|
+
# i.e. changes from high to low and low to high.
|
151
|
+
#
|
152
|
+
# For example: ('a', 129) will enable the interrupt for pins 0 and 7 of
|
153
|
+
# port a.
|
154
|
+
#
|
155
|
+
# The interrupt is delivered with the callback CALLBACK_INTERRUPT.
|
156
|
+
def set_port_interrupt(port, interrupt_mask)
|
157
|
+
send_request(FUNCTION_SET_PORT_INTERRUPT, [port, interrupt_mask], 'k C', 0, '')
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns the interrupt bitmask for the specified port as set by
|
161
|
+
# BrickletIO16#set_port_interrupt.
|
162
|
+
def get_port_interrupt(port)
|
163
|
+
send_request(FUNCTION_GET_PORT_INTERRUPT, [port], 'k', 1, 'C')
|
164
|
+
end
|
165
|
+
|
166
|
+
# Configures a monoflop of the pins specified by the second parameter as 8 bit
|
167
|
+
# long bitmask. The specified pins must be configured for output. Non-output
|
168
|
+
# pins will be ignored.
|
169
|
+
#
|
170
|
+
# The third parameter is a bitmask with the desired value of the specified
|
171
|
+
# output pins (*true* means high and *false* means low).
|
172
|
+
#
|
173
|
+
# The forth parameter indicates the time (in ms) that the pins should hold
|
174
|
+
# the value.
|
175
|
+
#
|
176
|
+
# If this function is called with the parameters ('a', (1 << 0) | (1 << 3), (1 << 0), 1500):
|
177
|
+
# Pin 0 will get high and pin 3 will get low on port 'a'. In 1.5s pin 0 will get
|
178
|
+
# low and pin 3 will get high again.
|
179
|
+
#
|
180
|
+
# A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
|
181
|
+
# have a RS485 bus and an IO-16 Bricklet connected to one of the slave
|
182
|
+
# stacks. You can now call this function every second, with a time parameter
|
183
|
+
# of two seconds and pin 0 set to high. Pin 0 will be high all the time. If now
|
184
|
+
# the RS485 connection is lost, then pin 0 will get low in at most two seconds.
|
185
|
+
#
|
186
|
+
# .. versionadded:: 1.1.2~(Plugin)
|
187
|
+
def set_port_monoflop(port, selection_mask, value_mask, time)
|
188
|
+
send_request(FUNCTION_SET_PORT_MONOFLOP, [port, selection_mask, value_mask, time], 'k C C L', 0, '')
|
189
|
+
end
|
190
|
+
|
191
|
+
# Returns (for the given pin) the current value and the time as set by
|
192
|
+
# BrickletIO16#set_port_monoflop as well as the remaining time until the value flips.
|
193
|
+
#
|
194
|
+
# If the timer is not running currently, the remaining time will be returned
|
195
|
+
# as 0.
|
196
|
+
#
|
197
|
+
# .. versionadded:: 1.1.2~(Plugin)
|
198
|
+
def get_port_monoflop(port, pin)
|
199
|
+
send_request(FUNCTION_GET_PORT_MONOFLOP, [port, pin], 'k C', 9, 'C L L')
|
200
|
+
end
|
201
|
+
|
202
|
+
# Sets the output value (high or low) for a port ("a" or "b" with a bitmask,
|
203
|
+
# according to the selection mask. The bitmask is 8 bit long, *true* refers
|
204
|
+
# to high and *false* refers to low.
|
205
|
+
#
|
206
|
+
# For example: The values 0b11000000, 0b10000000 will turn pin 7 high and
|
207
|
+
# pin 6 low, pins 0-6 will remain untouched.
|
208
|
+
#
|
209
|
+
# .. note::
|
210
|
+
# This function does nothing for pins that are configured as input.
|
211
|
+
# Pull-up resistors can be switched on with :func:`SetConfiguration`.
|
212
|
+
#
|
213
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
214
|
+
def set_selected_values(port, selection_mask, value_mask)
|
215
|
+
send_request(FUNCTION_SET_SELECTED_VALUES, [port, selection_mask, value_mask], 'k C C', 0, '')
|
216
|
+
end
|
217
|
+
|
218
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
219
|
+
# the position, the hardware and firmware version as well as the
|
220
|
+
# device identifier.
|
221
|
+
#
|
222
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
223
|
+
#
|
224
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
225
|
+
#
|
226
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
227
|
+
def get_identity
|
228
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
229
|
+
end
|
230
|
+
|
231
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
232
|
+
def register_callback(id, &block)
|
233
|
+
callback = block
|
234
|
+
@registered_callbacks[id] = callback
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -0,0 +1,236 @@
|
|
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 up to 4 general purpose input/output pins
|
14
|
+
class BrickletIO4 < Device
|
15
|
+
DEVICE_IDENTIFIER = 29 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered whenever a change of the voltage level is detected
|
18
|
+
# on pins where the interrupt was activated with BrickletIO4#set_interrupt.
|
19
|
+
#
|
20
|
+
# The values are a bitmask that specifies which interrupts occurred
|
21
|
+
# and the current value bitmask.
|
22
|
+
#
|
23
|
+
# For example:
|
24
|
+
#
|
25
|
+
# * (1, 1) means that an interrupt on pin 0 occurred and
|
26
|
+
# currently pin 0 is high and pins 1-3 are low.
|
27
|
+
# * (9, 14) means that interrupts on pins 0 and 3
|
28
|
+
# occurred and currently pin 0 is low and pins 1-3 are high.
|
29
|
+
CALLBACK_INTERRUPT = 9
|
30
|
+
|
31
|
+
# This callback is triggered whenever a monoflop timer reaches 0. The
|
32
|
+
# parameters contain the involved pins and the current value of the pins
|
33
|
+
# (the value after the monoflop).
|
34
|
+
#
|
35
|
+
# .. versionadded:: 1.1.1~(Plugin)
|
36
|
+
CALLBACK_MONOFLOP_DONE = 12
|
37
|
+
|
38
|
+
FUNCTION_SET_VALUE = 1 # :nodoc:
|
39
|
+
FUNCTION_GET_VALUE = 2 # :nodoc:
|
40
|
+
FUNCTION_SET_CONFIGURATION = 3 # :nodoc:
|
41
|
+
FUNCTION_GET_CONFIGURATION = 4 # :nodoc:
|
42
|
+
FUNCTION_SET_DEBOUNCE_PERIOD = 5 # :nodoc:
|
43
|
+
FUNCTION_GET_DEBOUNCE_PERIOD = 6 # :nodoc:
|
44
|
+
FUNCTION_SET_INTERRUPT = 7 # :nodoc:
|
45
|
+
FUNCTION_GET_INTERRUPT = 8 # :nodoc:
|
46
|
+
FUNCTION_SET_MONOFLOP = 10 # :nodoc:
|
47
|
+
FUNCTION_GET_MONOFLOP = 11 # :nodoc:
|
48
|
+
FUNCTION_SET_SELECTED_VALUES = 13 # :nodoc:
|
49
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
50
|
+
|
51
|
+
DIRECTION_IN = 'i' # :nodoc:
|
52
|
+
DIRECTION_OUT = 'o' # :nodoc:
|
53
|
+
|
54
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
55
|
+
# the IP Connection <tt>ipcon</tt>.
|
56
|
+
def initialize(uid, ipcon)
|
57
|
+
super uid, ipcon
|
58
|
+
|
59
|
+
@api_version = [2, 0, 0]
|
60
|
+
|
61
|
+
@response_expected[FUNCTION_SET_VALUE] = RESPONSE_EXPECTED_FALSE
|
62
|
+
@response_expected[FUNCTION_GET_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
63
|
+
@response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
|
64
|
+
@response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
65
|
+
@response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
|
66
|
+
@response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
67
|
+
@response_expected[FUNCTION_SET_INTERRUPT] = RESPONSE_EXPECTED_TRUE
|
68
|
+
@response_expected[FUNCTION_GET_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
69
|
+
@response_expected[CALLBACK_INTERRUPT] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
70
|
+
@response_expected[FUNCTION_SET_MONOFLOP] = RESPONSE_EXPECTED_FALSE
|
71
|
+
@response_expected[FUNCTION_GET_MONOFLOP] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
72
|
+
@response_expected[CALLBACK_MONOFLOP_DONE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
73
|
+
@response_expected[FUNCTION_SET_SELECTED_VALUES] = RESPONSE_EXPECTED_FALSE
|
74
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
75
|
+
|
76
|
+
@callback_formats[CALLBACK_INTERRUPT] = 'C C'
|
77
|
+
@callback_formats[CALLBACK_MONOFLOP_DONE] = 'C C'
|
78
|
+
end
|
79
|
+
|
80
|
+
# Sets the output value (high or low) with a bitmask. The bitmask
|
81
|
+
# is 4 bit long, *true* refers to high and *false* refers to low.
|
82
|
+
#
|
83
|
+
# For example: The value 0b0011 will turn the pins 0-1 high and the
|
84
|
+
# pins 2-3 low.
|
85
|
+
#
|
86
|
+
# .. note::
|
87
|
+
# This function does nothing for pins that are configured as input.
|
88
|
+
# Pull-up resistors can be switched on with BrickletIO4#set_configuration.
|
89
|
+
def set_value(value_mask)
|
90
|
+
send_request(FUNCTION_SET_VALUE, [value_mask], 'C', 0, '')
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns a bitmask of the values that are currently measured.
|
94
|
+
# This function works if the pin is configured to input
|
95
|
+
# as well as if it is configured to output.
|
96
|
+
def get_value
|
97
|
+
send_request(FUNCTION_GET_VALUE, [], '', 1, 'C')
|
98
|
+
end
|
99
|
+
|
100
|
+
# Configures the value and direction of the specified pins. Possible directions
|
101
|
+
# are "i" and "o" for input and output.
|
102
|
+
#
|
103
|
+
# If the direction is configured as output, the value is either high or low
|
104
|
+
# (set as *true* or *false*).
|
105
|
+
#
|
106
|
+
# If the direction is configured as input, the value is either pull-up or
|
107
|
+
# default (set as *true* or *false*).
|
108
|
+
#
|
109
|
+
# For example:
|
110
|
+
#
|
111
|
+
# * (15, 'i', true) will set all pins of as input pull-up.
|
112
|
+
# * (8, 'i', false) will set pin 3 of as input default (floating if nothing is connected).
|
113
|
+
# * (3, 'o', false) will set pins 0 and 1 as output low.
|
114
|
+
# * (4, 'o', true) will set pin 2 of as output high.
|
115
|
+
def set_configuration(selection_mask, direction, value)
|
116
|
+
send_request(FUNCTION_SET_CONFIGURATION, [selection_mask, direction, value], 'C k ?', 0, '')
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns a value bitmask and a direction bitmask.
|
120
|
+
#
|
121
|
+
# For example: A return value of 0b0011 and 0b0101 for
|
122
|
+
# direction and value means that:
|
123
|
+
#
|
124
|
+
# * pin 0 is configured as input pull-up,
|
125
|
+
# * pin 1 is configured as input default,
|
126
|
+
# * pin 2 is configured as output high
|
127
|
+
# * and pin 3 is are configured as output low.
|
128
|
+
def get_configuration
|
129
|
+
send_request(FUNCTION_GET_CONFIGURATION, [], '', 2, 'C C')
|
130
|
+
end
|
131
|
+
|
132
|
+
# Sets the debounce period of the CALLBACK_INTERRUPT callback in ms.
|
133
|
+
#
|
134
|
+
# For example: If you set this value to 100, you will get the interrupt
|
135
|
+
# maximal every 100ms. This is necessary if something that bounces is
|
136
|
+
# connected to the IO-4 Bricklet, such as a button.
|
137
|
+
#
|
138
|
+
# The default value is 100.
|
139
|
+
def set_debounce_period(debounce)
|
140
|
+
send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
|
141
|
+
end
|
142
|
+
|
143
|
+
# Returns the debounce period as set by BrickletIO4#set_debounce_period.
|
144
|
+
def get_debounce_period
|
145
|
+
send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
|
146
|
+
end
|
147
|
+
|
148
|
+
# Sets the pins on which an interrupt is activated with a bitmask.
|
149
|
+
# Interrupts are triggered on changes of the voltage level of the pin,
|
150
|
+
# i.e. changes from high to low and low to high.
|
151
|
+
#
|
152
|
+
# For example: An interrupt bitmask of 9 will enable the interrupt for
|
153
|
+
# pins 0 and 3.
|
154
|
+
#
|
155
|
+
# The interrupt is delivered with the callback CALLBACK_INTERRUPT.
|
156
|
+
def set_interrupt(interrupt_mask)
|
157
|
+
send_request(FUNCTION_SET_INTERRUPT, [interrupt_mask], 'C', 0, '')
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns the interrupt bitmask as set by BrickletIO4#set_interrupt.
|
161
|
+
def get_interrupt
|
162
|
+
send_request(FUNCTION_GET_INTERRUPT, [], '', 1, 'C')
|
163
|
+
end
|
164
|
+
|
165
|
+
# Configures a monoflop of the pins specified by the first parameter as 4 bit
|
166
|
+
# long bitmask. The specified pins must be configured for output. Non-output
|
167
|
+
# pins will be ignored.
|
168
|
+
#
|
169
|
+
# The second parameter is a bitmask with the desired value of the specified
|
170
|
+
# output pins (*true* means high and *false* means low).
|
171
|
+
#
|
172
|
+
# The third parameter indicates the time (in ms) that the pins should hold
|
173
|
+
# the value.
|
174
|
+
#
|
175
|
+
# If this function is called with the parameters ((1 << 0) | (1 << 3), (1 << 0), 1500):
|
176
|
+
# Pin 0 will get high and pin 3 will get low. In 1.5s pin 0 will get low and pin
|
177
|
+
# 3 will get high again.
|
178
|
+
#
|
179
|
+
# A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
|
180
|
+
# have a RS485 bus and an IO-4 Bricklet connected to one of the slave
|
181
|
+
# stacks. You can now call this function every second, with a time parameter
|
182
|
+
# of two seconds and pin 0 set to high. Pin 0 will be high all the time. If now
|
183
|
+
# the RS485 connection is lost, then pin 0 will get low in at most two seconds.
|
184
|
+
#
|
185
|
+
# .. versionadded:: 1.1.1~(Plugin)
|
186
|
+
def set_monoflop(selection_mask, value_mask, time)
|
187
|
+
send_request(FUNCTION_SET_MONOFLOP, [selection_mask, value_mask, time], 'C C L', 0, '')
|
188
|
+
end
|
189
|
+
|
190
|
+
# Returns (for the given pin) the current value and the time as set by
|
191
|
+
# BrickletIO4#set_monoflop as well as the remaining time until the value flips.
|
192
|
+
#
|
193
|
+
# If the timer is not running currently, the remaining time will be returned
|
194
|
+
# as 0.
|
195
|
+
#
|
196
|
+
# .. versionadded:: 1.1.1~(Plugin)
|
197
|
+
def get_monoflop(pin)
|
198
|
+
send_request(FUNCTION_GET_MONOFLOP, [pin], 'C', 9, 'C L L')
|
199
|
+
end
|
200
|
+
|
201
|
+
# Sets the output value (high or low) with a bitmask, according to
|
202
|
+
# the selection mask. The bitmask is 4 bit long, *true* refers to high
|
203
|
+
# and *false* refers to low.
|
204
|
+
#
|
205
|
+
# For example: The values 0b0110, 0b0011 will turn pin 2 high and
|
206
|
+
# pin 1 low, pin 0 and 3 will remain untouched.
|
207
|
+
#
|
208
|
+
# .. note::
|
209
|
+
# This function does nothing for pins that are configured as input.
|
210
|
+
# Pull-up resistors can be switched on with BrickletIO4#set_configuration.
|
211
|
+
#
|
212
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
213
|
+
def set_selected_values(selection_mask, value_mask)
|
214
|
+
send_request(FUNCTION_SET_SELECTED_VALUES, [selection_mask, value_mask], 'C C', 0, '')
|
215
|
+
end
|
216
|
+
|
217
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
218
|
+
# the position, the hardware and firmware version as well as the
|
219
|
+
# device identifier.
|
220
|
+
#
|
221
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
222
|
+
#
|
223
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
224
|
+
#
|
225
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
226
|
+
def get_identity
|
227
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
228
|
+
end
|
229
|
+
|
230
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
231
|
+
def register_callback(id, &block)
|
232
|
+
callback = block
|
233
|
+
@registered_callbacks[id] = callback
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|