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/camera/__init__.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Camera: a live preview from the CSI camera, and a shutter.
|
|
5
|
+
|
|
6
|
+
The preview is cameraif's ``capture_scaled``: the P4's pixel accelerator
|
|
7
|
+
scales each frame straight into a box of the panel's framebuffer, beside
|
|
8
|
+
the LVGL widgets, and only that box is presented. A panel on a bus (SPI or
|
|
9
|
+
i80) has no framebuffer, so there the frame goes into a buffer an LVGL
|
|
10
|
+
image shows (`touchkit.cam.Preview`). It runs as the set's foreground loop,
|
|
11
|
+
one frame per call, so LVGL and the timers keep going between frames.
|
|
12
|
+
|
|
13
|
+
On a screen too narrow for the controls beside the picture (240 x 240, say)
|
|
14
|
+
the picture takes the width with the shutter under it, and the other
|
|
15
|
+
controls are left off.
|
|
16
|
+
|
|
17
|
+
The shutter takes a JPEG on the P4's encoder (``capture_jpeg``) and saves it
|
|
18
|
+
in ``/sd/photos`` on the SD card, mounted while the app is open. Without a
|
|
19
|
+
card it goes to ``/photos`` on flash, or ``/data/photos`` when flash won't
|
|
20
|
+
take it (`appkit.places`). The last shot shows on the right, and every shot
|
|
21
|
+
in all three folders is on a small web page on the board: open the address
|
|
22
|
+
on the screen from a phone or a PC.
|
|
23
|
+
|
|
24
|
+
In a browser page the camera is the one the browser gives the page, chosen
|
|
25
|
+
under Camera in Connections (from Home's bar). The shutter's photos stay
|
|
26
|
+
in the page's memory and are gone when the page reloads, and Light and
|
|
27
|
+
Brightness change nothing there.
|
|
28
|
+
|
|
29
|
+
Without a camera the app says so, and Home goes back as usual.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
import os
|
|
33
|
+
|
|
34
|
+
import lvgl as lv
|
|
35
|
+
|
|
36
|
+
from touchkit import cam, net, ui
|
|
37
|
+
from touchkit.clock import sleep_ms
|
|
38
|
+
|
|
39
|
+
PREVIEW = 400 # the preview's longer side on the panel
|
|
40
|
+
WIDE = 640 # the narrowest app area with the controls beside the picture
|
|
41
|
+
SHUTTER_H = 44 # the shutter's height under the picture on a narrow screen
|
|
42
|
+
QUALITY = 85
|
|
43
|
+
PORT = 8080
|
|
44
|
+
THUMB = 160
|
|
45
|
+
|
|
46
|
+
state = None # the open app's state, for the console
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _save(path, data):
|
|
50
|
+
for attempt in range(3):
|
|
51
|
+
try:
|
|
52
|
+
with open(path, "wb") as f:
|
|
53
|
+
f.write(data)
|
|
54
|
+
if os.stat(path)[6] == len(data):
|
|
55
|
+
return True
|
|
56
|
+
except OSError as e:
|
|
57
|
+
print("camera: write", path, e)
|
|
58
|
+
sleep_ms(100)
|
|
59
|
+
try:
|
|
60
|
+
os.remove(path) # don't leave an empty or short file behind
|
|
61
|
+
except OSError:
|
|
62
|
+
pass
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def main(scope):
|
|
67
|
+
global state
|
|
68
|
+
root = scope.root
|
|
69
|
+
status = ui.status(scope)
|
|
70
|
+
W, H = scope.size
|
|
71
|
+
RX, RY = scope.rect[:2]
|
|
72
|
+
st = state = {"cam": None, "shots": 0, "last": None, "server": None, "open": True}
|
|
73
|
+
keep = {} # the thumbnail's pixels, while LVGL shows them
|
|
74
|
+
opts = cam.options(scope)
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
st["cam"] = cam.open_camera(opts)
|
|
78
|
+
except Exception as e:
|
|
79
|
+
ui.missing(scope, "no camera", cam.no_camera_text(e, "Video Camera"))
|
|
80
|
+
return
|
|
81
|
+
|
|
82
|
+
c0 = st["cam"]
|
|
83
|
+
wide = W >= WIDE
|
|
84
|
+
if wide:
|
|
85
|
+
pw, ph = cam.preview_size(c0, PREVIEW)
|
|
86
|
+
x0, y0 = 24, 8 + (PREVIEW - ph) // 2 # in root
|
|
87
|
+
else:
|
|
88
|
+
# The picture as wide as the area, or as tall as the shutter leaves.
|
|
89
|
+
# Under the row the Home button and the status line share.
|
|
90
|
+
y0 = ui.small.line_height + 14
|
|
91
|
+
cw, ch = c0.size()[:2]
|
|
92
|
+
pw, tall = W - 8, H - y0 - SHUTTER_H - 10
|
|
93
|
+
ph = pw * ch // cw
|
|
94
|
+
if ph > tall:
|
|
95
|
+
pw, ph = tall * cw // ch, tall
|
|
96
|
+
x0 = (W - pw) // 2
|
|
97
|
+
pv = cam.Preview(root, x0, y0, pw, ph, (RX, RY))
|
|
98
|
+
|
|
99
|
+
top = 8
|
|
100
|
+
rx = 24 + PREVIEW + 24
|
|
101
|
+
rw = W - rx - 24
|
|
102
|
+
shutter, _ = ui.button(root, lv.SYMBOL.IMAGE + " Shoot", lambda: shoot(), w=rw, h=72, font=ui.big, color=ui.ACCENT)
|
|
103
|
+
shutter.set_pos(rx, top)
|
|
104
|
+
if not wide:
|
|
105
|
+
shutter.set_size(W - 8, SHUTTER_H)
|
|
106
|
+
shutter.set_pos(4, y0 + ph + 6)
|
|
107
|
+
bw = (rw - 16) // 3
|
|
108
|
+
light_b, light_l = ui.button(root, "", lambda: cycle_light(), w=bw, h=52, font=ui.small)
|
|
109
|
+
light_b.set_pos(rx, top + 84)
|
|
110
|
+
flip_b, _ = ui.button(root, "Flip", lambda: toggle("flip"), w=bw, h=52, font=ui.small)
|
|
111
|
+
flip_b.set_pos(rx + bw + 8, top + 84)
|
|
112
|
+
mirror_b, _ = ui.button(root, "Mirror", lambda: toggle("mirror"), w=bw, h=52, font=ui.small)
|
|
113
|
+
mirror_b.set_pos(rx + 2 * (bw + 8), top + 84)
|
|
114
|
+
bright_l = ui.label(root, "", ui.small, ui.MUTED)
|
|
115
|
+
bright_l.set_pos(rx, top + 146)
|
|
116
|
+
slider = lv.slider(root)
|
|
117
|
+
slider.set_range(0, 100)
|
|
118
|
+
slider.set_size(rw - 16, 14)
|
|
119
|
+
slider.set_pos(rx + 8, top + 172)
|
|
120
|
+
slider.set_value(opts["bright"], False)
|
|
121
|
+
thumb = lv.image(root)
|
|
122
|
+
thumb.set_pos(rx + (rw - THUMB) // 2, top + 200)
|
|
123
|
+
thumb.set_size(THUMB, THUMB)
|
|
124
|
+
info = ui.label(root, "", ui.small, ui.MUTED)
|
|
125
|
+
info.set_pos(rx, top + 200 + THUMB + 4)
|
|
126
|
+
info.set_width(rw)
|
|
127
|
+
if not wide:
|
|
128
|
+
for o in (light_b, flip_b, mirror_b, bright_l, slider, thumb, info):
|
|
129
|
+
o.add_flag(lv.obj.FLAG.HIDDEN)
|
|
130
|
+
|
|
131
|
+
sd = cam.mount_sd(readonly=False)
|
|
132
|
+
scope.on_close(lambda: cam.unmount_sd(sd))
|
|
133
|
+
|
|
134
|
+
def show_opts():
|
|
135
|
+
light_l.set_text("Light: " + cam.LIGHT[opts["light"] % len(cam.LIGHT)][0])
|
|
136
|
+
bright_l.set_text("Brightness %d%%" % opts["bright"])
|
|
137
|
+
for b, key in ((flip_b, "flip"), (mirror_b, "mirror")):
|
|
138
|
+
b.set_style_bg_color(ui.ACCENT if opts[key] else ui.PANEL, 0)
|
|
139
|
+
|
|
140
|
+
def apply():
|
|
141
|
+
if st["cam"] is not None:
|
|
142
|
+
cam.apply_controls(st["cam"], opts)
|
|
143
|
+
show_opts()
|
|
144
|
+
|
|
145
|
+
def cycle_light():
|
|
146
|
+
opts["light"] = (opts["light"] + 1) % len(cam.LIGHT)
|
|
147
|
+
apply()
|
|
148
|
+
|
|
149
|
+
def toggle(key):
|
|
150
|
+
# Flip or mirror: open the camera again, turned, so the colours follow.
|
|
151
|
+
opts[key] = not opts[key]
|
|
152
|
+
old = st["cam"]
|
|
153
|
+
st["cam"] = None
|
|
154
|
+
if old is not None:
|
|
155
|
+
old.deinit()
|
|
156
|
+
try:
|
|
157
|
+
st["cam"] = cam.open_camera(opts)
|
|
158
|
+
except Exception as e:
|
|
159
|
+
status.set_text("camera: %s" % (e,))
|
|
160
|
+
return
|
|
161
|
+
apply()
|
|
162
|
+
|
|
163
|
+
def bright_moved(e):
|
|
164
|
+
opts["bright"] = slider.get_value()
|
|
165
|
+
apply()
|
|
166
|
+
|
|
167
|
+
slider.add_event_cb(bright_moved, lv.EVENT.RELEASED, None)
|
|
168
|
+
slider.add_event_cb(
|
|
169
|
+
lambda e: bright_l.set_text("Brightness %d%%" % slider.get_value()), lv.EVENT.VALUE_CHANGED, None
|
|
170
|
+
)
|
|
171
|
+
apply()
|
|
172
|
+
|
|
173
|
+
def preview():
|
|
174
|
+
c = st["cam"]
|
|
175
|
+
if c is not None and pv.capture(c):
|
|
176
|
+
pv.show()
|
|
177
|
+
|
|
178
|
+
def shoot():
|
|
179
|
+
c = st["cam"]
|
|
180
|
+
img = c.capture_jpeg(QUALITY) if c is not None else None
|
|
181
|
+
if not img:
|
|
182
|
+
status.set_text("no frame")
|
|
183
|
+
return
|
|
184
|
+
try:
|
|
185
|
+
path = cam.next_name(scope)
|
|
186
|
+
except OSError as e:
|
|
187
|
+
status.set_text("nowhere to save: %s" % (e,))
|
|
188
|
+
return
|
|
189
|
+
if not _save(path, img):
|
|
190
|
+
status.set_text("couldn't save the photo")
|
|
191
|
+
return
|
|
192
|
+
st["shots"] += 1
|
|
193
|
+
st["last"] = path
|
|
194
|
+
if wide:
|
|
195
|
+
px, tw, th = ui.decode_jpeg(img, THUMB)
|
|
196
|
+
ui.rgb565_image(thumb, px, tw, th, keep)
|
|
197
|
+
status.set_text("saved %s (%d KB)" % (path.rsplit("/", 1)[1], len(img) // 1024))
|
|
198
|
+
|
|
199
|
+
# -- the web page: every shot, newest first ----------------------------------
|
|
200
|
+
|
|
201
|
+
def start_server():
|
|
202
|
+
import socket
|
|
203
|
+
import _thread
|
|
204
|
+
|
|
205
|
+
def serve():
|
|
206
|
+
s = socket.socket()
|
|
207
|
+
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
208
|
+
s.bind(("0.0.0.0", PORT))
|
|
209
|
+
s.listen(2)
|
|
210
|
+
s.settimeout(0.5)
|
|
211
|
+
st["server"] = s
|
|
212
|
+
while st["open"]:
|
|
213
|
+
try:
|
|
214
|
+
c, _ = s.accept()
|
|
215
|
+
except OSError:
|
|
216
|
+
continue
|
|
217
|
+
try:
|
|
218
|
+
c.settimeout(5)
|
|
219
|
+
_reply(c)
|
|
220
|
+
except Exception as e:
|
|
221
|
+
print("camera web:", e)
|
|
222
|
+
finally:
|
|
223
|
+
c.close()
|
|
224
|
+
s.close()
|
|
225
|
+
|
|
226
|
+
_thread.stack_size(16 * 1024)
|
|
227
|
+
try:
|
|
228
|
+
_thread.start_new_thread(serve, ())
|
|
229
|
+
finally:
|
|
230
|
+
_thread.stack_size(0)
|
|
231
|
+
|
|
232
|
+
def _reply(c):
|
|
233
|
+
line = c.readline()
|
|
234
|
+
while c.readline() not in (b"\r\n", b"\n", b""):
|
|
235
|
+
pass
|
|
236
|
+
parts = line.split()
|
|
237
|
+
path = parts[1].decode() if len(parts) > 1 else "/"
|
|
238
|
+
if parts and parts[0] == b"POST" and path.startswith("/delete/"):
|
|
239
|
+
# One photo, or "all" of them.
|
|
240
|
+
key = path[8:]
|
|
241
|
+
for k, p in cam.photos(scope):
|
|
242
|
+
if key == "all" or k == key:
|
|
243
|
+
try:
|
|
244
|
+
os.remove(p)
|
|
245
|
+
except OSError as e:
|
|
246
|
+
print("camera web: delete %s: %s" % (p, e))
|
|
247
|
+
c.write(b"HTTP/1.0 303 See Other\r\nLocation: /\r\n\r\n")
|
|
248
|
+
return
|
|
249
|
+
if path.startswith("/photo/"):
|
|
250
|
+
key = path[7:]
|
|
251
|
+
for k, p in cam.photos(scope):
|
|
252
|
+
if k == key:
|
|
253
|
+
c.write(b"HTTP/1.0 200 OK\r\nContent-Type: image/jpeg\r\n\r\n")
|
|
254
|
+
with open(p, "rb") as f:
|
|
255
|
+
buf = bytearray(16384)
|
|
256
|
+
while True:
|
|
257
|
+
n = f.readinto(buf)
|
|
258
|
+
if not n:
|
|
259
|
+
break
|
|
260
|
+
c.write(buf[:n])
|
|
261
|
+
return
|
|
262
|
+
c.write(b"HTTP/1.0 404 Not Found\r\n\r\n")
|
|
263
|
+
return
|
|
264
|
+
photos = cam.photos(scope)
|
|
265
|
+
rows = "".join(
|
|
266
|
+
'<div><a href="/photo/{0}"><img src="/photo/{0}" loading="lazy"></a><br>{1}{2}</div>'.format(
|
|
267
|
+
k,
|
|
268
|
+
k.replace("/", ": "),
|
|
269
|
+
' <form method=post action="/delete/{0}" onsubmit="return confirm(\'Delete {0}?\')">'
|
|
270
|
+
"<button>Delete</button></form>".format(k),
|
|
271
|
+
)
|
|
272
|
+
for k, p in photos
|
|
273
|
+
)
|
|
274
|
+
if photos:
|
|
275
|
+
rows = (
|
|
276
|
+
'<form method=post action="/delete/all" onsubmit="return confirm(\'Delete every photo?\')">'
|
|
277
|
+
"<button class=all>Delete all</button></form>"
|
|
278
|
+
) + rows
|
|
279
|
+
html = (
|
|
280
|
+
"<!doctype html><meta name=viewport content='width=device-width'>"
|
|
281
|
+
"<title>Camera</title><style>body{font-family:sans-serif;background:#0b0e14;color:#ccc}"
|
|
282
|
+
"div{display:inline-block;margin:6px;font-size:13px;vertical-align:top}"
|
|
283
|
+
"img{width:220px;border-radius:8px}form{display:inline}"
|
|
284
|
+
"button{background:#3a2028;color:#f9b;border:1px solid #634;border-radius:6px;padding:2px 8px;cursor:pointer}"
|
|
285
|
+
"button.all{margin:0 6px 10px;padding:6px 12px}</style><h2>Camera</h2>"
|
|
286
|
+
+ (rows or "<p>No photos yet: press Shoot on the board.</p>")
|
|
287
|
+
)
|
|
288
|
+
c.write(b"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
|
|
289
|
+
c.write(html.encode())
|
|
290
|
+
|
|
291
|
+
ip = net.ip()
|
|
292
|
+
name = net.hostname()
|
|
293
|
+
where = "Photos go to the SD card." if sd else "Photos go to the board's flash."
|
|
294
|
+
if ip:
|
|
295
|
+
info.set_text(
|
|
296
|
+
"%s\nOpen %shttp://%s:%d to see them."
|
|
297
|
+
% (where, "http://%s.local:%d or " % (name, PORT) if name else "", ip, PORT)
|
|
298
|
+
)
|
|
299
|
+
try:
|
|
300
|
+
start_server()
|
|
301
|
+
except Exception as e:
|
|
302
|
+
print("camera: web page:", e)
|
|
303
|
+
else:
|
|
304
|
+
info.set_text(where + "\nNo Wi-Fi: no web page.")
|
|
305
|
+
|
|
306
|
+
def close():
|
|
307
|
+
st["open"] = False # the web page's thread ends within half a second
|
|
308
|
+
c = st["cam"]
|
|
309
|
+
st["cam"] = None
|
|
310
|
+
if c is not None:
|
|
311
|
+
c.deinit()
|
|
312
|
+
|
|
313
|
+
scope.on_close(close)
|
|
314
|
+
status.set_text("%s ready" % (c0.sensor()[0],) if hasattr(c0, "sensor") else "ready")
|
|
315
|
+
c0 = None
|
|
316
|
+
scope.foreground(preview)
|
apps/camera/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "camera", "title": "Video Camera", "category": "Video", "icon": "photo_camera", "color": "#1E6F8C", "bar": "none"}
|
apps/card/__init__.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Sound card: the board as a USB speaker, with the spectrum of what the PC
|
|
5
|
+
plays under the header.
|
|
6
|
+
|
|
7
|
+
The board is "Speakers (Espressif Device)" on Windows, on its device USB
|
|
8
|
+
port: usb-device-audio's speaker streams from the USB interrupt into an
|
|
9
|
+
audiopump ring, and audiodsp's pump plays that ring on the codec. Python only
|
|
10
|
+
keeps the clock feedback in step and follows the PC's volume. The meter is
|
|
11
|
+
the pump's own tap, so it shows whatever the pump plays.
|
|
12
|
+
|
|
13
|
+
It needs micropython-lib's ``usb-device`` and omnipython's ``usb-device-audio`` in
|
|
14
|
+
``/lib``, and gallery's spectrum analyzer for the meter.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import lvgl as lv
|
|
18
|
+
|
|
19
|
+
import spectrum
|
|
20
|
+
from touchkit import ui
|
|
21
|
+
|
|
22
|
+
VOLUME = 85 # the panel's listening level; the PC's slider moves it down from here
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _percent(spk):
|
|
26
|
+
if spk.mute:
|
|
27
|
+
return 0
|
|
28
|
+
db = max(-50 * 256, min(0, spk.volume))
|
|
29
|
+
return round(VOLUME * (1 + db / (50 * 256)))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def main(scope):
|
|
33
|
+
status = ui.status(scope)
|
|
34
|
+
# machine is imported here, not at the top, so the app imports on any
|
|
35
|
+
# Python and says why it can't run instead of failing to load.
|
|
36
|
+
try:
|
|
37
|
+
import machine
|
|
38
|
+
except ImportError:
|
|
39
|
+
ui.missing(scope, "no machine", "Sound card needs a board: this Python has no machine module.")
|
|
40
|
+
return
|
|
41
|
+
try:
|
|
42
|
+
import audiopump
|
|
43
|
+
import usb.device
|
|
44
|
+
from audiodev import AudioFormat, pump
|
|
45
|
+
from boarddev import pcm_out
|
|
46
|
+
from usb.device.audio import SpeakerInterface
|
|
47
|
+
except ImportError as e:
|
|
48
|
+
ui.missing(scope, "missing: %s" % e, "Sound card needs usb-device and usb-device-audio in /lib: %s." % (e,))
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
if not hasattr(machine, "USBDevice"):
|
|
52
|
+
ui.missing(scope, "no USB device", "Sound card needs a USB device port, and this firmware has none.")
|
|
53
|
+
return
|
|
54
|
+
fmt = AudioFormat(48000, 2, 16)
|
|
55
|
+
# The speaker first: without one, the board must not become a USB sound
|
|
56
|
+
# card the PC would play into.
|
|
57
|
+
try:
|
|
58
|
+
transport = pcm_out(fmt)
|
|
59
|
+
except Exception as e:
|
|
60
|
+
ui.missing(scope, "no speaker", "Sound card needs a speaker on this board: %s." % (e,))
|
|
61
|
+
return
|
|
62
|
+
ring = audiopump.Ring(sample_rate=48000, channel_count=2, frames=480, capacity=8)
|
|
63
|
+
spk = SpeakerInterface(sink=ring)
|
|
64
|
+
import boarddev
|
|
65
|
+
|
|
66
|
+
usb.device.get().init(spk, builtin_driver=True, product_str=boarddev.name()) # the PC lists the board's name
|
|
67
|
+
while transport is not None and getattr(transport, "wire", None) is None:
|
|
68
|
+
transport = getattr(transport, "_inner", None)
|
|
69
|
+
driver = pump.BusioDriver(transport.wire, fmt, power=getattr(transport, "audio_power", None),
|
|
70
|
+
volume=VOLUME, transport=transport)
|
|
71
|
+
pump.owner().play(spk, ring, driver=driver, raises=True)
|
|
72
|
+
state = {"m": None, "level": None, "bytes": None}
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
from spectrum.pump_levels import TapLevels
|
|
76
|
+
|
|
77
|
+
m = spectrum.meter(scope, lambda bands: TapLevels(bands, rate=48000, channels=2), 0)
|
|
78
|
+
state["m"] = m
|
|
79
|
+
except Exception as e:
|
|
80
|
+
print("card: no meter:", e)
|
|
81
|
+
|
|
82
|
+
def close():
|
|
83
|
+
pump.owner().stop(spk)
|
|
84
|
+
usb.device.get().init(builtin_driver=True) # the console alone again
|
|
85
|
+
state["m"] = None
|
|
86
|
+
|
|
87
|
+
scope.on_close(close)
|
|
88
|
+
|
|
89
|
+
def begin(t):
|
|
90
|
+
if state["m"] is not None:
|
|
91
|
+
spectrum.start(state["m"], scope, (getattr(scope, "header", None) or scope.root,))
|
|
92
|
+
|
|
93
|
+
scope.after(300, begin)
|
|
94
|
+
|
|
95
|
+
def service(t):
|
|
96
|
+
# Keep the clock feedback in step with the ring, and the codec with
|
|
97
|
+
# the PC's volume slider and mute.
|
|
98
|
+
spk.service()
|
|
99
|
+
now = _percent(spk)
|
|
100
|
+
if now != state["level"]:
|
|
101
|
+
transport.set_volume(now)
|
|
102
|
+
state["level"] = now
|
|
103
|
+
|
|
104
|
+
scope.every(5, service)
|
|
105
|
+
|
|
106
|
+
def tick(t):
|
|
107
|
+
got = ring.stats()[0]
|
|
108
|
+
playing = spk.streaming and got != state["bytes"]
|
|
109
|
+
state["bytes"] = got
|
|
110
|
+
status.set_text('Play to "Speakers (Espressif Device)" %s' % ("playing" if playing else "idle"))
|
|
111
|
+
|
|
112
|
+
tick(None)
|
|
113
|
+
scope.every(1000, tick)
|
apps/card/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "card", "title": "Sound card", "category": "Audio", "icon": "speaker", "color": "#1E6F8C"}
|