Skip to content
Snippets Groups Projects
Commit 6ae71812 authored by q3k's avatar q3k
Browse files

py: update InputState to use new st3m captouch structures

parent 70443571
No related branches found
No related tags found
No related merge requests found
...@@ -55,9 +55,10 @@ class CapTouchDemo(application.Application): ...@@ -55,9 +55,10 @@ class CapTouchDemo(application.Application):
super().think(ins, delta_ms) super().think(ins, delta_ms)
self.dots = [] self.dots = []
for i in range(10): for i in range(10):
(rad, phi) = ins.petal_pos[i] petal = ins.captouch.petals[i]
(rad, phi) = petal.position
size = 4 size = 4
if ins.petal_pressed[i]: if petal.pressed:
size += 4 size += 4
x = 70 + (rad / 1000) + 0j x = 70 + (rad / 1000) + 0j
x += (phi / 600) * 1j x += (phi / 600) * 1j
......
...@@ -46,7 +46,8 @@ def run(ins: InputState) -> None: ...@@ -46,7 +46,8 @@ def run(ins: InputState) -> None:
global octave global octave
global synths global synths
for i in range(10): for i in range(10):
if ins.petal_pressed[i]: petal = ins.captouch.petals[i]
if petal.pressed:
if i == 4: if i == 4:
octave = -1 octave = -1
adjust_playing_field_to_octave() adjust_playing_field_to_octave()
......
...@@ -18,15 +18,12 @@ class InputState: ...@@ -18,15 +18,12 @@ class InputState:
def __init__( def __init__(
self, self,
petal_pressed: List[bool], captouch: captouch.CaptouchState,
# petal_pads: List[List[int]],
petal_pos: List[Tuple[int, int]],
left_button: int, left_button: int,
right_button: int, right_button: int,
) -> None: ) -> None:
self.petal_pressed = petal_pressed
# self.petal_pads = petal_pads # self.petal_pads = petal_pads
self.petal_pos = petal_pos self.captouch = captouch
self.left_button = left_button self.left_button = left_button
self.right_button = right_button self.right_button = right_button
...@@ -37,17 +34,10 @@ class InputState: ...@@ -37,17 +34,10 @@ class InputState:
Reactor. Reactor.
""" """
cts = captouch.read() cts = captouch.read()
petal_pressed = [cts.petals[i].pressed for i in range(10)]
# petal_pads = [
# [hardware.captouch_get_petal_pad(petal_ix, pad_ix) for pad_ix in range(3)]
# for petal_ix in range(10)
# ]
petal_pos = [cts.petals[petal_ix].position for petal_ix in range(10)]
left_button = hardware.left_button_get() left_button = hardware.left_button_get()
right_button = hardware.right_button_get() right_button = hardware.right_button_get()
return InputState(petal_pressed, petal_pos, left_button, right_button) return InputState(cts, left_button, right_button)
class RepeatSettings: class RepeatSettings:
...@@ -281,9 +271,9 @@ class CaptouchState: ...@@ -281,9 +271,9 @@ class CaptouchState:
def __init__(self) -> None: def __init__(self) -> None:
self.petals = [PetalState(i) for i in range(10)] self.petals = [PetalState(i) for i in range(10)]
def _update(self, ts: int, hr: InputState) -> None: def _update(self, ts: int, ins: InputState) -> None:
for i, petal in enumerate(self.petals): for i, petal in enumerate(self.petals):
petal._update(ts, hr.petal_pressed[i]) petal._update(ts, ins.captouch.petals[i].pressed)
def _ignore_pressed(self) -> None: def _ignore_pressed(self) -> None:
for petal in self.petals: for petal in self.petals:
......
...@@ -154,8 +154,8 @@ class OverlayCaptouch(Overlay): ...@@ -154,8 +154,8 @@ class OverlayCaptouch(Overlay):
self.pressed = False self.pressed = False
def think(self, s: InputState, delta_ms: int) -> None: def think(self, s: InputState, delta_ms: int) -> None:
self.pressed = s.petal_pressed[self.ix] self.pressed = s.captouch.petals[self.ix].pressed
(rad, phi) = s.petal_pos[self.ix] (rad, phi) = s.captouch.petals[self.ix].position
self.phi = phi self.phi = phi
self.rad = rad self.rad = rad
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment