Skip to content

Commit 13c3636

Browse files
committed
merge things cleanup....
1 parent 82cb221 commit 13c3636

7 files changed

+135
-74
lines changed

adafruit_tlc59711.py

+52-61
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2018 Stefan Krüger s-light.eu
23
#
34
# SPDX-License-Identifier: MIT
45

@@ -9,7 +10,7 @@
910
1011
CircuitPython module for the
1112
TLC59711 or TLC5971 16-bit 12 channel LED PWM driver.
12-
See examples/simpletest_multi.py for a demo of the usage.
13+
See examples/tlc59711_simpletest.py for a demo of the usage.
1314
1415
* Author(s): Tony DiCola, Stefan Kruger
1516
@@ -183,9 +184,21 @@ class TLC59711:
183184
_BC_BIT_COUNT = const(3 * 7)
184185
# this holds the chip offset and
185186
_BC_FIELDS = {
186-
"BCR": {"offset": 0, "length": 7, "mask": 0b01111111,},
187-
"BCG": {"offset": 7, "length": 7, "mask": 0b01111111,},
188-
"BCB": {"offset": 14, "length": 7, "mask": 0b01111111,},
187+
"BCR": {
188+
"offset": 0,
189+
"length": 7,
190+
"mask": 0b01111111,
191+
},
192+
"BCG": {
193+
"offset": 7,
194+
"length": 7,
195+
"mask": 0b01111111,
196+
},
197+
"BCB": {
198+
"offset": 14,
199+
"length": 7,
200+
"mask": 0b01111111,
201+
},
189202
}
190203

191204
##########################################
@@ -218,11 +231,31 @@ class TLC59711:
218231
_FC_CHIP_BUFFER_BIT_OFFSET = const(_BC_BIT_COUNT)
219232
_FC_BIT_COUNT = const(5)
220233
_FC_FIELDS = {
221-
"BLANK": {"offset": 0, "length": 1, "mask": 0b1,},
222-
"DSPRPT": {"offset": 1, "length": 1, "mask": 0b1,},
223-
"TMGRST": {"offset": 2, "length": 1, "mask": 0b1,},
224-
"EXTGCK": {"offset": 3, "length": 1, "mask": 0b1,},
225-
"OUTTMG": {"offset": 4, "length": 1, "mask": 0b1,},
234+
"BLANK": {
235+
"offset": 0,
236+
"length": 1,
237+
"mask": 0b1,
238+
},
239+
"DSPRPT": {
240+
"offset": 1,
241+
"length": 1,
242+
"mask": 0b1,
243+
},
244+
"TMGRST": {
245+
"offset": 2,
246+
"length": 1,
247+
"mask": 0b1,
248+
},
249+
"EXTGCK": {
250+
"offset": 3,
251+
"length": 1,
252+
"mask": 0b1,
253+
},
254+
"OUTTMG": {
255+
"offset": 4,
256+
"length": 1,
257+
"mask": 0b1,
258+
},
226259
}
227260

228261
##########################################
@@ -232,7 +265,11 @@ class TLC59711:
232265
_WC_CHIP_BUFFER_BIT_OFFSET = const(_FC_BIT_COUNT + _BC_BIT_COUNT)
233266
_WC_BIT_COUNT = const(6)
234267
_WC_FIELDS = {
235-
"WRITE_COMMAND": {"offset": 0, "length": 6, "mask": 0b111111,},
268+
"WRITE_COMMAND": {
269+
"offset": 0,
270+
"length": 6,
271+
"mask": 0b111111,
272+
},
236273
}
237274
WRITE_COMMAND = const(0b100101)
238275
##########################################
@@ -433,7 +470,6 @@ def _write(self):
433470
self._spi.unlock()
434471

435472
def show(self):
436-
437473
"""Write out the current LED PWM state to the chip."""
438474
self._write()
439475

@@ -839,57 +875,12 @@ def set_channel(self, channel_index, value):
839875
)
840876

841877
# Define index and length properties to set and get each pixel as
842-
=======
843-
"""Write out the current LED PWM state to the chip. This is only necessary if
844-
auto_show was set to false in the initializer.
845-
"""
846-
self._write()
847-
848-
# Define properties for global brightness control channels.
849-
@property
850-
def red_brightness(self):
851-
"""The red brightness for all channels (i.e. R0, R1, R2, and R3). This is a 7-bit
852-
value from 0-127.
853-
"""
854-
return self._bcr
855-
856-
@red_brightness.setter
857-
def red_brightness(self, val):
858-
assert 0 <= val <= 127
859-
self._bcr = val
860-
if self.auto_show:
861-
self._write()
862-
863-
@property
864-
def green_brightness(self):
865-
"""The green brightness for all channels (i.e. G0, G1, G2, and G3). This is a
866-
7-bit value from 0-127.
867-
"""
868-
return self._bcg
869-
870-
@green_brightness.setter
871-
def green_brightness(self, val):
872-
assert 0 <= val <= 127
873-
self._bcg = val
874-
if self.auto_show:
875-
self._write()
876-
877-
@property
878-
def blue_brightness(self):
879-
"""The blue brightness for all channels (i.e. B0, B1, B2, and B3). This is a 7-bit
880-
value from 0-127.
881-
"""
882-
return self._bcb
883-
884-
@blue_brightness.setter
885-
def blue_brightness(self, val):
886-
assert 0 <= val <= 127
887-
self._bcb = val
888-
if self.auto_show:
889-
self._write()
890-
891-
# Define index and length properties to set and get each channel as
878+
# atomic RGB tuples. This provides a similar feel as using neopixels.
879+
def __len__(self):
880+
"""Retrieve TLC5975 the total number of Pixels available."""
881+
return self.pixel_count
892882

883+
def __getitem__(self, key):
893884
"""
894885
Retrieve the R, G, B values for the provided channel as a 3-tuple.
895886

examples/tlc59711_dev.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
"""TLC5971 / TLC59711 Multi."""
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# CircuitPython
4+
5+
# SPDX-FileCopyrightText: 2021 s-light
6+
# SPDX-License-Identifier: MIT
7+
# Author Stefan Krüger (s-light)
8+
9+
"""TLC5971 / TLC59711 Multi Development."""
210

311
__doc__ = """
412
TLC59711 development helper.
@@ -101,7 +109,10 @@ def timeit_call(message, test_function, loop_count=1000):
101109
# "{:>8.2f}ms".format(3.56)
102110
print(
103111
"{call_duration:>10.4f}ms\t{message}"
104-
"".format(call_duration=(duration / loop_count) * 1000, message=message,)
112+
"".format(
113+
call_duration=(duration / loop_count) * 1000,
114+
message=message,
115+
)
105116
)
106117

107118

@@ -408,15 +419,22 @@ def test_bcdata():
408419
"bcr: {:>3}\n"
409420
"bcg: {:>3}\n"
410421
"bcb: {:>3}\n"
411-
"".format(pixels.bcr, pixels.bcg, pixels.bcb,)
422+
"".format(
423+
pixels.bcr,
424+
pixels.bcg,
425+
pixels.bcb,
426+
)
412427
)
413428
# calculate bc values
414429
Ioclmax = adafruit_tlc59711.TLC59711.calculate_Ioclmax(Riref=2.7)
415430
print("Ioclmax = {}".format(Ioclmax))
416431
Riref = adafruit_tlc59711.TLC59711.calculate_Riref(Ioclmax=Ioclmax)
417432
print("Riref = {}".format(Riref))
418433
BCValues = adafruit_tlc59711.TLC59711.calculate_BCData(
419-
Ioclmax=Ioclmax, IoutR=18, IoutG=11, IoutB=13,
434+
Ioclmax=Ioclmax,
435+
IoutR=18,
436+
IoutG=11,
437+
IoutB=13,
420438
)
421439
# (127, 77, 91)
422440
print("BCValues = {}".format(BCValues))
@@ -431,7 +449,11 @@ def test_bcdata():
431449
"bcr: {:>3}\n"
432450
"bcg: {:>3}\n"
433451
"bcb: {:>3}\n"
434-
"".format(pixels.bcr, pixels.bcg, pixels.bcb,)
452+
"".format(
453+
pixels.bcr,
454+
pixels.bcg,
455+
pixels.bcb,
456+
)
435457
)
436458
time.sleep(2)
437459

examples/tlc59711_fancyled.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# -*- coding: utf-8 -*-
33
# CircuitPython
44

5+
# SPDX-FileCopyrightText: 2021 s-light
6+
# SPDX-License-Identifier: MIT
7+
# Author Stefan Krüger (s-light)
8+
59
"""TLC59711 & FancyLED."""
610

711
__doc__ = """
@@ -38,7 +42,10 @@
3842
print(42 * "*")
3943
print("init TLC5957")
4044
NUM_LEDS = 16
41-
pixels = adafruit_tlc59711.TLC59711(spi=spi, pixel_count=NUM_LEDS,)
45+
pixels = adafruit_tlc59711.TLC59711(
46+
spi=spi,
47+
pixel_count=NUM_LEDS,
48+
)
4249

4350
print("pixel_count", pixels.pixel_count)
4451
print("chip_count", pixels.chip_count)

examples/tlc59711_fastset.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
"""TLC5971 / TLC59711."""
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# CircuitPython
4+
5+
# SPDX-FileCopyrightText: 2021 s-light
6+
# SPDX-License-Identifier: MIT
7+
# Author Stefan Krüger (s-light)
8+
9+
"""TLC5971 / TLC59711 Example."""
210

311
__doc__ = """
412
tlc59711_fastset.py - TLC59711 fast set example.
@@ -10,6 +18,7 @@
1018
Enjoy the colors :-)
1119
"""
1220

21+
1322
import time
1423

1524
import board
@@ -58,7 +67,10 @@ def test_main():
5867
print(42 * "*")
5968

6069
bcvalues = adafruit_tlc59711.TLC59711.calculate_BCData(
61-
Ioclmax=18, IoutR=18, IoutG=11, IoutB=13,
70+
Ioclmax=18,
71+
IoutR=18,
72+
IoutG=11,
73+
IoutB=13,
6274
)
6375
print("bcvalues = {}".format(bcvalues))
6476
pixels.bcr = bcvalues[0]

examples/tlc59711_singlechip_autoshow.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
"""TLC5971 / TLC59711."""
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# CircuitPython
4+
5+
# SPDX-FileCopyrightText: 2021 s-light
6+
# SPDX-License-Identifier: MIT
7+
# Author Stefan Krüger (s-light)
8+
9+
"""TLC5971 / TLC59711 Example."""
210

311
__doc__ = """
412
tlc59711_singlechip_autoshow.py - TLC59711AutoShow minimal usage example.

examples/tlc59711_test_bcdata.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
"""TLC5971 / TLC59711 Multi."""
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# CircuitPython
4+
5+
# SPDX-FileCopyrightText: 2021 s-light
6+
# SPDX-License-Identifier: MIT
7+
# Author Stefan Krüger (s-light)
8+
9+
"""TLC5971 / TLC59711 Test BCData."""
210

311
__doc__ = """
412
tlc59711_test_bcdata.py.
@@ -43,7 +51,10 @@ def main_loop():
4351
except ValueError as e:
4452
print("Exception: ", e)
4553
BCValues = adafruit_tlc59711.TLC59711.calculate_BCData(
46-
Ioclmax=Ioclmax, IoutR=IoutR, IoutG=IoutG, IoutB=IoutB,
54+
Ioclmax=Ioclmax,
55+
IoutR=IoutR,
56+
IoutG=IoutG,
57+
IoutB=IoutB,
4758
)
4859
pixels.bcr = BCValues[0]
4960
pixels.bcg = BCValues[1]
@@ -52,7 +63,11 @@ def main_loop():
5263
"bcr: {:>3}\n"
5364
"bcg: {:>3}\n"
5465
"bcb: {:>3}\n"
55-
"".format(pixels.bcr, pixels.bcg, pixels.bcb,)
66+
"".format(
67+
pixels.bcr,
68+
pixels.bcg,
69+
pixels.bcb,
70+
)
5671
)
5772
pixels.update_BCData()
5873
pixels.show()
@@ -77,7 +92,10 @@ def test_main():
7792
Riref = adafruit_tlc59711.TLC59711.calculate_Riref(Ioclmax=Ioclmax)
7893
print("Riref = {}".format(Riref))
7994
BCValues = adafruit_tlc59711.TLC59711.calculate_BCData(
80-
Ioclmax=Ioclmax, IoutR=18, IoutG=11, IoutB=13,
95+
Ioclmax=Ioclmax,
96+
IoutR=18,
97+
IoutG=11,
98+
IoutB=13,
8199
)
82100
# (127, 77, 91)
83101
print("BCValues = {}".format(BCValues))

pylama.ini

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: 2021 s-light
2+
# SPDX-License-Identifier: Unlicense
3+
14
[pylama:pycodestyle]
25
max_line_length = 100
36

0 commit comments

Comments
 (0)