omnipython-apps 0.1.4.dev8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apps/__init__.py +5 -0
- apps/about/__init__.py +257 -0
- apps/about/app.json +1 -0
- apps/about/credits.py +12 -0
- apps/about/facts.py +398 -0
- apps/about/fonts/OFL.txt +93 -0
- apps/about/fonts/latin1_14.bin +0 -0
- apps/about/fonts/latin1_16.bin +0 -0
- apps/about/fonts/latin1_24.bin +0 -0
- apps/about/fonts/latin1_32.bin +0 -0
- apps/about/fonts/latin1_40.bin +0 -0
- apps/backline/__init__.py +58 -0
- apps/backline/app.json +1 -0
- apps/backline/app.py +475 -0
- apps/backline/art.py +717 -0
- apps/backline/ask.py +781 -0
- apps/backline/box.py +502 -0
- apps/backline/cast.py +137 -0
- apps/backline/desk/__init__.py +329 -0
- apps/backline/desk/editor.py +331 -0
- apps/backline/desk/grid.py +154 -0
- apps/backline/desk/look.py +169 -0
- apps/backline/desk/pedals.py +102 -0
- apps/backline/desk/perform.py +157 -0
- apps/backline/desk/prompt.py +210 -0
- apps/backline/desk/strip.py +159 -0
- apps/backline/desk_main.py +226 -0
- apps/backline/engine.py +622 -0
- apps/backline/floor.py +509 -0
- apps/backline/footswitch.py +119 -0
- apps/backline/glyphs.py +82 -0
- apps/backline/kits.py +428 -0
- apps/backline/midipedal.py +362 -0
- apps/backline/page_data.py +413 -0
- apps/backline/parts.py +145 -0
- apps/backline/pedal.py +107 -0
- apps/backline/remote.py +134 -0
- apps/backline/songs/ballad_68.json +1 -0
- apps/backline/songs/bossa.json +1 -0
- apps/backline/songs/country_train.json +1 -0
- apps/backline/songs/funk.json +1 -0
- apps/backline/songs/metal.json +1 -0
- apps/backline/songs/pop.json +1 -0
- apps/backline/songs/rock.json +1 -0
- apps/backline/songs/shuffle.json +1 -0
- apps/battery/__init__.py +101 -0
- apps/battery/app.json +1 -0
- apps/bit_world/act_deck.py +683 -0
- apps/bit_world/act_game.py +762 -0
- apps/bit_world/act_pet.py +1032 -0
- apps/bit_world/app.json +1 -0
- apps/bit_world/bit_output.py +45 -0
- apps/bit_world/bit_palette.py +503 -0
- apps/bit_world/bit_sound.py +431 -0
- apps/bit_world/bit_sprites.py +632 -0
- apps/bit_world/bit_world.py +534 -0
- apps/btreceiver/__init__.py +690 -0
- apps/btreceiver/app.json +1 -0
- apps/btreceiver/chime.py +155 -0
- apps/btreceiver/demo.py +529 -0
- apps/btreceiver/screen.py +633 -0
- apps/camera/__init__.py +316 -0
- apps/camera/app.json +1 -0
- apps/card/__init__.py +113 -0
- apps/card/app.json +1 -0
- apps/cast/__init__.py +631 -0
- apps/cast/app.json +1 -0
- apps/cast/receivers.py +193 -0
- apps/chess/__init__.py +18 -0
- apps/chess/app.json +1 -0
- apps/chess/app.py +922 -0
- apps/chess/art.py +323 -0
- apps/chess/ble.py +411 -0
- apps/chess/engine.py +925 -0
- apps/chess/game.py +327 -0
- apps/chess/net.py +261 -0
- apps/clock/__init__.py +38 -0
- apps/clock/app.json +1 -0
- apps/detect/__init__.py +214 -0
- apps/detect/app.json +1 -0
- apps/fmsynth/__init__.py +41 -0
- apps/fmsynth/algorithms.py +61 -0
- apps/fmsynth/app.json +1 -0
- apps/fmsynth/app.py +355 -0
- apps/fmsynth/editor.py +206 -0
- apps/fmsynth/engine.py +257 -0
- apps/fmsynth/meters.py +262 -0
- apps/fmsynth/midi.py +375 -0
- apps/fmsynth/panel_view.py +1071 -0
- apps/fmsynth/patches/fmsynth-01.syx +0 -0
- apps/fmsynth/settings.py +138 -0
- apps/fmsynth/voice.py +398 -0
- apps/gamepad/__init__.py +685 -0
- apps/gamepad/app.json +1 -0
- apps/gamepad/pad.py +94 -0
- apps/gamepad/watch.py +352 -0
- apps/hidden/__init__.py +72 -0
- apps/hidden/app.json +1 -0
- apps/home/__init__.py +483 -0
- apps/home/app.json +1 -0
- apps/home/main.py +36 -0
- apps/homeassistant/__init__.py +213 -0
- apps/homeassistant/api.py +104 -0
- apps/homeassistant/app.json +1 -0
- apps/huey/__init__.py +287 -0
- apps/huey/acting.py +184 -0
- apps/huey/actor.py +194 -0
- apps/huey/app.json +1 -0
- apps/huey/client.py +125 -0
- apps/huey/servers.py +121 -0
- apps/huey/settings.example.json +8 -0
- apps/huey/settings.py +97 -0
- apps/huey/turn.py +504 -0
- apps/huey/voice.py +217 -0
- apps/info/__init__.py +810 -0
- apps/info/app.json +1 -0
- apps/lora/__init__.py +62 -0
- apps/lora/app.json +1 -0
- apps/manifest.py +71 -0
- apps/medialink_baby_monitor/__init__.py +222 -0
- apps/medialink_baby_monitor/app.json +1 -0
- apps/medialink_doorbell/__init__.py +251 -0
- apps/medialink_doorbell/app.json +1 -0
- apps/medialink_hands_free/__init__.py +217 -0
- apps/medialink_hands_free/app.json +1 -0
- apps/medialink_surveillance_camera/__init__.py +258 -0
- apps/medialink_surveillance_camera/app.json +1 -0
- apps/medialink_video_doorbell/__init__.py +289 -0
- apps/medialink_video_doorbell/app.json +1 -0
- apps/medialink_videophone/__init__.py +273 -0
- apps/medialink_videophone/app.json +1 -0
- apps/medialink_walkie_talkie/__init__.py +228 -0
- apps/medialink_walkie_talkie/app.json +1 -0
- apps/midicontroller/__init__.py +774 -0
- apps/midicontroller/app.json +1 -0
- apps/midicontroller/links.py +421 -0
- apps/midicontroller/surface.py +343 -0
- apps/midiengine/__init__.py +977 -0
- apps/midiengine/app.json +1 -0
- apps/midiengine/banks.py +85 -0
- apps/midiengine/midiin.py +165 -0
- apps/midiengine/player.py +392 -0
- apps/midiengine/umidiparser.py +1413 -0
- apps/mp3/__init__.py +240 -0
- apps/mp3/app.json +1 -0
- apps/perch/__init__.py +119 -0
- apps/perch/app.json +1 -0
- apps/perch/huey.py +481 -0
- apps/perch/huey_props.py +386 -0
- apps/perch/huey_shift.py +42 -0
- apps/perch/huey_views.py +296 -0
- apps/perch/scene_bench.py +680 -0
- apps/perch/scene_coast.py +479 -0
- apps/perch/scene_desk.py +492 -0
- apps/perch/stage.py +1274 -0
- apps/perch/vec.py +366 -0
- apps/repl/__init__.py +325 -0
- apps/repl/app.json +1 -0
- apps/roku/__init__.py +156 -0
- apps/roku/app.json +1 -0
- apps/rokucam/__init__.py +362 -0
- apps/rokucam/app.json +1 -0
- apps/security/__init__.py +261 -0
- apps/security/app.json +1 -0
- apps/settings/__init__.py +221 -0
- apps/settings/app.json +1 -0
- apps/shell/__init__.py +33 -0
- apps/shell/app.json +1 -0
- apps/spotify/__init__.py +669 -0
- apps/spotify/app.json +1 -0
- apps/spotify/screen.py +82 -0
- apps/steps/__init__.py +58 -0
- apps/steps/app.json +1 -0
- apps/stompbox/__init__.py +31 -0
- apps/stompbox/app.json +1 -0
- apps/stompbox/app.py +668 -0
- apps/stompbox/boards.json +20 -0
- apps/stompbox/effects.py +241 -0
- apps/stompbox/engine.py +340 -0
- apps/stompbox/footswitch.py +331 -0
- apps/stompbox/inputs.py +449 -0
- apps/stompbox/meter.py +72 -0
- apps/stompbox/outputs.py +135 -0
- apps/stompbox/pedals.txt +45 -0
- apps/stompbox/presets.py +106 -0
- apps/stompbox/styles.py +135 -0
- apps/stompbox/ui.py +817 -0
- apps/stompbox/wavfile.py +73 -0
- apps/synthstation/__init__.py +20 -0
- apps/synthstation/app.json +1 -0
- apps/synthstation/audio.py +397 -0
- apps/synthstation/catalog.py +50 -0
- apps/synthstation/meters.py +136 -0
- apps/synthstation/midi.py +380 -0
- apps/synthstation/pads.py +177 -0
- apps/synthstation/parts.py +128 -0
- apps/synthstation/station.py +1069 -0
- apps/system/__init__.py +11 -0
- apps/system/app.json +1 -0
- apps/touchcal/__init__.py +324 -0
- apps/touchcal/app.json +1 -0
- apps/touchcal/fit.py +262 -0
- apps/wake/__init__.py +268 -0
- apps/wake/app.json +1 -0
- apps/wake/feed.py +155 -0
- apps/watch/__init__.py +355 -0
- apps/watch/app.json +1 -0
- apps/watch/faces.py +35 -0
- apps/watch/wheel.py +157 -0
- apps/weather/__init__.py +278 -0
- apps/weather/app.json +1 -0
- apps/weather/icons.py +172 -0
- apps/weather/sizing.py +71 -0
- apps/weather/zippad.py +172 -0
- omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
- omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
apps/gamepad/pad.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The on-screen gamepad's state, and the USB report it sends.
|
|
5
|
+
|
|
6
|
+
The report is the one ``usb_hid.Device.GAMEPAD`` takes, seven bytes: sixteen
|
|
7
|
+
buttons as a little-endian mask (bit 0 is button 1), the hat (0 centred, 1
|
|
8
|
+
north to 8 north-west, clockwise), then X, Y, Z and Rz from -127 to 127.
|
|
9
|
+
Nothing here draws or touches USB, so the same code runs in the tests.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import math
|
|
13
|
+
import struct
|
|
14
|
+
|
|
15
|
+
#: The buttons on the pad, by the HID button number each one sends.
|
|
16
|
+
A, B, X, Y = 1, 2, 3, 4
|
|
17
|
+
L, R = 5, 6
|
|
18
|
+
SELECT, START = 7, 8
|
|
19
|
+
|
|
20
|
+
#: Where a press inside the d-pad counts as no direction, as a share of its radius.
|
|
21
|
+
DEAD = 0.3
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def hat_at(dx, dy, radius):
|
|
25
|
+
"""The hat direction for a touch *dx*, *dy* from the d-pad's centre (y
|
|
26
|
+
grows downwards): 0 north to 7 north-west, clockwise, or None inside the
|
|
27
|
+
dead zone."""
|
|
28
|
+
if dx * dx + dy * dy < (DEAD * radius) ** 2:
|
|
29
|
+
return None
|
|
30
|
+
# Clockwise from north, in eighths, each centred on its direction.
|
|
31
|
+
turn = math.atan2(dx, -dy) / (2 * math.pi)
|
|
32
|
+
return int(turn * 8 + 8.5) % 8
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def stick_at(dx, dy, radius):
|
|
36
|
+
"""``(x, y)`` from -127 to 127 for a touch *dx*, *dy* from the stick's
|
|
37
|
+
centre; a touch past the rim reads as the rim in the same direction."""
|
|
38
|
+
d = math.sqrt(dx * dx + dy * dy)
|
|
39
|
+
if d > radius:
|
|
40
|
+
dx, dy = dx * radius / d, dy * radius / d
|
|
41
|
+
return round(dx * 127 / radius), round(dy * 127 / radius)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Pad:
|
|
45
|
+
"""What is held on the pad: buttons, the hat and the stick."""
|
|
46
|
+
|
|
47
|
+
def __init__(self):
|
|
48
|
+
self.buttons = 0
|
|
49
|
+
self.hat = None
|
|
50
|
+
self.x = 0
|
|
51
|
+
self.y = 0
|
|
52
|
+
|
|
53
|
+
def press(self, number):
|
|
54
|
+
self.buttons |= 1 << number - 1
|
|
55
|
+
|
|
56
|
+
def release(self, number):
|
|
57
|
+
self.buttons &= ~(1 << number - 1)
|
|
58
|
+
|
|
59
|
+
def report(self):
|
|
60
|
+
"""The seven bytes ``Device.GAMEPAD.send_report`` takes."""
|
|
61
|
+
hat = 0 if self.hat is None else self.hat + 1
|
|
62
|
+
return struct.pack("<HBbbbb", self.buttons & 0xFFFF, hat, self.x, self.y, 0, 0)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Sender:
|
|
66
|
+
"""Sends the pad's report to a host when it changes.
|
|
67
|
+
|
|
68
|
+
*device* is ``usb_hid.Device.GAMEPAD``, or anything with its
|
|
69
|
+
``send_report``. A report that couldn't go, because no host has the
|
|
70
|
+
board yet or the host stopped taking reports, is sent again by the next
|
|
71
|
+
`send`, so the host always ends up with what the pad holds.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
def __init__(self, pad, device):
|
|
75
|
+
self.pad = pad
|
|
76
|
+
self.device = device
|
|
77
|
+
self.sent = None
|
|
78
|
+
self.count = 0
|
|
79
|
+
self.error = None
|
|
80
|
+
|
|
81
|
+
def send(self):
|
|
82
|
+
"""Send the report if the host doesn't have it yet. Returns True when one went."""
|
|
83
|
+
report = self.pad.report()
|
|
84
|
+
if report == self.sent:
|
|
85
|
+
return False
|
|
86
|
+
try:
|
|
87
|
+
self.device.send_report(report)
|
|
88
|
+
except OSError as e:
|
|
89
|
+
self.error = str(e) or type(e).__name__
|
|
90
|
+
return False
|
|
91
|
+
self.sent = report
|
|
92
|
+
self.count += 1
|
|
93
|
+
self.error = None
|
|
94
|
+
return True
|
apps/gamepad/watch.py
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The tester's side: a gamepad on the USB host port, read as it changes.
|
|
5
|
+
|
|
6
|
+
`Watch` looks for a gamepad, reads its events and keeps what it holds now,
|
|
7
|
+
and finds it again after it's unplugged. It takes ``usb.core`` and
|
|
8
|
+
``usb.host.hid_generic`` as arguments, so the tests hand it stand-ins.
|
|
9
|
+
`PageWatch` is the same for a browser page: the pad chosen for ``gamepad``
|
|
10
|
+
in Connections, or the first the browser shows, read through the Gamepad
|
|
11
|
+
API.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
#: How often the tester looks for a gamepad while it has none, in ms.
|
|
15
|
+
LOOK_MS = 1000
|
|
16
|
+
#: The most events read in one `Watch.poll`, so a busy pad can't hold up the screen.
|
|
17
|
+
MOST = 64
|
|
18
|
+
#: Short names for the axes a gamepad can have, by hid_generic's Axis code.
|
|
19
|
+
AXIS_NAMES = {
|
|
20
|
+
0x010030: "X",
|
|
21
|
+
0x010031: "Y",
|
|
22
|
+
0x010032: "Z",
|
|
23
|
+
0x010033: "Rx",
|
|
24
|
+
0x010034: "Ry",
|
|
25
|
+
0x010035: "Rz",
|
|
26
|
+
0x010036: "Slider",
|
|
27
|
+
0x010037: "Dial",
|
|
28
|
+
0x010038: "Wheel",
|
|
29
|
+
0x0200BA: "Rudder",
|
|
30
|
+
0x0200BB: "Throttle",
|
|
31
|
+
0x0200C4: "Accel",
|
|
32
|
+
0x0200C5: "Brake",
|
|
33
|
+
0x0200C8: "Steer",
|
|
34
|
+
}
|
|
35
|
+
#: Short names for the vendor values many gamepads send after their sticks,
|
|
36
|
+
#: by usage: the PS3 layout's pressure for each control, then its motion
|
|
37
|
+
#: sensors: tilting left and right (roll), moving up and down (lift),
|
|
38
|
+
#: tilting forward and back (pitch), and turning flat (yaw).
|
|
39
|
+
EXTRA_NAMES = {
|
|
40
|
+
0xFF000020: "Rt", 0xFF000021: "Lt", 0xFF000022: "Up", 0xFF000023: "Dn",
|
|
41
|
+
0xFF000024: "Y", 0xFF000025: "B", 0xFF000026: "A", 0xFF000027: "X",
|
|
42
|
+
0xFF000028: "LB", 0xFF000029: "RB", 0xFF00002A: "LT", 0xFF00002B: "RT",
|
|
43
|
+
0xFF00002C: "roll", 0xFF00002D: "lift", 0xFF00002E: "pitch", 0xFF00002F: "yaw",
|
|
44
|
+
}
|
|
45
|
+
#: The order the vendor values that aren't a button's go in on the screen:
|
|
46
|
+
#: the d-pad's pressure clockwise from up, then the motion sensors.
|
|
47
|
+
EXTRA_ORDER = (0xFF000022, 0xFF000020, 0xFF000023, 0xFF000021, 0xFF00002C, 0xFF00002D, 0xFF00002E, 0xFF00002F)
|
|
48
|
+
#: Which button each pressure value belongs to, on a pad in the PS3 layout:
|
|
49
|
+
#: 1 is the left face button, 2 the bottom, 3 the right, 4 the top, then the
|
|
50
|
+
#: shoulders and triggers, as that layout numbers them.
|
|
51
|
+
PRESSURE_OF = {
|
|
52
|
+
0xFF000027: 1, 0xFF000026: 2, 0xFF000025: 3, 0xFF000024: 4,
|
|
53
|
+
0xFF000028: 5, 0xFF000029: 6, 0xFF00002A: 7, 0xFF00002B: 8,
|
|
54
|
+
}
|
|
55
|
+
#: Vendor values that rest in the middle and move only a little either way,
|
|
56
|
+
#: drawn as a bar from the middle: (middle, how far either way fills it). A
|
|
57
|
+
#: PS3-layout pad's yaw sensor gives about 120 either side of 512 for a
|
|
58
|
+
#: quick turn.
|
|
59
|
+
CENTRED = {0xFF00002F: (512, 128)}
|
|
60
|
+
#: What a pad in the PS3 layout calls each button, by number.
|
|
61
|
+
BUTTON_NAMES = ("X", "A", "B", "Y", "LB", "RB", "LT", "RT", "Back", "Start", "L3", "R3", "Home")
|
|
62
|
+
#: Each field in hid_generic's ``Gamepad.fields`` starts with its kind.
|
|
63
|
+
_BUTTON, _AXIS, _HAT = 0, 1, 2
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _name(dev):
|
|
67
|
+
maker = getattr(dev, "manufacturer", None) or "%04x" % dev.idVendor
|
|
68
|
+
product = getattr(dev, "product", None) or "%04x" % dev.idProduct
|
|
69
|
+
return "%s %s" % (maker, product)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Watch:
|
|
73
|
+
"""The gamepad on the host port, if there is one, and what it holds.
|
|
74
|
+
|
|
75
|
+
Read `buttons` (the numbers held), `axes` (axis code to -1.0 to 1.0) and
|
|
76
|
+
`hats` (hat index to 0 up to 7 up-left, clockwise, or -1 centred) after
|
|
77
|
+
each `poll`, and `extras`, the pad's vendor values (pressure, motion) in
|
|
78
|
+
its report's order. `layout` says which buttons, axes and hats the pad
|
|
79
|
+
has, and the usage and range of each extra, and changes only when a
|
|
80
|
+
different pad is found.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
def __init__(self, core, hid_generic):
|
|
84
|
+
self.core = core
|
|
85
|
+
self.hid = hid_generic
|
|
86
|
+
self.pad = None
|
|
87
|
+
self.name = None
|
|
88
|
+
self.layout = None
|
|
89
|
+
self.buttons = set()
|
|
90
|
+
self.axes = {}
|
|
91
|
+
self.hats = {}
|
|
92
|
+
self.extras = []
|
|
93
|
+
self.events = 0
|
|
94
|
+
self.status = "no gamepad yet: plug one into the USB host port"
|
|
95
|
+
self._looked = None
|
|
96
|
+
|
|
97
|
+
def _forget(self):
|
|
98
|
+
self.pad = None
|
|
99
|
+
self.name = None
|
|
100
|
+
self.layout = None
|
|
101
|
+
self.buttons = set()
|
|
102
|
+
self.axes = {}
|
|
103
|
+
self.hats = {}
|
|
104
|
+
self.extras = []
|
|
105
|
+
|
|
106
|
+
def look(self):
|
|
107
|
+
"""Look for a gamepad now. Returns True when one was found."""
|
|
108
|
+
hid = self.hid
|
|
109
|
+
dev = self.core.find(custom_match=hid.Gamepad.match)
|
|
110
|
+
if dev is None:
|
|
111
|
+
return False
|
|
112
|
+
pad = hid.Gamepad(dev)
|
|
113
|
+
buttons, axes, hats = [], [], 0
|
|
114
|
+
for f in pad.fields:
|
|
115
|
+
if f[0] == _BUTTON:
|
|
116
|
+
buttons.append(f[6])
|
|
117
|
+
elif f[0] == _AXIS:
|
|
118
|
+
axes.append(f[6])
|
|
119
|
+
elif f[0] == _HAT:
|
|
120
|
+
hats += 1
|
|
121
|
+
self.pad = pad
|
|
122
|
+
self.name = _name(dev)
|
|
123
|
+
# A library from before extras has none to give.
|
|
124
|
+
extras = tuple(getattr(pad, "extra_info", ()))
|
|
125
|
+
self.layout = (tuple(sorted(buttons)), tuple(axes), hats, extras)
|
|
126
|
+
self.extras = list(getattr(pad, "extras", ()))
|
|
127
|
+
self.status = self.name
|
|
128
|
+
return True
|
|
129
|
+
|
|
130
|
+
def poll(self, now_ms, since):
|
|
131
|
+
"""Read what the pad sent since the last poll. *now_ms* is the time
|
|
132
|
+
and *since* a ``ticks_diff``-like function, so a pad that isn't there
|
|
133
|
+
is looked for only every `LOOK_MS`. Returns True when anything changed."""
|
|
134
|
+
if self.pad is None:
|
|
135
|
+
if self._looked is not None and since(now_ms, self._looked) < LOOK_MS:
|
|
136
|
+
return False
|
|
137
|
+
self._looked = now_ms
|
|
138
|
+
try:
|
|
139
|
+
return self.look()
|
|
140
|
+
except (OSError, ValueError) as e:
|
|
141
|
+
# A device that went while it was being read, or one whose
|
|
142
|
+
# descriptor isn't a pad's after all: say so, look again.
|
|
143
|
+
self.status = "couldn't read the gamepad: %s" % (e,)
|
|
144
|
+
return False
|
|
145
|
+
pad, hid = self.pad, self.hid
|
|
146
|
+
changed = False
|
|
147
|
+
try:
|
|
148
|
+
for _ in range(MOST):
|
|
149
|
+
reports = getattr(pad, "reports", 0)
|
|
150
|
+
ev = pad.read(1) # ms; 0 would wait forever, as in pyusb
|
|
151
|
+
if not ev:
|
|
152
|
+
# A report that only moved the extras makes no event:
|
|
153
|
+
# read on while reports still come.
|
|
154
|
+
if getattr(pad, "reports", 0) != reports:
|
|
155
|
+
continue
|
|
156
|
+
break
|
|
157
|
+
changed = True
|
|
158
|
+
self.events += 1
|
|
159
|
+
kind = ev[0]
|
|
160
|
+
if kind == hid.BUTTON_DOWN:
|
|
161
|
+
self.buttons.add(ev[1])
|
|
162
|
+
elif kind == hid.BUTTON_UP:
|
|
163
|
+
self.buttons.discard(ev[1])
|
|
164
|
+
elif kind == hid.AXIS:
|
|
165
|
+
self.axes[ev[1]] = pad.scaled(ev[1])
|
|
166
|
+
elif kind == hid.HAT:
|
|
167
|
+
self.hats[ev[1]] = ev[2]
|
|
168
|
+
extras = getattr(pad, "extras", None)
|
|
169
|
+
if extras and extras != self.extras:
|
|
170
|
+
self.extras = list(extras)
|
|
171
|
+
changed = True
|
|
172
|
+
except self.core.USBError:
|
|
173
|
+
# Unplugged: drop it and look again.
|
|
174
|
+
self.close()
|
|
175
|
+
self.status = "the gamepad went: plug it in again"
|
|
176
|
+
self._looked = now_ms
|
|
177
|
+
return True
|
|
178
|
+
return changed
|
|
179
|
+
|
|
180
|
+
def close(self):
|
|
181
|
+
pad = self.pad
|
|
182
|
+
self._forget()
|
|
183
|
+
if pad is not None:
|
|
184
|
+
try:
|
|
185
|
+
pad.close()
|
|
186
|
+
except Exception as e: # noqa: BLE001 - it's gone either way
|
|
187
|
+
print("gamepad: closing the pad:", e)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
#: What the tester says in a browser without gamepads.
|
|
191
|
+
NO_GAMEPAD_API = "This browser has no Gamepad API"
|
|
192
|
+
#: The browser's standard gamepad layout, as the tester names its axes: the
|
|
193
|
+
#: left stick, then the right.
|
|
194
|
+
PAGE_AXES = (0x010030, 0x010031, 0x010032, 0x010035)
|
|
195
|
+
#: The standard layout's d-pad buttons (up, down, left, right), counted from 1,
|
|
196
|
+
#: which the tester shows as a hat.
|
|
197
|
+
PAGE_DPAD = (13, 14, 15, 16)
|
|
198
|
+
#: Hat directions for the d-pad's buttons held (up, down, left, right):
|
|
199
|
+
#: 0 up, clockwise to 7 up-left.
|
|
200
|
+
_HAT_OF = {
|
|
201
|
+
(1, 0, 0, 0): 0, (1, 0, 0, 1): 1, (0, 0, 0, 1): 2, (0, 1, 0, 1): 3,
|
|
202
|
+
(0, 1, 0, 0): 4, (0, 1, 1, 0): 5, (0, 0, 1, 0): 6, (1, 0, 1, 0): 7,
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
# Every pad the page sees, one per line: index, id, mapping, then the
|
|
206
|
+
# buttons' values and the axes' values, comma-separated.
|
|
207
|
+
_PADS = """() => {
|
|
208
|
+
const nav = globalThis.navigator;
|
|
209
|
+
if (!nav || !nav.getGamepads) return null;
|
|
210
|
+
const lines = [];
|
|
211
|
+
for (const pad of nav.getGamepads()) {
|
|
212
|
+
if (!pad || !pad.connected) continue;
|
|
213
|
+
lines.push([pad.index, pad.id.replace(/[\\t\\n]/g, ' '), pad.mapping,
|
|
214
|
+
pad.buttons.map((b) => b.pressed ? Math.max(b.value, 0.5).toFixed(2) : b.value.toFixed(2)).join(','),
|
|
215
|
+
pad.axes.map((a) => a.toFixed(3)).join(',')].join('\\t'));
|
|
216
|
+
}
|
|
217
|
+
return lines.join('\\n');
|
|
218
|
+
}"""
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def page_pads(read=None):
|
|
222
|
+
"""The pads the browser shows this page, as ``(index, name, mapping,
|
|
223
|
+
buttons, axes)``: buttons are 0.0 to 1.0, axes -1.0 to 1.0. None when the
|
|
224
|
+
browser has no Gamepad API. *read* stands in for the browser in a test."""
|
|
225
|
+
if read is None:
|
|
226
|
+
import js
|
|
227
|
+
|
|
228
|
+
read = js.eval(_PADS)
|
|
229
|
+
text = read()
|
|
230
|
+
if text is None:
|
|
231
|
+
return None
|
|
232
|
+
pads = []
|
|
233
|
+
for line in str(text).split("\n") if text else ():
|
|
234
|
+
index, name, mapping, buttons, axes = line.split("\t")
|
|
235
|
+
pads.append((int(index), name, mapping,
|
|
236
|
+
[float(v) for v in buttons.split(",")] if buttons else [],
|
|
237
|
+
[float(v) for v in axes.split(",")] if axes else []))
|
|
238
|
+
return pads
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class _PagePad:
|
|
242
|
+
"""What the tester reads of a pad besides its state: ``axes``, the raw values."""
|
|
243
|
+
|
|
244
|
+
def __init__(self):
|
|
245
|
+
self.axes = {}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class PageWatch:
|
|
249
|
+
"""A gamepad the browser shows the page, read like `Watch` reads one on
|
|
250
|
+
the USB host port: the one chosen for ``gamepad`` in Connections, or the
|
|
251
|
+
first there is.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
pads (callable): returns `page_pads`'s list; the browser's when None.
|
|
255
|
+
chosen (callable): returns the names chosen for ``gamepad``;
|
|
256
|
+
endpointkit's choice when None.
|
|
257
|
+
"""
|
|
258
|
+
|
|
259
|
+
def __init__(self, pads=None, chosen=None):
|
|
260
|
+
self._pads = pads or page_pads
|
|
261
|
+
self._chosen = chosen or _chosen_pads
|
|
262
|
+
self.pad = None
|
|
263
|
+
self.name = None
|
|
264
|
+
self.layout = None
|
|
265
|
+
self.buttons = set()
|
|
266
|
+
self.axes = {}
|
|
267
|
+
self.hats = {}
|
|
268
|
+
self.extras = []
|
|
269
|
+
self.events = 0
|
|
270
|
+
self.status = "no gamepad yet: press a button on one, and the browser shows it to the page"
|
|
271
|
+
self._last = None
|
|
272
|
+
|
|
273
|
+
def _pick(self, pads):
|
|
274
|
+
"""The chosen pad, by the name Connections lists it under (a second
|
|
275
|
+
pad of the same name is "#2"), or the first when none is chosen."""
|
|
276
|
+
names = self._chosen()
|
|
277
|
+
if not names:
|
|
278
|
+
return pads[0] if pads else None
|
|
279
|
+
labels = []
|
|
280
|
+
for pad in pads:
|
|
281
|
+
label, n = pad[1], 2
|
|
282
|
+
while label in labels:
|
|
283
|
+
label = "%s #%d" % (pad[1], n)
|
|
284
|
+
n += 1
|
|
285
|
+
labels.append(label)
|
|
286
|
+
for want in names:
|
|
287
|
+
if want in labels:
|
|
288
|
+
return pads[labels.index(want)]
|
|
289
|
+
return None
|
|
290
|
+
|
|
291
|
+
def poll(self, now_ms=None, since=None):
|
|
292
|
+
"""Read the chosen pad now. Returns True when anything changed."""
|
|
293
|
+
pads = self._pads()
|
|
294
|
+
if pads is None:
|
|
295
|
+
changed = self.status != NO_GAMEPAD_API
|
|
296
|
+
self.status = NO_GAMEPAD_API
|
|
297
|
+
return changed
|
|
298
|
+
pad = self._pick(pads)
|
|
299
|
+
if pad is None:
|
|
300
|
+
if self.pad is None:
|
|
301
|
+
return False
|
|
302
|
+
self.close()
|
|
303
|
+
self.status = "the gamepad went: press a button on it again"
|
|
304
|
+
return True
|
|
305
|
+
index, name, mapping, buttons, axes = pad
|
|
306
|
+
standard = mapping == "standard"
|
|
307
|
+
dpad = PAGE_DPAD if standard and len(buttons) >= 16 else ()
|
|
308
|
+
numbers = tuple(n for n in range(1, len(buttons) + 1) if n not in dpad)
|
|
309
|
+
codes = PAGE_AXES[:len(axes)] if standard else tuple(0x010030 + i for i in range(len(axes)))
|
|
310
|
+
layout = (numbers, codes, 1 if dpad else 0, ())
|
|
311
|
+
changed = False
|
|
312
|
+
if self.pad is None or self.name != name or self.layout != layout:
|
|
313
|
+
self.pad = _PagePad()
|
|
314
|
+
self.name = name
|
|
315
|
+
self.layout = layout
|
|
316
|
+
self.status = name
|
|
317
|
+
changed = True
|
|
318
|
+
held = {n for n in numbers if buttons[n - 1] >= 0.5}
|
|
319
|
+
if held != self.buttons:
|
|
320
|
+
self.buttons = held
|
|
321
|
+
changed = True
|
|
322
|
+
for code, value in zip(codes, axes):
|
|
323
|
+
if self.axes.get(code) != value:
|
|
324
|
+
self.axes[code] = value
|
|
325
|
+
self.pad.axes[code] = int(value * 32767)
|
|
326
|
+
changed = True
|
|
327
|
+
if dpad:
|
|
328
|
+
key = tuple(1 if buttons[n - 1] >= 0.5 else 0 for n in dpad)
|
|
329
|
+
hat = _HAT_OF.get(key, -1)
|
|
330
|
+
if self.hats.get(0, -1) != hat:
|
|
331
|
+
self.hats[0] = hat
|
|
332
|
+
changed = True
|
|
333
|
+
if changed:
|
|
334
|
+
self.events += 1
|
|
335
|
+
return changed
|
|
336
|
+
|
|
337
|
+
def close(self):
|
|
338
|
+
self.pad = None
|
|
339
|
+
self.name = None
|
|
340
|
+
self.layout = None
|
|
341
|
+
self.buttons = set()
|
|
342
|
+
self.axes = {}
|
|
343
|
+
self.hats = {}
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def _chosen_pads():
|
|
348
|
+
try:
|
|
349
|
+
import endpointkit
|
|
350
|
+
except ImportError:
|
|
351
|
+
return []
|
|
352
|
+
return [ep.label for ep in endpointkit.selected("gamepad")]
|
apps/hidden/__init__.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Hidden apps: the apps kept off Home's pages, and a way to put each back.
|
|
5
|
+
|
|
6
|
+
An app that can't run on this board offers "Hide from Home" on its screen
|
|
7
|
+
(``touchkit.ui.hide_button``). Each one hidden that way is listed here with
|
|
8
|
+
the reason it gave, and Unhide puts its tile back on Home. Home goes back,
|
|
9
|
+
as it does from any app; the list is read afresh each time the app opens.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import lvgl as lv
|
|
13
|
+
|
|
14
|
+
from touchkit import ui
|
|
15
|
+
|
|
16
|
+
GAP = 12
|
|
17
|
+
CARD = 0x121826 # Home's card colour
|
|
18
|
+
NONE_HIDDEN = "No app is hidden.\nAn app that can't run on this board offers Hide from Home, and comes back from here."
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _empty(scope):
|
|
22
|
+
msg = ui.label(scope.root, NONE_HIDDEN, ui.font, ui.MUTED)
|
|
23
|
+
msg.set_width(scope.size[0] - 4 * GAP)
|
|
24
|
+
msg.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
25
|
+
msg.align(lv.ALIGN.CENTER, 0, 0)
|
|
26
|
+
return msg
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def main(scope):
|
|
30
|
+
launcher = scope.launcher
|
|
31
|
+
W, H = scope.size
|
|
32
|
+
root = scope.root
|
|
33
|
+
root.set_style_bg_color(ui.BG, 0)
|
|
34
|
+
root.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
35
|
+
hidden = launcher.hidden()
|
|
36
|
+
if not hidden:
|
|
37
|
+
_empty(scope)
|
|
38
|
+
return
|
|
39
|
+
rows = lv.obj(root)
|
|
40
|
+
rows.set_size(W, H)
|
|
41
|
+
rows.set_style_bg_opa(lv.OPA.TRANSP, 0)
|
|
42
|
+
rows.set_style_border_width(0, 0)
|
|
43
|
+
rows.set_style_radius(0, 0)
|
|
44
|
+
rows.set_style_pad_all(GAP, 0)
|
|
45
|
+
rows.set_style_pad_gap(GAP, 0)
|
|
46
|
+
rows.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
|
47
|
+
small = W < 480
|
|
48
|
+
button_w = 96 if small else 120
|
|
49
|
+
left = [len(hidden)]
|
|
50
|
+
for name in sorted(hidden):
|
|
51
|
+
row = ui.plain(lv.obj(rows))
|
|
52
|
+
row.set_size(lv.pct(100), lv.SIZE_CONTENT)
|
|
53
|
+
row.set_style_bg_color(lv.color_hex(CARD), 0)
|
|
54
|
+
row.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
55
|
+
row.set_style_radius(12, 0)
|
|
56
|
+
row.set_style_pad_all(GAP, 0)
|
|
57
|
+
text = ui.label(row, launcher.info.get(name, {}).get("title", name), ui.font, ui.WHITE)
|
|
58
|
+
text.set_pos(0, 0)
|
|
59
|
+
if hidden[name]:
|
|
60
|
+
why = ui.label(row, hidden[name], ui.small, ui.MUTED)
|
|
61
|
+
why.set_width(W - 6 * GAP - button_w)
|
|
62
|
+
why.align_to(text, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 4)
|
|
63
|
+
|
|
64
|
+
def unhide(name=name, row=row):
|
|
65
|
+
launcher.unhide(name)
|
|
66
|
+
row.delete_async() # from its own button's callback
|
|
67
|
+
left[0] -= 1
|
|
68
|
+
if not left[0]:
|
|
69
|
+
_empty(scope)
|
|
70
|
+
|
|
71
|
+
u, _ = ui.button(row, "Unhide", unhide, w=button_w, color=ui.PANEL)
|
|
72
|
+
u.align(lv.ALIGN.RIGHT_MID, 0, 0)
|
apps/hidden/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "hidden", "title": "Hidden apps", "category": "System", "icon": "visibility_off", "color": "#44505E"}
|