Skip to content
Snippets Groups Projects
Commit 2b007357 authored by iggy's avatar iggy
Browse files

py: captouch-demo: autocalib button added (app enter), fixes for misc captouch issues

parent c446dbdf
No related branches found
No related tags found
No related merge requests found
from st3m import logging
log = logging.Log(__name__, level=logging.INFO)
log.info("import")
import cmath
import math
import time
import hardware
from st3m import utils, application
from st3m import utils, application, ui, event
class Dot:
......@@ -28,6 +33,20 @@ class Dot:
class CapTouchDemo(application.Application):
def on_init(self):
self.dots = []
self.last_calib = None
self.ui_autocalib = ui.IconLabel("Autocalib done", size=30)
self.add_event(
event.Event(
name="captouch_autocalib",
action=self.do_autocalib,
condition=lambda data: data["type"] == "button"
and data["index"] == 0
and data["change"]
and data["from"] == 2,
enabled=True,
)
)
def main_foreground(self):
self.dots = []
......@@ -36,7 +55,9 @@ class CapTouchDemo(application.Application):
size += int(
max(
0,
sum([hardware.captouch_get_petal_pad(i, x) for x in range(0, 3 + 1)])
sum(
[hardware.captouch_get_petal_pad(i, x) for x in range(0, 3 + 1)]
)
/ 8000,
)
)
......@@ -48,9 +69,18 @@ class CapTouchDemo(application.Application):
self.dots.append(Dot(size, x.imag, x.real))
def on_draw(self, ctx):
print(self.last_calib)
ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill()
for i, dot in enumerate(self.dots):
dot.draw(i, ctx)
if not self.last_calib is None and self.last_calib > 0:
self.last_calib -= 1
self.ui_autocalib.draw(ctx)
def do_autocalib(self, data):
log.info("Performing captouch autocalibration")
hardware.captouch_autocalib()
self.last_calib = 50
app = CapTouchDemo("cap touch")
......@@ -35,6 +35,7 @@ class Application:
name="exit",
action=self.exit,
condition=lambda e: e["type"] == "button"
and e["index"] == 1
and e.get("from") == 2
and e["change"],
)
......
......@@ -21,9 +21,9 @@ class Control:
self.menu = menu.MenuControl(self)
def draw(self):
def draw(self, ctx):
self.ui.value = self.get_value()
self.ui.draw()
self.ui.draw(ctx)
def get_normal_value(self):
v = self.get_value()
......@@ -88,7 +88,6 @@ class ControlKnob(ControlFloat):
def enter(self):
# repeat action with current value
self.set_value(self.get_value())
self.draw()
def scroll(self, delta):
if self.on_mod:
......@@ -99,7 +98,6 @@ class ControlKnob(ControlFloat):
v = self.get_value()
v_new = max(self.min, min(self.max, v + delta * self.step))
self.set_value(v_new)
self.draw()
def touch_1d(self, x, z):
if z > 0: # Inital Contact
......@@ -138,7 +136,6 @@ class ControlSlide(ControlFloat):
if self.do_reset:
self.set_value(self._saved_value)
self._saved_value = None
self.draw()
class ControlString(Control):
......
......@@ -239,6 +239,8 @@ def on_scroll(d):
menu_offset = None
last = time.ticks_ms()
def on_scroll_captouch(d):
active_menu = get_active_menu()
if active_menu is None:
......@@ -269,8 +271,6 @@ def on_scroll_captouch(d):
if diff < 300:
active_menu.enter_menu()
# active_menu.rotate_to(a)
......@@ -298,13 +298,14 @@ def on_touch_1d(d):
z = -1
log.debug(f"menu: touch_1d ({v},{z})")
hovered = active_menu.get_hovered_item()
petal_idx = d["index"]
petal_item = active_menu.items_petal[petal_idx]
if petal_item:
petal_item.touch_1d(v, z)
if d["index"] == 8:
hovered = active_menu.get_hovered_item()
if hasattr(hovered, "touch_1d"):
hovered.touch_1d(v, z)
......@@ -336,10 +337,14 @@ event.Event(
enabled=True,
)
event.Event(name="menu rotation captouch",group_id="menu",
condition=lambda e: e["type"] =="captouch" and (e["value"] == 1 or e["change"]) and e["index"]==2,
event.Event(
name="menu rotation captouch",
group_id="menu",
condition=lambda e: e["type"] == "captouch"
and (e["value"] == 1 or e["change"])
and e["index"] == 2,
action=on_scroll_captouch,
enabled=True
enabled=True,
)
......@@ -354,11 +359,9 @@ event.Event(
event.Event(
name="menu 1d captouch",
group_id="menu",
condition=lambda e: e["type"] == "captouch"
and (e["value"] == 1 or e["change"])
and e["index"] % 2 == 1,
condition=lambda e: e["type"] == "captouch" and (e["value"] == 1 or e["change"]),
action=on_touch_1d,
enabled=False,
enabled=True,
)
event.Event(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment