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

py: add Captouch debug overlay, add System menu

parent bbc95701
No related branches found
No related tags found
No related merge requests found
...@@ -94,12 +94,24 @@ menu_badge = SimpleMenu( ...@@ -94,12 +94,24 @@ menu_badge = SimpleMenu(
], ],
vm, vm,
) )
menu_system = SimpleMenu(
[
MenuItemBack(),
MenuItemForeground("Settings", menu_settings),
MenuItemNoop("Disk Mode"),
MenuItemNoop("About"),
MenuItemNoop("Reboot"),
],
vm,
)
menu_main = SunMenu( menu_main = SunMenu(
[ [
MenuItemForeground("Badge", menu_badge), MenuItemForeground("Badge", menu_badge),
MenuItemForeground("Music", menu_music), MenuItemForeground("Music", menu_music),
MenuItemForeground("Apps", menu_apps), MenuItemForeground("Apps", menu_apps),
MenuItemForeground("Settings", menu_settings), MenuItemForeground("System", menu_system),
], ],
vm, vm,
) )
...@@ -126,5 +138,17 @@ debug = overlays.OverlayDebug() ...@@ -126,5 +138,17 @@ debug = overlays.OverlayDebug()
debug.add_fragment(overlays.DebugReactorStats(reactor)) debug.add_fragment(overlays.DebugReactorStats(reactor))
compositor.add_overlay(debug) compositor.add_overlay(debug)
debug_touch = overlays.OverlayCaptouch()
# Tie compositor's debug touch overlay to setting.
def _onoff_debug_touch_update() -> None:
compositor.enabled[overlays.OverlayKind.Touch] = settings.onoff_debug_touch.value
_onoff_debug_touch_update()
settings.onoff_debug_touch.subscribe(_onoff_debug_touch_update)
compositor.add_overlay(debug_touch)
reactor.set_top(compositor) reactor.set_top(compositor)
reactor.run() reactor.run()
...@@ -293,8 +293,10 @@ class SettingsMenu(SimpleMenu): ...@@ -293,8 +293,10 @@ class SettingsMenu(SimpleMenu):
# Actual tunables / settings. # Actual tunables / settings.
onoff_debug = OnOffTunable("Debug Overlay", "system.debug", False) onoff_debug = OnOffTunable("Debug Overlay", "system.debug", False)
onoff_debug_touch = OnOffTunable("Touch Overlay", "system.debug_touch", False)
all_settings: List[UnaryTunable] = [ all_settings: List[UnaryTunable] = [
onoff_debug, onoff_debug,
onoff_debug_touch,
] ]
......
...@@ -8,6 +8,7 @@ etc. ...@@ -8,6 +8,7 @@ etc.
from st3m import Responder, Ctx, InputState, Reactor from st3m import Responder, Ctx, InputState, Reactor
from st3m.goose import Dict, Enum, List, ABCBase, abstractmethod from st3m.goose import Dict, Enum, List, ABCBase, abstractmethod
from st3m.utils import tau
class OverlayKind(Enum): class OverlayKind(Enum):
...@@ -15,11 +16,13 @@ class OverlayKind(Enum): ...@@ -15,11 +16,13 @@ class OverlayKind(Enum):
Indicators = 0 Indicators = 0
# Naughty debug developers for naughty developers and debuggers. # Naughty debug developers for naughty developers and debuggers.
Debug = 1 Debug = 1
Touch = 2
_all_kinds = [ _all_kinds = [
OverlayKind.Indicators, OverlayKind.Indicators,
OverlayKind.Debug, OverlayKind.Debug,
OverlayKind.Touch,
] ]
...@@ -138,3 +141,47 @@ class OverlayDebug(Overlay): ...@@ -138,3 +141,47 @@ class OverlayDebug(Overlay):
ctx.gray(0).rectangle(-120, 80, 240, 12).fill() ctx.gray(0).rectangle(-120, 80, 240, 12).fill()
ctx.gray(1).move_to(0, 86).text(self.text()) ctx.gray(1).move_to(0, 86).text(self.text())
ctx.restore() ctx.restore()
class OverlayCaptouch(Overlay):
kind = OverlayKind.Touch
class Dot(Responder):
def __init__(self, ix: int) -> None:
self.ix = ix
self.phi = 0.0
self.rad = 0.0
self.pressed = False
def think(self, s: InputState, delta_ms: int) -> None:
self.pressed = s.petal_pressed[self.ix]
(rad, phi) = s.petal_pos[self.ix]
self.phi = phi
self.rad = rad
def draw(self, ctx: Ctx) -> None:
if not self.pressed:
return
a = (tau / 10) * self.ix
ctx.rotate(-a)
ctx.translate(0, -80)
offs_x = -self.phi / 1000
offs_y = -self.rad / 1000
ctx.rectangle(-5 + offs_x, -5 + offs_y, 10, 10)
ctx.rgb(1, 0, 1)
ctx.fill()
def __init__(self) -> None:
self.dots = [self.Dot(i) for i in range(10)]
def think(self, ins: InputState, delta_ms: int) -> None:
for dot in self.dots:
dot.think(ins, delta_ms)
def draw(self, ctx: Ctx) -> None:
for dot in self.dots:
ctx.save()
dot.draw(ctx)
ctx.restore()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment