Skip to content

Commit c529ef2

Browse files
Merge pull request #17 from jposada202020/replacing_named_tuple
Replacing named tuple
2 parents 775e238 + 1352ce3 commit c529ef2

File tree

3 files changed

+59
-37
lines changed

3 files changed

+59
-37
lines changed

adafruit_as7341.py

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@
1616
1717
**Hardware:**
1818
19-
* `Adafruit AS7341 Breakout <https://www.adafruit.com/product/4698>`_
19+
* `Adafruit AS7341 Breakout
20+
<https://www.adafruit.com/product/4698>`_ (Product ID: 4698)
2021
2122
**Software and Dependencies:**
2223
2324
* Adafruit CircuitPython firmware for the supported boards:
24-
https://github.com/adafruit/circuitpython/releases
25+
https://circuitpython.org/downloads
2526
26-
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
27-
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
27+
* Adafruit's Bus Device library:
28+
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2829
29-
"""
30+
* Adafruit's Register library:
31+
https://github.com/adafruit/Adafruit_CircuitPython_Register
3032
31-
# imports
33+
"""
3234

3335
__version__ = "0.0.0-auto.0"
3436
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_AS7341.git"
35-
from collections import namedtuple
37+
3638
from time import sleep, monotonic
3739
from micropython import const
3840
import adafruit_bus_device.i2c_device as i2c_device
@@ -165,38 +167,58 @@ class Gain(CV):
165167
)
166168

167169

168-
_SmuxIn = namedtuple(
169-
"_SmuxIn",
170-
[
171-
"NC_F3L",
172-
"F1L_NC",
173-
"NC_NC0",
174-
"NC_F8L",
175-
"F6L_NC",
176-
"F2L_F4L",
177-
"NC_F5L",
178-
"F7L_NC",
179-
"NC_CL",
180-
"NC_F5R",
181-
"F7R_NC",
182-
"NC_NC1",
183-
"NC_F2R",
184-
"F4R_NC",
185-
"F8R_F6R",
186-
"NC_F3R",
187-
"F1R_EXT_GPIO",
188-
"EXT_INT_CR",
189-
"NC_DARK",
190-
"NIR_F",
191-
],
170+
class SMUX_OUT(CV):
171+
"""Options for ``smux_out``"""
172+
173+
pass # pylint: disable=unnecessary-pass
174+
175+
176+
SMUX_OUT.add_values(
177+
(
178+
("DISABLED", 0, 0, None),
179+
("ADC0", 1, 1, None),
180+
("ADC1", 2, 2, None),
181+
("ADC2", 3, 3, None),
182+
("ADC3", 4, 4, None),
183+
("ADC4", 5, 5, None),
184+
("ADC5", 6, 6, None),
185+
)
192186
)
193-
SMUX_IN = _SmuxIn(*list(range(20)))
194187

195-
_SmuxOut = namedtuple("_SmuxOut", "DISABLED ADC0 ADC1 ADC2 ADC3 ADC4 ADC5")
196-
SMUX_OUT = _SmuxOut(*list(range(7)))
188+
189+
class SMUX_IN(CV):
190+
"""Options for ``smux_in``"""
191+
192+
pass # pylint: disable=unnecessary-pass
193+
194+
195+
SMUX_IN.add_values(
196+
(
197+
("NC_F3L", 0, 0, None),
198+
("F1L_NC", 1, 1, None),
199+
("NC_NC0", 2, 2, None),
200+
("NC_F8L", 3, 3, None),
201+
("F6L_NC", 4, 4, None),
202+
("F2L_F4L", 5, 5, None),
203+
("NC_F5L", 6, 6, None),
204+
("F7L_NC", 7, 7, None),
205+
("NC_CL", 8, 8, None),
206+
("NC_F5R", 9, 9, None),
207+
("F7R_NC", 10, 10, None),
208+
("NC_NC1", 11, 11, None),
209+
("NC_F2R", 12, 12, None),
210+
("F4R_NC", 13, 13, None),
211+
("F8R_F6R", 14, 14, None),
212+
("NC_F3R", 15, 15, None),
213+
("F1R_EXT_GPIO", 16, 16, None),
214+
("EXT_INT_CR", 17, 17, None),
215+
("NC_DARK", 18, 18, None),
216+
("NIR_F", 19, 19, None),
217+
)
218+
)
197219

198220

199-
class AS7341: # pylint:disable=too-many-instance-attributes
221+
class AS7341: # pylint:disable=too-many-instance-attributes, no-member
200222
"""Library for the AS7341 Sensor
201223
202224
:param ~busio.I2C i2c_bus: The I2C bus the device is connected to

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
77
.. automodule:: adafruit_as7341
88
:members:
9-
:exclude-members: CV, Gain
9+
:exclude-members: CV, Gain, SMUX_IN, SMUX_OUT

examples/as7341_led_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import board
66
import adafruit_as7341
77

8-
i2c = board.I2C()
8+
i2c = board.I2C() # uses board.SCL and board.SDA
99
sensor = adafruit_as7341.AS7341(i2c)
1010

1111
print("out of init!")

0 commit comments

Comments
 (0)