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
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Security cam: the CSI camera streamed as MJPEG, with a preview on the panel.
|
|
5
|
+
|
|
6
|
+
Open the address on the screen in VLC (Media > Open Network Stream) or any
|
|
7
|
+
browser: MJPEG is one HTTP response carrying JPEG after JPEG, which every
|
|
8
|
+
player and browser understands. The P4's encoder makes each JPEG; the
|
|
9
|
+
network is what limits the frame rate, so ``?q=`` on the address sets the
|
|
10
|
+
quality (default ``QUALITY``): lower is smaller and faster.
|
|
11
|
+
|
|
12
|
+
The camera has one user. The foreground loop takes a preview frame for the
|
|
13
|
+
panel and, while anyone is watching, a JPEG for the stream; a server thread
|
|
14
|
+
hands each viewer the newest JPEG. Every thread ends when the app closes: a
|
|
15
|
+
live thread's stack sits in internal RAM, and a few left behind split it
|
|
16
|
+
too small for the video encoder. Flip, mirror, light and brightness are
|
|
17
|
+
the Camera app's.
|
|
18
|
+
|
|
19
|
+
Without a camera the app says so, and Home goes back as usual.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import errno
|
|
23
|
+
|
|
24
|
+
import lvgl as lv
|
|
25
|
+
from multimer import ticks_add, ticks_diff, ticks_ms
|
|
26
|
+
|
|
27
|
+
from touchkit import cam, net, ui
|
|
28
|
+
from touchkit.clock import sleep_ms
|
|
29
|
+
|
|
30
|
+
PORT = 8081
|
|
31
|
+
QUALITY = 50
|
|
32
|
+
PREVIEW = 400
|
|
33
|
+
BOUNDARY = "touchkitframe"
|
|
34
|
+
FRAME_SECONDS = 4 # a viewer that can't take a whole frame in this long is dropped
|
|
35
|
+
|
|
36
|
+
state = None # the open app's state, for the console
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main(scope):
|
|
40
|
+
global state
|
|
41
|
+
root = scope.root
|
|
42
|
+
status = ui.status(scope)
|
|
43
|
+
W, H = scope.size
|
|
44
|
+
RX, RY = scope.rect[:2]
|
|
45
|
+
|
|
46
|
+
opts = cam.options(scope)
|
|
47
|
+
try:
|
|
48
|
+
c0 = cam.open_camera(opts)
|
|
49
|
+
except Exception as e:
|
|
50
|
+
ui.missing(scope, "no camera", cam.no_camera_text(e, "Security cam"))
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
from board_config import display_drv as d
|
|
54
|
+
|
|
55
|
+
if not d.framebuffers():
|
|
56
|
+
c0.deinit()
|
|
57
|
+
ui.missing(scope, "no framebuffer", "Security cam draws its preview straight into the display's framebuffer, and this board's display has none.")
|
|
58
|
+
return
|
|
59
|
+
try:
|
|
60
|
+
import _thread
|
|
61
|
+
import socket
|
|
62
|
+
except ImportError as e:
|
|
63
|
+
c0.deinit()
|
|
64
|
+
ui.missing(scope, "missing: %s" % (e,), "Security cam serves its stream from a thread: %s." % (e,))
|
|
65
|
+
return
|
|
66
|
+
st = state = {
|
|
67
|
+
"cam": None, "open": True, "jpeg": None, "seq": 0, "viewers": 0, "conns": [],
|
|
68
|
+
"sent": 0, "dropped": 0, "t0": ticks_ms(), "q": QUALITY, "lock": _thread.allocate_lock(),
|
|
69
|
+
} # fmt: skip
|
|
70
|
+
|
|
71
|
+
cam.apply_controls(c0, opts)
|
|
72
|
+
st["cam"] = c0
|
|
73
|
+
fb = d.framebuffers()[0]
|
|
74
|
+
cw, chh = c0.size()[:2]
|
|
75
|
+
pw, ph = cam.preview_size(c0, PREVIEW)
|
|
76
|
+
x0, y0 = 24, 8 + (PREVIEW - ph) // 2
|
|
77
|
+
ax, ay = RX + x0, RY + y0
|
|
78
|
+
ui.frame(root, x0, y0, pw, ph)
|
|
79
|
+
|
|
80
|
+
rx = 24 + PREVIEW + 24
|
|
81
|
+
rw = W - rx - 24
|
|
82
|
+
title = ui.label(root, lv.SYMBOL.EYE_OPEN + " Watching", ui.big, ui.ACCENT)
|
|
83
|
+
title.set_pos(rx, 12)
|
|
84
|
+
where = ui.label(root, "", ui.font, ui.WHITE)
|
|
85
|
+
where.set_pos(rx, 64)
|
|
86
|
+
where.set_width(rw)
|
|
87
|
+
live = ui.label(root, "", ui.small, ui.MUTED)
|
|
88
|
+
live.set_pos(rx, 210)
|
|
89
|
+
live.set_width(rw)
|
|
90
|
+
|
|
91
|
+
ip = net.ip()
|
|
92
|
+
name = net.hostname()
|
|
93
|
+
if ip:
|
|
94
|
+
where.set_text(
|
|
95
|
+
"In VLC or a browser:\n%shttp://%s:%d" % ("http://%s.local:%d\n" % (name, PORT) if name else "", ip, PORT)
|
|
96
|
+
)
|
|
97
|
+
else:
|
|
98
|
+
where.set_text("No Wi-Fi: nothing to stream to.")
|
|
99
|
+
|
|
100
|
+
# -- the stream ---------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
def send_all(c, data):
|
|
103
|
+
# A slow viewer keeps a trickle moving, so the socket's own timeout
|
|
104
|
+
# never fires; give each send a deadline, and stop as soon as the
|
|
105
|
+
# app closes.
|
|
106
|
+
view = memoryview(data)
|
|
107
|
+
end = ticks_add(ticks_ms(), FRAME_SECONDS * 1000)
|
|
108
|
+
while view:
|
|
109
|
+
if not st["open"] or ticks_diff(end, ticks_ms()) < 0:
|
|
110
|
+
raise OSError("too slow" if st["open"] else "closing")
|
|
111
|
+
try:
|
|
112
|
+
n = c.send(view) # waits at most a second (the viewer's timeout)
|
|
113
|
+
except OSError as e:
|
|
114
|
+
if e.args and e.args[0] in (errno.ETIMEDOUT, errno.EAGAIN):
|
|
115
|
+
continue
|
|
116
|
+
raise
|
|
117
|
+
if n <= 0:
|
|
118
|
+
raise OSError("closed")
|
|
119
|
+
view = view[n:]
|
|
120
|
+
|
|
121
|
+
alive = scope.store() # threads still running, counted across opens
|
|
122
|
+
alive.setdefault("server", 0)
|
|
123
|
+
alive.setdefault("viewer", 0)
|
|
124
|
+
|
|
125
|
+
def viewer(c, q):
|
|
126
|
+
st["viewers"] += 1
|
|
127
|
+
alive["viewer"] += 1
|
|
128
|
+
c.settimeout(1)
|
|
129
|
+
try:
|
|
130
|
+
send_all(
|
|
131
|
+
c,
|
|
132
|
+
b"HTTP/1.0 200 OK\r\nContent-Type: multipart/x-mixed-replace; boundary="
|
|
133
|
+
+ BOUNDARY.encode()
|
|
134
|
+
+ b"\r\nCache-Control: no-store\r\n\r\n",
|
|
135
|
+
)
|
|
136
|
+
seen = -1
|
|
137
|
+
while st["open"]:
|
|
138
|
+
if st["seq"] == seen:
|
|
139
|
+
sleep_ms(10)
|
|
140
|
+
continue
|
|
141
|
+
with st["lock"]:
|
|
142
|
+
img, seen = st["jpeg"], st["seq"]
|
|
143
|
+
if img is None:
|
|
144
|
+
continue
|
|
145
|
+
send_all(
|
|
146
|
+
c, ("--%s\r\nContent-Type: image/jpeg\r\nContent-Length: %d\r\n\r\n" % (BOUNDARY, len(img))).encode()
|
|
147
|
+
)
|
|
148
|
+
send_all(c, img)
|
|
149
|
+
send_all(c, b"\r\n")
|
|
150
|
+
st["sent"] += 1
|
|
151
|
+
st["taken"] = seen
|
|
152
|
+
except OSError as e:
|
|
153
|
+
if e.args and e.args[0] == "too slow":
|
|
154
|
+
st["dropped"] += 1
|
|
155
|
+
print("security cam: dropped a viewer that couldn't keep up")
|
|
156
|
+
finally:
|
|
157
|
+
st["viewers"] -= 1
|
|
158
|
+
alive["viewer"] -= 1
|
|
159
|
+
try:
|
|
160
|
+
st["conns"].remove(c)
|
|
161
|
+
except ValueError:
|
|
162
|
+
pass
|
|
163
|
+
c.close()
|
|
164
|
+
|
|
165
|
+
def serve():
|
|
166
|
+
alive["server"] += 1
|
|
167
|
+
try:
|
|
168
|
+
_serve()
|
|
169
|
+
finally:
|
|
170
|
+
alive["server"] -= 1
|
|
171
|
+
|
|
172
|
+
def _serve():
|
|
173
|
+
s = socket.socket()
|
|
174
|
+
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
175
|
+
s.bind(("0.0.0.0", PORT))
|
|
176
|
+
s.listen(2)
|
|
177
|
+
s.settimeout(0.5)
|
|
178
|
+
while st["open"]:
|
|
179
|
+
try:
|
|
180
|
+
c, _ = s.accept()
|
|
181
|
+
except OSError:
|
|
182
|
+
continue
|
|
183
|
+
try:
|
|
184
|
+
c.settimeout(10)
|
|
185
|
+
req = c.recv(512)
|
|
186
|
+
path = req.split(b" ")[1] if b" " in req else b"/"
|
|
187
|
+
if b"q=" in path:
|
|
188
|
+
try:
|
|
189
|
+
st["q"] = min(95, max(10, int(path.split(b"q=")[1][:3])))
|
|
190
|
+
except ValueError:
|
|
191
|
+
pass
|
|
192
|
+
if path.startswith(b"/favicon"):
|
|
193
|
+
c.close()
|
|
194
|
+
continue
|
|
195
|
+
st["conns"].append(c)
|
|
196
|
+
_thread.start_new_thread(viewer, (c, st["q"]))
|
|
197
|
+
except Exception as e:
|
|
198
|
+
print("security cam:", e)
|
|
199
|
+
c.close()
|
|
200
|
+
s.close()
|
|
201
|
+
|
|
202
|
+
if ip:
|
|
203
|
+
_thread.stack_size(16 * 1024)
|
|
204
|
+
try:
|
|
205
|
+
_thread.start_new_thread(serve, ())
|
|
206
|
+
finally:
|
|
207
|
+
_thread.stack_size(0)
|
|
208
|
+
|
|
209
|
+
# -- the foreground loop: a preview frame, and a JPEG while anyone watches ----
|
|
210
|
+
|
|
211
|
+
def loop():
|
|
212
|
+
c = st["cam"]
|
|
213
|
+
if c is None:
|
|
214
|
+
return
|
|
215
|
+
loops = st["loops"] = st.get("loops", 0) + 1
|
|
216
|
+
watched = st["viewers"] > 0
|
|
217
|
+
# Waiting for a camera frame holds the interpreter, so the sender only
|
|
218
|
+
# runs between captures: with viewers, refresh the panel one loop in
|
|
219
|
+
# four, make a JPEG only once the last one has gone, and yield.
|
|
220
|
+
if not watched or loops % 4 == 0:
|
|
221
|
+
if c.capture_scaled(fb, d.width, d.height, x=ax, y=ay, w=pw, h=ph, timeout=200) is not None:
|
|
222
|
+
d.flush_rect(ax, ay, pw, ph)
|
|
223
|
+
if watched and st.get("taken", -1) == st["seq"] or watched and st["jpeg"] is None:
|
|
224
|
+
img = c.capture_jpeg(st["q"])
|
|
225
|
+
if img:
|
|
226
|
+
with st["lock"]:
|
|
227
|
+
st["jpeg"] = img
|
|
228
|
+
st["seq"] += 1
|
|
229
|
+
sleep_ms(2)
|
|
230
|
+
|
|
231
|
+
def tick(t=None):
|
|
232
|
+
dt = ticks_diff(ticks_ms(), st["t0"]) or 1
|
|
233
|
+
n = st["viewers"]
|
|
234
|
+
img = st["jpeg"]
|
|
235
|
+
live.set_text(
|
|
236
|
+
"%d watching%s"
|
|
237
|
+
% (
|
|
238
|
+
n,
|
|
239
|
+
""
|
|
240
|
+
if not n
|
|
241
|
+
else ", %.1f fps, %d KB a frame, quality %d"
|
|
242
|
+
% (st["sent"] * 1000 / dt, len(img) // 1024 if img else 0, st["q"]),
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
st["loops"] = 0
|
|
246
|
+
st["sent"] = 0
|
|
247
|
+
st["t0"] = ticks_ms()
|
|
248
|
+
|
|
249
|
+
def close():
|
|
250
|
+
st["open"] = False
|
|
251
|
+
c = st["cam"]
|
|
252
|
+
st["cam"] = None
|
|
253
|
+
if c is not None:
|
|
254
|
+
c.deinit()
|
|
255
|
+
|
|
256
|
+
scope.on_close(close)
|
|
257
|
+
scope.every(2000, tick)
|
|
258
|
+
tick()
|
|
259
|
+
status.set_text("%dx%d" % (cw, chh))
|
|
260
|
+
c0 = None
|
|
261
|
+
scope.foreground(loop)
|
apps/security/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "security", "title": "Security cam", "category": "Video", "icon": "security", "color": "#8C3B1E"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Settings: what you can change about this board, one card per setting.
|
|
5
|
+
|
|
6
|
+
Device name is the name the board shows everywhere: its hostname on the
|
|
7
|
+
network, its Bluetooth and BLE names, and the USB sound card's name on a
|
|
8
|
+
computer. It is saved with ``boarddev.name``, where the board keeps its Wi-Fi
|
|
9
|
+
networks, and the radios take it up from the next start. An empty name puts
|
|
10
|
+
the board back on its default, ``omnipython-`` and the end of its unique ID.
|
|
11
|
+
|
|
12
|
+
Wi-Fi power saving lets the radio sleep between the access point's beacons:
|
|
13
|
+
it saves battery, and every reply to the board waits for the radio to wake.
|
|
14
|
+
It is on by default when a battery is fitted, and while Bluetooth runs, which
|
|
15
|
+
needs the radio to sleep to share its antenna; otherwise it's off. A choice
|
|
16
|
+
made here is remembered by ``wifi_manager``, and Default forgets it. The card
|
|
17
|
+
says which it is. A board without ``wifi_manager`` has no such card.
|
|
18
|
+
|
|
19
|
+
Network folder lists the board in computers' Network folder (Windows' File
|
|
20
|
+
Explorer) under its name, where a double click opens its WebREPL page. It's on
|
|
21
|
+
by default. The card is left out where the board can't be listed: firmware
|
|
22
|
+
without OmniPython's ``ssdp`` module, and CircuitPython.
|
|
23
|
+
|
|
24
|
+
Each card is built by one function in `CARDS`, so another setting is
|
|
25
|
+
another function there.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
import sys
|
|
29
|
+
|
|
30
|
+
import lvgl as lv
|
|
31
|
+
|
|
32
|
+
from appkit import keys
|
|
33
|
+
from touchkit import net, settings, ui
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
import boarddev
|
|
37
|
+
except ImportError:
|
|
38
|
+
boarddev = None
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
import wifi_manager
|
|
42
|
+
except ImportError:
|
|
43
|
+
wifi_manager = None # no Wi-Fi here: no power saving card
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
import ssdp
|
|
47
|
+
except ImportError:
|
|
48
|
+
ssdp = None # firmware older than the module: no Network folder card
|
|
49
|
+
|
|
50
|
+
GAP = 12
|
|
51
|
+
CARD = 0x121826 # Home's card colour
|
|
52
|
+
NAME_HINT = "Letters, digits and hyphens, up to %d. Empty goes back to the default. The network and Bluetooth use it from the next start."
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _card(parent, title):
|
|
56
|
+
"""A card in the list, with *title* at its top. Returns the card."""
|
|
57
|
+
card = ui.plain(lv.obj(parent))
|
|
58
|
+
card.set_size(lv.pct(100), lv.SIZE_CONTENT)
|
|
59
|
+
card.set_style_bg_color(lv.color_hex(CARD), 0)
|
|
60
|
+
card.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
61
|
+
card.set_style_radius(12, 0)
|
|
62
|
+
card.set_style_pad_all(GAP, 0)
|
|
63
|
+
card.set_style_pad_row(8, 0)
|
|
64
|
+
card.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
|
65
|
+
ui.label(card, title, ui.font, ui.WHITE)
|
|
66
|
+
return card
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def save_name(text):
|
|
70
|
+
"""Save *text* as the board's name, or go back to the default when it's
|
|
71
|
+
empty. Returns what to tell the user; a name the board can't take says why."""
|
|
72
|
+
text = text.strip()
|
|
73
|
+
try:
|
|
74
|
+
boarddev.name(text or None)
|
|
75
|
+
except ValueError as e:
|
|
76
|
+
return str(e)
|
|
77
|
+
except OSError as e: # CircuitPython, with CIRCUITPY mounted on a computer
|
|
78
|
+
return "Not saved: %s" % (e,)
|
|
79
|
+
return "Saved: %s. Restart the board to use it everywhere." % (boarddev.name(),)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def device_name(scope, parent):
|
|
83
|
+
"""The Device name card: the name in a field, and Save."""
|
|
84
|
+
card = _card(parent, "Device name")
|
|
85
|
+
row = ui.plain(lv.obj(card))
|
|
86
|
+
row.set_size(lv.pct(100), lv.SIZE_CONTENT)
|
|
87
|
+
row.set_flex_flow(lv.FLEX_FLOW.ROW)
|
|
88
|
+
row.set_flex_align(lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
|
89
|
+
row.set_style_pad_column(GAP, 0)
|
|
90
|
+
field = lv.textarea(row)
|
|
91
|
+
field.set_one_line(True)
|
|
92
|
+
field.set_max_length(boarddev.NAME_MAX)
|
|
93
|
+
field.set_accepted_chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")
|
|
94
|
+
field.set_text(boarddev.name())
|
|
95
|
+
field.set_flex_grow(1)
|
|
96
|
+
keys.attach(field)
|
|
97
|
+
said = ui.label(card, NAME_HINT % boarddev.NAME_MAX, ui.small, ui.MUTED)
|
|
98
|
+
said.set_width(lv.pct(100))
|
|
99
|
+
said.set_long_mode(lv.label.LONG_MODE.WRAP)
|
|
100
|
+
|
|
101
|
+
def save():
|
|
102
|
+
said.set_text(save_name(field.get_text()))
|
|
103
|
+
field.set_text(boarddev.name())
|
|
104
|
+
keys.hide()
|
|
105
|
+
|
|
106
|
+
ui.button(row, "Save", save, color=ui.PANEL)
|
|
107
|
+
# Enter on any keyboard saves too.
|
|
108
|
+
field.add_event_cb(lambda e: save(), lv.EVENT.READY, None)
|
|
109
|
+
return card
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _wifi_call(name):
|
|
113
|
+
"""``wifi_manager``'s *name* called, or None where this version hasn't it."""
|
|
114
|
+
fn = getattr(wifi_manager, name, None)
|
|
115
|
+
try:
|
|
116
|
+
return fn() if fn is not None else None
|
|
117
|
+
except Exception: # a reading that fails says nothing either way
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def power_save_state():
|
|
122
|
+
"""``(on, why)``: whether Wi-Fi power saving is on, and why: "Set by you",
|
|
123
|
+
or what makes it the default ("On by default: a battery is fitted")."""
|
|
124
|
+
chosen = (_wifi_call("_settings") or {}).get("power_save")
|
|
125
|
+
bluetooth = _wifi_call("_bluetooth_on")
|
|
126
|
+
if chosen is not None:
|
|
127
|
+
if not chosen and bluetooth:
|
|
128
|
+
return True, "On while Bluetooth runs: it shares the antenna. Off is kept for after."
|
|
129
|
+
return bool(chosen), "Set by you."
|
|
130
|
+
if bluetooth:
|
|
131
|
+
return True, "On by default: Bluetooth is running."
|
|
132
|
+
if wifi_manager.power_save():
|
|
133
|
+
return True, "On by default: a battery is fitted."
|
|
134
|
+
return False, "Off by default: no battery is fitted."
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def power_saving(scope, parent):
|
|
138
|
+
"""The Wi-Fi power saving card: a switch, why it's on or off, and Default."""
|
|
139
|
+
card = _card(parent, "Wi-Fi power saving")
|
|
140
|
+
row = ui.plain(lv.obj(card))
|
|
141
|
+
row.set_size(lv.pct(100), lv.SIZE_CONTENT)
|
|
142
|
+
row.set_flex_flow(lv.FLEX_FLOW.ROW)
|
|
143
|
+
row.set_flex_align(lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
|
144
|
+
row.set_style_pad_column(GAP, 0)
|
|
145
|
+
sw = lv.switch(row)
|
|
146
|
+
sw.set_ext_click_area(8)
|
|
147
|
+
why = ui.label(row, "", ui.small, ui.MUTED)
|
|
148
|
+
why.set_flex_grow(1)
|
|
149
|
+
why.set_long_mode(lv.label.LONG_MODE.WRAP)
|
|
150
|
+
|
|
151
|
+
def show():
|
|
152
|
+
on, said = power_save_state()
|
|
153
|
+
if on:
|
|
154
|
+
sw.add_state(lv.STATE.CHECKED)
|
|
155
|
+
else:
|
|
156
|
+
sw.remove_state(lv.STATE.CHECKED)
|
|
157
|
+
why.set_text(said)
|
|
158
|
+
|
|
159
|
+
def flipped(e):
|
|
160
|
+
wifi_manager.set_power_save(sw.has_state(lv.STATE.CHECKED))
|
|
161
|
+
show()
|
|
162
|
+
|
|
163
|
+
def default():
|
|
164
|
+
wifi_manager.set_power_save(None)
|
|
165
|
+
show()
|
|
166
|
+
|
|
167
|
+
sw.add_event_cb(flipped, lv.EVENT.VALUE_CHANGED, None)
|
|
168
|
+
ui.button(row, "Default", default, color=ui.PANEL)
|
|
169
|
+
show()
|
|
170
|
+
return card
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def network_folder(scope, parent):
|
|
174
|
+
"""The Network folder card: a switch, and what it does."""
|
|
175
|
+
card = _card(parent, "Network folder")
|
|
176
|
+
row = ui.plain(lv.obj(card))
|
|
177
|
+
row.set_size(lv.pct(100), lv.SIZE_CONTENT)
|
|
178
|
+
row.set_flex_flow(lv.FLEX_FLOW.ROW)
|
|
179
|
+
row.set_flex_align(lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
|
180
|
+
row.set_style_pad_column(GAP, 0)
|
|
181
|
+
sw = lv.switch(row)
|
|
182
|
+
sw.set_ext_click_area(8)
|
|
183
|
+
if settings.get("network_folder", True):
|
|
184
|
+
sw.add_state(lv.STATE.CHECKED)
|
|
185
|
+
why = ui.label(row, "Show this board in computers' Network folder, where a double click opens its WebREPL page.", ui.small, ui.MUTED)
|
|
186
|
+
why.set_flex_grow(1)
|
|
187
|
+
why.set_long_mode(lv.label.LONG_MODE.WRAP)
|
|
188
|
+
|
|
189
|
+
def flipped(e):
|
|
190
|
+
net.network_folder(sw.has_state(lv.STATE.CHECKED))
|
|
191
|
+
|
|
192
|
+
sw.add_event_cb(flipped, lv.EVENT.VALUE_CHANGED, None)
|
|
193
|
+
return card
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
#: The cards, top to bottom: each a function of (scope, parent) that adds one.
|
|
197
|
+
CARDS = [device_name, power_saving, network_folder]
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def main(scope):
|
|
201
|
+
if boarddev is None:
|
|
202
|
+
ui.missing(scope, "no boarddev here", "Settings saves through boarddev,\nwhich comes with OmniPython.")
|
|
203
|
+
return
|
|
204
|
+
W, H = scope.size
|
|
205
|
+
root = scope.root
|
|
206
|
+
root.set_style_bg_color(ui.BG, 0)
|
|
207
|
+
root.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
208
|
+
cards = lv.obj(root)
|
|
209
|
+
cards.set_size(W, H)
|
|
210
|
+
cards.set_style_bg_opa(lv.OPA.TRANSP, 0)
|
|
211
|
+
cards.set_style_border_width(0, 0)
|
|
212
|
+
cards.set_style_radius(0, 0)
|
|
213
|
+
cards.set_style_pad_all(GAP, 0)
|
|
214
|
+
cards.set_style_pad_gap(GAP, 0)
|
|
215
|
+
cards.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
|
216
|
+
for card in CARDS:
|
|
217
|
+
if card is power_saving and not hasattr(wifi_manager, "set_power_save"):
|
|
218
|
+
continue
|
|
219
|
+
if card is network_folder and (ssdp is None or sys.implementation.name == "circuitpython"):
|
|
220
|
+
continue
|
|
221
|
+
card(scope, cards)
|
apps/settings/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "settings", "title": "Settings", "category": "System", "icon": "settings", "color": "#3E5A6B"}
|
apps/shell/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Shell: look after the board's files from its own screen, typed on a keyboard.
|
|
5
|
+
|
|
6
|
+
The Shell is the REPL app with micropython-lib's upysh loaded into the
|
|
7
|
+
prompt, as ``from upysh import *`` would: ``ls``, ``pwd``, ``cd("lib")``,
|
|
8
|
+
``cat("boot.py")``, ``head``, ``cp``, ``mv``, ``rm``, ``mkdir``, ``rmdir``,
|
|
9
|
+
``newfile``, ``clear``, and ``man`` to list them. Everything else the REPL
|
|
10
|
+
app does, keyboards, colors, scrollback and the shared dupterm slot, is the
|
|
11
|
+
same, because it is the REPL app.
|
|
12
|
+
|
|
13
|
+
It needs upysh (``mip.install("upysh")``), and what the REPL app needs.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import __main__
|
|
17
|
+
|
|
18
|
+
from touchkit import ui
|
|
19
|
+
|
|
20
|
+
from ..repl import main as repl_main
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main(scope):
|
|
24
|
+
try:
|
|
25
|
+
import upysh
|
|
26
|
+
except ImportError:
|
|
27
|
+
ui.missing(scope, "upysh isn't installed", 'The Shell runs micropython-lib\'s upysh.\nInstall it with mip.install("upysh").')
|
|
28
|
+
return
|
|
29
|
+
# The REPL runs in __main__'s globals, so its names are what the prompt sees.
|
|
30
|
+
for name in dir(upysh):
|
|
31
|
+
if not name.startswith("_"):
|
|
32
|
+
setattr(__main__, name, getattr(upysh, name))
|
|
33
|
+
repl_main(scope)
|
apps/shell/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "shell", "title": "Shell", "category": "System", "icon": "folder_open", "color": "#3B4252", "needs": ["os.dupterm"]}
|