Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit c21bc15

Browse files
committed
made neopixel lib work on cpx and clue
1 parent 43d789c commit c21bc15

File tree

6 files changed

+46
-39
lines changed

6 files changed

+46
-39
lines changed

src/clue/adafruit_clue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
abs_path = pathlib.Path(__file__).parent.absolute()
6868
sys.path.insert(0, os.path.join(abs_path))
6969
import neopixel
70+
import constants as CONSTANTS
7071

7172
# REVISED VERSION OF THE ADAFRUIT CLUE LIBRARY FOR DSX
7273

@@ -198,7 +199,7 @@ class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-met
198199
RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
199200

200201
def __init__(self):
201-
self._pixel = neopixel.NeoPixel(0, 1)
202+
self._pixel = neopixel.NeoPixel(pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB)
202203

203204
@property
204205
def pixel(self):

src/clue/board.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ def show(self, group):
1111

1212

1313
DISPLAY = Display()
14+
NEOPIXEL = "D00"

src/clue/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CPX = "CPX"
2+
CLUE = "CLUE"
3+
PIXELS = "pixels"
4+
5+
CLUE_PIN = "D18"

src/clue/digitalio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class DigitalInOut:
88
def __init__(self, pin):
9+
self.pin = pin
910
pass
1011

1112
def deinit(self):

src/clue/neopixel_write.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,43 @@
33
# original implementation docs for neopixel_write:
44
# https://circuitpython.readthedocs.io/en/5.0.x/shared-bindings/neopixel_write/__init__.html
55

6+
import constants as CONSTANTS
7+
import common
8+
from adafruit_circuitplayground import cp
9+
610

711
def neopixel_write(gpio, buf):
812
"""Write buf out on the given DigitalInOut."""
9-
print(tuple(buf))
13+
14+
if len(tuple(buf)) > 0:
15+
# if we are explicitly given
16+
# the clue pin, that means that
17+
# the clue is definitely the active device
18+
# because the constructor for the
19+
# clue is what calls neopixel
20+
# with the clue pin argument
21+
if gpio.pin != CONSTANTS.CLUE_PIN:
22+
send_cpx(buf)
23+
send_clue(buf)
24+
25+
26+
def send_clue(buf):
27+
sendable_json = {CONSTANTS.PIXELS: [tuple(buf)]}
28+
common.utils.send_to_simulator(sendable_json, CONSTANTS.CLUE)
29+
30+
31+
def send_cpx(buf):
32+
buf_list = list(buf)
33+
ret_list = []
34+
temp_list = []
35+
for idx, elem in enumerate(buf_list):
36+
if idx % 3 == 0 and idx != 0:
37+
ret_list.append(tuple(temp_list))
38+
temp_list = []
39+
temp_list.append(elem)
40+
41+
if len(temp_list) == 3:
42+
ret_list.append(tuple(temp_list))
43+
44+
max_index = min(len(ret_list), 10)
45+
cp.pixels[0:max_index] = ret_list[0:max_index]

src/micropython/neopixel.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)