Skip to content

Commit 6a03d5e

Browse files
committed
myoy + pad index awareness
1 parent b6aa649 commit 6a03d5e

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

adafruit_neotrellis/multitrellis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
__version__ = "0.0.0-auto.0"
3030
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_neotrellis.git"
3131

32-
from typing import List, Sequence
32+
from typing import List, Optional, Sequence
3333

3434
from adafruit_neotrellis.neotrellis import CallbackType, NeoTrellis
3535
from adafruit_seesaw.neopixel import PixelType
@@ -69,6 +69,8 @@ def __init__(self, neotrellis_array: List[List[NeoTrellis]]):
6969

7070
t.x_base = x_base
7171
t.y_base = y_base
72+
t.pad_x = px
73+
t.pad_y = py
7274

7375
self._width = col_size_sum[self._cols - 1]
7476
self._height = row_size_sum[self._rows - 1]
@@ -123,7 +125,6 @@ def set_callback(self, x: int, y: int, function: CallbackType):
123125
pad = self._key_pads[y][x]
124126
pad.callbacks[pad.key_index(x, y)] = function
125127

126-
127128
def get_callback(self, x: int, y: int) -> Optional[CallbackType]:
128129
"""Get a callback function for when an event for the key at index x, y
129130
(measured from the top lefthand corner) is detected."""

adafruit_neotrellis/neotrellis.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_neotrellis.git"
4848

4949
from time import sleep
50-
from typing import Callable, List, Optional
50+
from typing import Callable, List, Optional, TypeAlias
5151

5252
from adafruit_seesaw.keypad import KeyEvent, Keypad, ResponseType
5353
from adafruit_seesaw.neopixel import NeoPixel
@@ -63,7 +63,7 @@
6363
_NEO_TRELLIS_NUM_KEYS = const(64)
6464

6565

66-
CallbackType = Callable[[KeyEvent], None]
66+
CallbackType: TypeAlias = Callable[[KeyEvent], None]
6767

6868

6969
class NeoTrellis(Keypad):
@@ -73,15 +73,18 @@ class NeoTrellis(Keypad):
7373
height: int
7474
x_base: int
7575
y_base: int
76+
pad_x: int
77+
pad_y: int
7678
interrupt_enabled: bool
7779
callbacks: List[Optional[CallbackType]]
7880
pixels: NeoPixel
7981

80-
def __init__(self, i2c_bus, interrupt=False,
81-
addr=_NEO_TRELLIS_ADDR, drdy=None,
82-
width=_NEO_TRELLIS_NUM_COLS,
83-
height=_NEO_TRELLIS_NUM_ROWS,
84-
x_base = 0, y_base = 0):
82+
def __init__(self, i2c_bus, interrupt: bool = False,
83+
addr: int = _NEO_TRELLIS_ADDR, drdy = None,
84+
width: int = _NEO_TRELLIS_NUM_COLS,
85+
height: int = _NEO_TRELLIS_NUM_ROWS,
86+
x_base: int = 0, y_base: int = 0,
87+
pad_x: int = 0, pad_y: int = 0):
8588
super().__init__(i2c_bus, addr, drdy)
8689
self.width = width
8790
self.height = height
@@ -91,18 +94,21 @@ def __init__(self, i2c_bus, interrupt=False,
9194
self.callbacks = [None] * _NEO_TRELLIS_NUM_KEYS
9295
self.pixels = NeoPixel(self, _NEO_TRELLIS_NEOPIX_PIN, _NEO_TRELLIS_NUM_KEYS)
9396

94-
def activate_key(self, key: int, edge: int, enable: bool = True):
97+
def activate_key(self, key: int, edge: int, enable: bool = True) -> None:
9598
"""Activate or deactivate a key on the trellis. Key is the key number from
9699
0 to 16. Edge specifies what edge to register an event on and can be
97100
NeoTrellis.EDGE_FALLING or NeoTrellis.EDGE_RISING. enable should be set
98101
to True if the event is to be enabled, or False if the event is to be
99102
disabled."""
100103
self.set_event(key, edge, enable)
101104

102-
def clear(self):
105+
def clear(self) -> None:
103106
self.pixels.fill((0, 0, 0))
104107

105-
def sync(self):
108+
def show(self) -> None:
109+
self.pixels.show()
110+
111+
def sync(self) -> None:
106112
"""read any events from the Trellis hardware and call associated
107113
callbacks"""
108114
available = self.count
@@ -120,9 +126,9 @@ def sync(self):
120126
):
121127
callback(evt)
122128

123-
def local_key_index(self, x, y):
129+
def local_key_index(self, x, y) -> int:
124130
return int(y * self.width + x)
125131

126-
def key_index(self, x, y):
132+
def key_index(self, x, y) -> int:
127133
return int((y - self.y_base) * self.width + (x - self.x_base))
128134

0 commit comments

Comments
 (0)