forked from pybricks/pybricks-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiodevices.py
More file actions
246 lines (181 loc) · 5.85 KB
/
Copy pathiodevices.py
File metadata and controls
246 lines (181 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2020 The Pybricks Authors
"""Generic input/output devices."""
class PUPDevice:
"""Powered Up motor or sensor."""
def __init__(self, port):
"""
Arguments:
port (Port): Port to which the device is connected.
"""
pass
def info(self):
"""Returns information about the device.
Returns:
``dict``: Dictionary with information, such as the device ``id``.
"""
pass
def read(self, mode):
"""Reads values from a given mode.
Arguments:
mode (``int``): Device mode.
Returns:
``tuple``: Values read from the sensor.
"""
pass
def write(self, mode, data):
"""Writes values to the sensor. Only selected sensors and modes support
this.
Arguments:
mode (``int``): Device mode.
data (``tuple``): Values to be written.
"""
pass
class LUMPDevice:
"""Devices using the LEGO UART Messaging Protocol."""
def __init__(self, port):
"""
Arguments:
port (Port): Port to which the device is connected.
"""
pass
def read(self, mode):
"""Reads values from a given mode.
Arguments:
mode (``int``): Device mode.
Returns:
``tuple``: Values read from the sensor.
"""
pass
class Ev3devSensor:
"""Read values of an ev3dev-compatible sensor."""
sensor_index = 0
"""Index of the ev3dev sysfs `lego-sensor`_ class."""
port_index = 0
"""Index of the ev3dev sysfs `lego-port`_ class."""
def __init__(self, port):
"""
Arguments:
port (Port): Port to which the device is connected.
"""
pass
def read(self, mode):
"""Reads values at a given mode.
Arguments:
mode (``str``): `Mode name`_.
Returns:
``tuple``: Values read from the sensor.
"""
pass
class AnalogSensor:
"""Generic or custom analog sensor."""
def __init__(self, port):
"""
Arguments:
port (Port): Port to which the sensor is connected.
"""
pass
def voltage(self):
"""Measures analog voltage.
Returns:
:ref:`voltage`: Analog voltage.
"""
pass
def resistance(self):
"""Measures resistance.
This value is only meaningful if the analog device is a passive load
such as a resistor or thermistor.
Returns:
:ref:`resistance: Ω <voltage>`: Resistance of the analog device.
"""
pass
def active(self):
"""Sets sensor to active mode. This sets pin 5 of the sensor
port to `high`.
This is used in some analog
sensors to control a switch. For example, if you use the NXT Light
Sensor as a custom analog sensor, this method will turn the light on.
From then on, ``voltage()`` returns the raw reflected light value.
"""
pass
def passive(self):
"""Sets sensor to passive mode. This sets pin 5 of the sensor
port to `low`.
This is used in some analog
sensors to control a switch. For example, if you use the NXT Light
Sensor as a custom analog sensor, this method will turn the light off.
From then on, ``voltage()`` returns the raw ambient light value.
"""
pass
class I2CDevice:
"""Generic or custom I2C device."""
def __init__(self, port, address):
"""
Arguments:
port (Port): Port to which the device is connected.
address(int): I2C address of the client device. See
:ref:`I2C Addresses <i2caddress>`.
"""
pass
def read(self, reg, length=1):
"""Reads bytes, starting at a given register.
Arguments:
reg (``int``): Register at which to begin
reading: 0--255 or 0x00--0xFF.
length (``int``): How many bytes to read.
Returns:
``bytes``: Bytes returned from the device.
"""
pass
def write(self, reg, data=None):
"""Writes bytes, starting at a given register.
Arguments:
reg (``int``): Register at which to begin
writing: 0--255 or 0x00--0xFF.
data (``bytes``): Bytes to be written.
"""
pass
class UARTDevice:
"""Generic UART device."""
def __init__(self, port, baudrate, timeout=None):
"""
Arguments:
port (Port): Port to which the device is connected.
baudrate (int): Baudrate of the UART device.
timeout (:ref:`time`): How long to wait
during ``read`` before giving up. If you choose ``None``,
it will wait forever.
"""
pass
def read(self, length=1):
"""Reads a given number of bytes from the buffer.
Your program will wait until the requested number of bytes are
received. If this takes longer than ``timeout``, the ``ETIMEDOUT``
exception is raised.
Arguments:
length (``int``): How many bytes to read.
Returns:
``bytes``: Bytes returned from the device.
"""
pass
def read_all(self):
"""Reads all bytes from the buffer.
Returns:
``bytes``: Bytes returned from the device.
"""
pass
def write(self, data):
"""Writes bytes.
Arguments:
data (``bytes``): Bytes to be written.
"""
pass
def waiting(self):
"""Gets how many bytes are still waiting to be read.
Returns:
``int``: Number of bytes in the buffer.
"""
pass
def clear(self):
"""Empties the buffer."""
pass