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/info/__init__.py
ADDED
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Info: whether this board is well, at a glance.
|
|
5
|
+
|
|
6
|
+
The arc turns once a second, stepping every frame, with the seconds counted in
|
|
7
|
+
its middle: when the arc and the count drift apart, so do the timers. Beside
|
|
8
|
+
it are the display's frame rate, the interpreter and its version, and a button that counts taps and shows where
|
|
9
|
+
the last touch landed, so touch turned the wrong way on a rotated panel shows
|
|
10
|
+
at once. The moving parts share one card, so the screen redraws as little as
|
|
11
|
+
it can while it measures itself.
|
|
12
|
+
|
|
13
|
+
The rows go in order of importance: memory, boot, network, audio, then what
|
|
14
|
+
the board is. The moving card's font is the largest the firmware has at or
|
|
15
|
+
below a twentieth of the screen's short side. The rows take the largest at or
|
|
16
|
+
below that which fits them all; a screen too small for all of them at the
|
|
17
|
+
smallest font drops them from the end. The cards sit side by side only when
|
|
18
|
+
the screen is more than 1.5 times wider than tall.
|
|
19
|
+
|
|
20
|
+
On a round screen everything goes in one centred column, each line no wider
|
|
21
|
+
than the circle is at its height, and the rows go on down while the circle
|
|
22
|
+
leaves them two fifths of its width. A driver says its panel is round with a
|
|
23
|
+
``round`` attribute; a GC9A01's is taken to be.
|
|
24
|
+
|
|
25
|
+
On a screen 400 pixels or more on its short side, More has the last app
|
|
26
|
+
switches, the restarts, the largest free block and a Wi-Fi button, which
|
|
27
|
+
opens the connections picker at the networks in range. Wi-Fi power saving
|
|
28
|
+
is in Settings. The heap line
|
|
29
|
+
there is the one to watch: switching back and forth all day should leave
|
|
30
|
+
"in use" where it started, give or take a few KB.
|
|
31
|
+
|
|
32
|
+
`stats` returns the same numbers as a dict, whether the screen is open or
|
|
33
|
+
not, so they can be read from the REPL while the apps keep running::
|
|
34
|
+
|
|
35
|
+
>>> import apps.info
|
|
36
|
+
>>> apps.info.stats()
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
import gc
|
|
40
|
+
import os
|
|
41
|
+
import sys
|
|
42
|
+
import time
|
|
43
|
+
|
|
44
|
+
import lvgl as lv
|
|
45
|
+
|
|
46
|
+
from touchkit import net, shell, ui
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
from board_config import display_drv
|
|
50
|
+
except ImportError:
|
|
51
|
+
display_drv = None
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
import machine
|
|
55
|
+
except ImportError:
|
|
56
|
+
machine = None
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
import esp32
|
|
60
|
+
except ImportError:
|
|
61
|
+
esp32 = None
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
import microcontroller # CircuitPython's
|
|
65
|
+
except ImportError:
|
|
66
|
+
microcontroller = None
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
import platform
|
|
70
|
+
except ImportError:
|
|
71
|
+
platform = None
|
|
72
|
+
|
|
73
|
+
_SIZES = tuple(range(12, 50, 2)) # the Montserrat sizes LVGL builds, from the smallest worth reading
|
|
74
|
+
GC_MS = 10000 # how often the open screen times a collection
|
|
75
|
+
ROWS_MS = 5000 # how often the rows are read again
|
|
76
|
+
SMALL = 400 # below this short side there's no More page
|
|
77
|
+
|
|
78
|
+
# What the open screen has counted, for stats().
|
|
79
|
+
_st = {"seconds": None, "taps": 0, "touch": None, "gc_ms": None}
|
|
80
|
+
_ident = {} # what doesn't change while the board runs, read once
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# -- reading the board ---------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _ticks_ms():
|
|
87
|
+
try:
|
|
88
|
+
return time.ticks_ms()
|
|
89
|
+
except AttributeError: # CPython
|
|
90
|
+
return int(time.monotonic() * 1000)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _ticks_diff(a, b):
|
|
94
|
+
try:
|
|
95
|
+
return time.ticks_diff(a, b)
|
|
96
|
+
except AttributeError:
|
|
97
|
+
return a - b
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _uptime_s():
|
|
101
|
+
# CPython's and CircuitPython's monotonic clocks start at boot; MicroPython
|
|
102
|
+
# has the tick counter, which wraps after some days on most ports.
|
|
103
|
+
mono = getattr(time, "monotonic", None)
|
|
104
|
+
if mono is not None:
|
|
105
|
+
return int(mono())
|
|
106
|
+
return time.ticks_ms() // 1000
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def collect():
|
|
110
|
+
"""Run ``gc.collect()`` and return how many milliseconds it took."""
|
|
111
|
+
t = _ticks_ms()
|
|
112
|
+
gc.collect()
|
|
113
|
+
ms = _ticks_diff(_ticks_ms(), t)
|
|
114
|
+
_st["gc_ms"] = ms
|
|
115
|
+
return ms
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _reset_cause():
|
|
119
|
+
if machine is not None and hasattr(machine, "reset_cause"):
|
|
120
|
+
try:
|
|
121
|
+
cause = machine.reset_cause()
|
|
122
|
+
except Exception:
|
|
123
|
+
return None
|
|
124
|
+
for const, text in (
|
|
125
|
+
("PWRON_RESET", "power on"),
|
|
126
|
+
("HARD_RESET", "hard reset"),
|
|
127
|
+
("WDT_RESET", "watchdog"),
|
|
128
|
+
("DEEPSLEEP_RESET", "deep sleep"),
|
|
129
|
+
("SOFT_RESET", "soft reset"),
|
|
130
|
+
("BROWNOUT_RESET", "brownout"),
|
|
131
|
+
):
|
|
132
|
+
if getattr(machine, const, None) == cause:
|
|
133
|
+
return text
|
|
134
|
+
return str(cause)
|
|
135
|
+
if microcontroller is not None:
|
|
136
|
+
try:
|
|
137
|
+
reason = str(microcontroller.cpu.reset_reason)
|
|
138
|
+
except Exception:
|
|
139
|
+
return None
|
|
140
|
+
return reason[reason.rfind(".") + 1 :].replace("_", " ").lower()
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _built():
|
|
145
|
+
"""The day this interpreter was built."""
|
|
146
|
+
build = getattr(platform, "python_build", None)
|
|
147
|
+
if build is not None: # CPython: "Aug 14 2024 14:39:54"
|
|
148
|
+
try:
|
|
149
|
+
return " ".join(build()[1].split()[:3])
|
|
150
|
+
except Exception:
|
|
151
|
+
return None
|
|
152
|
+
try:
|
|
153
|
+
version = os.uname().version # "v1.30.0-preview on 2026-11-05"
|
|
154
|
+
except Exception:
|
|
155
|
+
return None
|
|
156
|
+
i = version.rfind(" on ")
|
|
157
|
+
return version[i + 4 :].split()[0] if i >= 0 else None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _interpreter():
|
|
161
|
+
impl = sys.implementation
|
|
162
|
+
name = {"micropython": "MicroPython", "circuitpython": "CircuitPython", "cpython": "CPython"}.get(
|
|
163
|
+
impl.name, impl.name
|
|
164
|
+
)
|
|
165
|
+
if impl.name == "circuitpython":
|
|
166
|
+
# Its version tuple leaves out the pre-release, which tells one
|
|
167
|
+
# alpha from the next: "11.0.0-alpha.2 on 2026-11-05".
|
|
168
|
+
try:
|
|
169
|
+
return "%s %s" % (name, os.uname().version.split(" on ")[0])
|
|
170
|
+
except Exception:
|
|
171
|
+
pass
|
|
172
|
+
v = impl.version
|
|
173
|
+
return "%s %d.%d.%d" % (name, v[0], v[1], v[2])
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _board_and_cpu():
|
|
177
|
+
board = getattr(sys.implementation, "_machine", None)
|
|
178
|
+
if board: # "Generic ESP32S3 module with ESP32S3": the CPU has a row of its own
|
|
179
|
+
i = board.rfind(" with ")
|
|
180
|
+
return (board[:i], board[i + 6 :]) if i >= 0 else (board, None)
|
|
181
|
+
arch = None
|
|
182
|
+
if platform is not None and hasattr(platform, "machine"):
|
|
183
|
+
arch = platform.machine()
|
|
184
|
+
return "%s computer" % sys.platform, arch
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _mhz():
|
|
188
|
+
try:
|
|
189
|
+
if machine is not None:
|
|
190
|
+
f = machine.freq()
|
|
191
|
+
if isinstance(f, tuple): # stm32: (sysclk, hclk, pclk1, pclk2)
|
|
192
|
+
f = f[0]
|
|
193
|
+
return f // 1000000
|
|
194
|
+
if microcontroller is not None:
|
|
195
|
+
return microcontroller.cpu.frequency // 1000000
|
|
196
|
+
except Exception:
|
|
197
|
+
pass
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _temp_c():
|
|
202
|
+
"""The chip's own temperature in degrees C, where it has a sensor."""
|
|
203
|
+
try:
|
|
204
|
+
if esp32 is not None and hasattr(esp32, "mcu_temperature"):
|
|
205
|
+
return esp32.mcu_temperature()
|
|
206
|
+
if microcontroller is not None:
|
|
207
|
+
t = microcontroller.cpu.temperature
|
|
208
|
+
return None if t is None else round(t)
|
|
209
|
+
except Exception:
|
|
210
|
+
pass
|
|
211
|
+
return None
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _identity():
|
|
215
|
+
if not _ident:
|
|
216
|
+
board, cpu = _board_and_cpu()
|
|
217
|
+
_ident.update(
|
|
218
|
+
board=board,
|
|
219
|
+
cpu=cpu,
|
|
220
|
+
mhz=_mhz(),
|
|
221
|
+
python=_interpreter(),
|
|
222
|
+
built=_built(),
|
|
223
|
+
reset=_reset_cause(),
|
|
224
|
+
)
|
|
225
|
+
name = net.hostname()
|
|
226
|
+
if name and hasattr(sys.implementation, "_machine"):
|
|
227
|
+
name += ".local"
|
|
228
|
+
_ident["hostname"] = name
|
|
229
|
+
return _ident
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _audio():
|
|
233
|
+
"""``(pump running, underruns)``. The pump is only asked when something
|
|
234
|
+
has loaded it: then it can't be running, and nothing new is imported."""
|
|
235
|
+
p = sys.modules.get("audiodev.pump")
|
|
236
|
+
if p is None:
|
|
237
|
+
return False, None
|
|
238
|
+
try:
|
|
239
|
+
h = p.health()
|
|
240
|
+
except Exception:
|
|
241
|
+
h = None
|
|
242
|
+
if h is None:
|
|
243
|
+
return False, None
|
|
244
|
+
return bool(h.get("running")), h.get("dropped")
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def stats(collect_now=False):
|
|
248
|
+
"""What the Info screen shows, as a dict, whether it's open or not.
|
|
249
|
+
|
|
250
|
+
It reads everything fresh but the identity, and blocks for nothing:
|
|
251
|
+
``gc_ms`` is the last collection the open screen timed, unless
|
|
252
|
+
*collect_now* runs one here. ``seconds``, ``fps`` and the touch figures
|
|
253
|
+
are from the screen, and ``None`` (or 0 taps) while it's closed.
|
|
254
|
+
"""
|
|
255
|
+
if collect_now:
|
|
256
|
+
collect()
|
|
257
|
+
s = dict(_identity())
|
|
258
|
+
s["open"] = _st["seconds"] is not None
|
|
259
|
+
s["seconds"] = _st["seconds"]
|
|
260
|
+
s["taps"] = _st["taps"]
|
|
261
|
+
s["touch"] = _st["touch"]
|
|
262
|
+
fps = getattr(display_drv, "fps", None)
|
|
263
|
+
s["fps"] = fps() if fps is not None else None
|
|
264
|
+
if hasattr(gc, "mem_free"):
|
|
265
|
+
s["heap_free"] = gc.mem_free()
|
|
266
|
+
s["heap_used"] = gc.mem_alloc()
|
|
267
|
+
else: # CPython counts no heap of its own
|
|
268
|
+
s["heap_free"] = s["heap_used"] = None
|
|
269
|
+
s["gc_ms"] = _st["gc_ms"]
|
|
270
|
+
s["uptime_s"] = _uptime_s()
|
|
271
|
+
s["ip"] = net.ip()
|
|
272
|
+
s["rssi"] = net.rssi()
|
|
273
|
+
s["webrepl"] = net.webrepl_on()
|
|
274
|
+
s["pump"], s["underruns"] = _audio()
|
|
275
|
+
s["temp_c"] = _temp_c()
|
|
276
|
+
s["screen"] = (int(display_drv.width), int(display_drv.height)) if display_drv is not None else None
|
|
277
|
+
s["rotation"] = int(getattr(display_drv, "rotation", 0) or 0)
|
|
278
|
+
return s
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
# -- the rows, in order of importance ------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _size(n):
|
|
285
|
+
return "%.2f MB" % (n / 1e6) if n >= 1000000 else "%d KB" % (n // 1024)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _duration(sec):
|
|
289
|
+
d, sec = divmod(sec, 86400)
|
|
290
|
+
h, sec = divmod(sec, 3600)
|
|
291
|
+
m, sec = divmod(sec, 60)
|
|
292
|
+
if d:
|
|
293
|
+
return "%d d %d h" % (d, h)
|
|
294
|
+
if h:
|
|
295
|
+
return "%d h %02d min" % (h, m)
|
|
296
|
+
if m:
|
|
297
|
+
return "%d min" % m
|
|
298
|
+
return "%d s" % sec
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _memory(s):
|
|
302
|
+
if s["heap_free"] is None:
|
|
303
|
+
return "not counted here"
|
|
304
|
+
return "%s free, %s used" % (_size(s["heap_free"]), _size(s["heap_used"]))
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _boot(s):
|
|
308
|
+
up = "up " + _duration(s["uptime_s"])
|
|
309
|
+
return "%s, %s" % (up, s["reset"]) if s["reset"] else up
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _network(s):
|
|
313
|
+
if not s["ip"]:
|
|
314
|
+
return "not connected"
|
|
315
|
+
return "%s, %d dBm" % (s["ip"], s["rssi"]) if s["rssi"] else s["ip"]
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _pump(s):
|
|
319
|
+
if s["underruns"] is None and not s["pump"]:
|
|
320
|
+
return "pump not started"
|
|
321
|
+
return "pump %s, %d underruns" % ("running" if s["pump"] else "stopped", s["underruns"] or 0)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _cpu(s):
|
|
325
|
+
parts = [p for p in (s["cpu"], s["mhz"] and "%d MHz" % s["mhz"]) if p]
|
|
326
|
+
if s["temp_c"] is not None:
|
|
327
|
+
parts.append("%d °C" % s["temp_c"])
|
|
328
|
+
return ", ".join(parts) or "-"
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _screen(s):
|
|
332
|
+
if s["screen"] is None:
|
|
333
|
+
return "-"
|
|
334
|
+
return "%dx%d, rotation %d" % (s["screen"][0], s["screen"][1], s["rotation"])
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
ROWS = (
|
|
338
|
+
("Memory", _memory),
|
|
339
|
+
("Collect", lambda s: "-" if s["gc_ms"] is None else "%d ms" % s["gc_ms"]),
|
|
340
|
+
("Boot", _boot),
|
|
341
|
+
("Built", lambda s: s["built"] or "-"),
|
|
342
|
+
("Network", _network),
|
|
343
|
+
("WebREPL", lambda s: "on" if s["webrepl"] else "off"),
|
|
344
|
+
("Audio", _pump),
|
|
345
|
+
("Board", lambda s: s["board"] or "-"),
|
|
346
|
+
("Host", lambda s: s["hostname"] or "-"),
|
|
347
|
+
("CPU", _cpu),
|
|
348
|
+
("Screen", _screen),
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
# -- the screen ------------------------------------------------------------------------
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _fonts(limit):
|
|
356
|
+
"""The Montserrat sizes this firmware has at or below *limit* pixels,
|
|
357
|
+
smallest first; the smallest it has when none is that small."""
|
|
358
|
+
fonts = []
|
|
359
|
+
for size in _SIZES:
|
|
360
|
+
font = getattr(lv, "font_montserrat_%d" % size, None)
|
|
361
|
+
if font is not None and (not fonts or size <= limit):
|
|
362
|
+
fonts.append(font)
|
|
363
|
+
return fonts or [lv.font_get_default()]
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _font_for(short):
|
|
367
|
+
"""The largest Montserrat this firmware has at or below a twentieth of
|
|
368
|
+
*short*, or its smallest when none is that small."""
|
|
369
|
+
return _fonts(short // 20)[-1]
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def _card(parent, flow, pad):
|
|
373
|
+
c = lv.obj(parent)
|
|
374
|
+
c.set_style_bg_color(ui.PANEL, 0)
|
|
375
|
+
c.set_style_text_color(ui.WHITE, 0)
|
|
376
|
+
c.set_style_border_width(0, 0)
|
|
377
|
+
c.set_style_radius(pad * 2, 0)
|
|
378
|
+
c.set_style_pad_all(pad, 0)
|
|
379
|
+
c.set_style_pad_gap(pad // 2, 0)
|
|
380
|
+
c.set_flex_flow(flow)
|
|
381
|
+
c.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
382
|
+
c.add_flag(lv.obj.FLAG.EVENT_BUBBLE) # a press anywhere shows where it landed
|
|
383
|
+
return c
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def _dark(obj):
|
|
387
|
+
"""Info's own colours on *obj*, so it reads the same whether or not the
|
|
388
|
+
shell put a dark theme on the display."""
|
|
389
|
+
obj.set_style_bg_color(ui.BG, 0)
|
|
390
|
+
obj.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
391
|
+
obj.set_style_text_color(ui.WHITE, 0)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def _is_round():
|
|
395
|
+
"""Whether the panel is round: its driver says so with ``round``, or it's
|
|
396
|
+
a GC9A01, a controller made for round panels."""
|
|
397
|
+
if display_drv is None or int(display_drv.width) != int(display_drv.height):
|
|
398
|
+
return False
|
|
399
|
+
r = getattr(display_drv, "round", None)
|
|
400
|
+
if r is None:
|
|
401
|
+
r = type(display_drv).__name__.upper().startswith("GC9A01")
|
|
402
|
+
return bool(r)
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _round_page(root, size, font, big, pad, tapped, more=None):
|
|
406
|
+
"""Info on a round screen: one centred column, each line no wider than
|
|
407
|
+
the circle is at its height.
|
|
408
|
+
|
|
409
|
+
Returns ``(page, arc, seconds, fps, tap, touch, more, info, values)``:
|
|
410
|
+
*more* is the More button when *more* is given, and the rows are *info*'s
|
|
411
|
+
children. A row with too little of the circle left for it is hidden, as
|
|
412
|
+
the square layout hides the rows that don't fit.
|
|
413
|
+
"""
|
|
414
|
+
page = ui.plain(lv.obj(root))
|
|
415
|
+
page.set_size(size, size)
|
|
416
|
+
page.set_style_text_font(font, 0)
|
|
417
|
+
page.add_flag(lv.obj.FLAG.CLICKABLE)
|
|
418
|
+
_dark(page)
|
|
419
|
+
r = size // 2
|
|
420
|
+
inner = r - pad # everything keeps inside this circle
|
|
421
|
+
gap = max(2, pad // 2)
|
|
422
|
+
|
|
423
|
+
# As small as the square layout's smallest: an arc round the rim looked
|
|
424
|
+
# right, but its redraws halved the frame rate it was there to show.
|
|
425
|
+
d = max(4 * font.line_height, size // 4)
|
|
426
|
+
width = max(4, d // 12)
|
|
427
|
+
arc = lv.arc(page)
|
|
428
|
+
arc.set_size(d, d)
|
|
429
|
+
arc.set_bg_angles(0, 360)
|
|
430
|
+
arc.set_rotation(270)
|
|
431
|
+
arc.set_angles(0, 0)
|
|
432
|
+
arc.remove_style(None, lv.PART.KNOB)
|
|
433
|
+
arc.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
434
|
+
arc.set_style_arc_width(width, lv.PART.MAIN)
|
|
435
|
+
arc.set_style_arc_width(width, lv.PART.INDICATOR)
|
|
436
|
+
|
|
437
|
+
def room(y, h):
|
|
438
|
+
# The circle's width across the band from y to y + h, at its narrowest.
|
|
439
|
+
dy = max(abs(y - r), abs(y + h - r))
|
|
440
|
+
return 2 * int((inner * inner - dy * dy) ** 0.5) if dy < inner else 0
|
|
441
|
+
|
|
442
|
+
def place(obj, y, w):
|
|
443
|
+
# Centred at the first y, going down, where the circle is w wide.
|
|
444
|
+
h = obj.get_height()
|
|
445
|
+
while room(y, h) < w and y < r:
|
|
446
|
+
y += 1
|
|
447
|
+
obj.set_pos(r - w // 2, y)
|
|
448
|
+
return y + h + gap
|
|
449
|
+
|
|
450
|
+
def line(text, sample, font=None, color=None):
|
|
451
|
+
# A centred label as wide as *sample*, the widest text it will show.
|
|
452
|
+
lbl = ui.label(page, sample, font, color)
|
|
453
|
+
page.update_layout()
|
|
454
|
+
lbl.set_width(lbl.get_width())
|
|
455
|
+
lbl.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
456
|
+
lbl.set_text(text)
|
|
457
|
+
return lbl
|
|
458
|
+
|
|
459
|
+
# The count takes the big font only while four digits fit inside the arc.
|
|
460
|
+
seconds_lbl = ui.label(arc, "0000", big)
|
|
461
|
+
arc.update_layout()
|
|
462
|
+
if seconds_lbl.get_width() > d - 2 * width - 4:
|
|
463
|
+
seconds_lbl.set_style_text_font(font, 0)
|
|
464
|
+
seconds_lbl.set_text("0")
|
|
465
|
+
seconds_lbl.center()
|
|
466
|
+
fps_lbl = line(_fps_text(False), "88.8 fps, 88.8 ms, 100% busy", None, ui.MUTED)
|
|
467
|
+
python_lbl = line(_identity()["python"], _identity()["python"])
|
|
468
|
+
buttons = _box(page, lv.FLEX_FLOW.ROW, pad)
|
|
469
|
+
_, tap_lbl = _button(buttons, "Tap 0", pad, tapped)
|
|
470
|
+
more_btn = None
|
|
471
|
+
if more is not None:
|
|
472
|
+
more_btn, _ = _button(buttons, "More", pad, more)
|
|
473
|
+
more_btn.set_style_bg_color(ui.KEY, 0)
|
|
474
|
+
touch_lbl = ui.label(buttons, "touch 888, 888", None, ui.MUTED)
|
|
475
|
+
page.update_layout()
|
|
476
|
+
touch_lbl.set_width(touch_lbl.get_width())
|
|
477
|
+
touch_lbl.set_text("touch -")
|
|
478
|
+
page.update_layout()
|
|
479
|
+
y = r - inner
|
|
480
|
+
for obj in (arc, fps_lbl, python_lbl, buttons):
|
|
481
|
+
y = place(obj, y, obj.get_width())
|
|
482
|
+
|
|
483
|
+
# The rows, in order of importance, while the circle leaves them room.
|
|
484
|
+
info = ui.plain(lv.obj(page))
|
|
485
|
+
info.remove_flag(lv.obj.FLAG.CLICKABLE) # the Tap button above it stays pressable
|
|
486
|
+
info.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
|
487
|
+
info.set_pos(0, y)
|
|
488
|
+
info.set_size(size, size - y)
|
|
489
|
+
top = y
|
|
490
|
+
line_h = font.line_height
|
|
491
|
+
narrowest = size * 2 // 5
|
|
492
|
+
values = []
|
|
493
|
+
for key, _fn in ROWS:
|
|
494
|
+
w = room(y, line_h)
|
|
495
|
+
row = ui.plain(lv.obj(info))
|
|
496
|
+
row.set_size(max(w, narrowest), line_h)
|
|
497
|
+
row.set_pos(r - max(w, narrowest) // 2, y - top)
|
|
498
|
+
row.set_flex_flow(lv.FLEX_FLOW.ROW)
|
|
499
|
+
row.set_style_pad_column(pad, 0)
|
|
500
|
+
row.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
|
501
|
+
ui.label(row, key, None, ui.MUTED)
|
|
502
|
+
v = lv.label(row)
|
|
503
|
+
v.set_flex_grow(1)
|
|
504
|
+
v.set_height(line_h)
|
|
505
|
+
v.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
506
|
+
v.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
|
|
507
|
+
values.append(v)
|
|
508
|
+
if w < narrowest:
|
|
509
|
+
row.add_flag(lv.obj.FLAG.HIDDEN)
|
|
510
|
+
y += line_h + gap
|
|
511
|
+
return page, arc, seconds_lbl, fps_lbl, tap_lbl, touch_lbl, more_btn, info, values
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def _box(parent, flow, gap):
|
|
515
|
+
b = ui.plain(lv.obj(parent))
|
|
516
|
+
b.set_size(lv.SIZE_CONTENT, lv.SIZE_CONTENT)
|
|
517
|
+
b.set_flex_flow(flow)
|
|
518
|
+
b.set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
|
519
|
+
b.set_style_pad_gap(gap, 0)
|
|
520
|
+
b.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
|
521
|
+
return b
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def _button(parent, text, pad, cb):
|
|
525
|
+
b = lv.button(parent)
|
|
526
|
+
b.set_style_pad_hor(pad * 2, 0)
|
|
527
|
+
b.set_style_pad_ver(pad, 0)
|
|
528
|
+
b.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
|
529
|
+
lbl = lv.label(b)
|
|
530
|
+
lbl.set_text(text)
|
|
531
|
+
lbl.center()
|
|
532
|
+
b.add_event_cb(lambda e: cb(), lv.EVENT.CLICKED, None)
|
|
533
|
+
return b, lbl
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def _fps_text(split):
|
|
537
|
+
fps = getattr(display_drv, "fps", None)
|
|
538
|
+
f = fps() if fps is not None else None
|
|
539
|
+
if f is None:
|
|
540
|
+
return "fps n/a"
|
|
541
|
+
return "%.1f fps%s%.1f ms, %d%% busy" % (f["fps"], "\n" if split else ", ", f["present_ms"], round(f["busy"] * 100))
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def main(scope):
|
|
545
|
+
root = scope.root
|
|
546
|
+
W, H = scope.size
|
|
547
|
+
scr = root.get_screen()
|
|
548
|
+
short = min(scr.get_width(), scr.get_height())
|
|
549
|
+
font = _font_for(short)
|
|
550
|
+
big = _font_for(short * 2)
|
|
551
|
+
pad = max(4, short // 40)
|
|
552
|
+
landscape = W * 2 > H * 3 # side by side only when more than 1.5 times wider than tall
|
|
553
|
+
# A round panel gets its own layout when the app has the whole screen.
|
|
554
|
+
round_ = _is_round() and getattr(scope, "rect", (0, 0, W, H)) == (0, 0, scr.get_width(), scr.get_height())
|
|
555
|
+
across = not landscape and W * 10 >= H * 9 # the live card's own long side
|
|
556
|
+
timers = []
|
|
557
|
+
# The meter goes on first, so the frame rate's two lines are there to lay out.
|
|
558
|
+
measuring = getattr(display_drv, "fps", None) is not None and display_drv.fps() is not None
|
|
559
|
+
if not measuring and hasattr(display_drv, "measure_fps"):
|
|
560
|
+
display_drv.measure_fps(True)
|
|
561
|
+
|
|
562
|
+
def tapped():
|
|
563
|
+
_st["taps"] += 1
|
|
564
|
+
tap_lbl.set_text("Tap %d" % _st["taps"])
|
|
565
|
+
|
|
566
|
+
_st["taps"] = 0
|
|
567
|
+
_st["touch"] = None
|
|
568
|
+
|
|
569
|
+
if round_:
|
|
570
|
+
more = (lambda: show_more(True)) if short >= SMALL else None
|
|
571
|
+
page, arc, seconds_lbl, fps_lbl, tap_lbl, touch_lbl, more_btn, info, values = _round_page(
|
|
572
|
+
root, W, font, big, pad, tapped, more
|
|
573
|
+
)
|
|
574
|
+
else:
|
|
575
|
+
page = ui.plain(lv.obj(root))
|
|
576
|
+
page.set_size(W, H)
|
|
577
|
+
page.set_style_text_font(font, 0)
|
|
578
|
+
page.set_style_pad_all(pad, 0)
|
|
579
|
+
page.set_style_pad_gap(pad, 0)
|
|
580
|
+
page.set_flex_flow(lv.FLEX_FLOW.ROW if landscape else lv.FLEX_FLOW.COLUMN)
|
|
581
|
+
page.add_flag(lv.obj.FLAG.CLICKABLE)
|
|
582
|
+
_dark(page)
|
|
583
|
+
|
|
584
|
+
# The live card: every moving part, so the dirty areas stay together.
|
|
585
|
+
live = _card(page, lv.FLEX_FLOW.ROW if across else lv.FLEX_FLOW.COLUMN, pad)
|
|
586
|
+
live.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
|
587
|
+
if landscape:
|
|
588
|
+
live.set_size(W * 2 // 5, lv.pct(100))
|
|
589
|
+
else:
|
|
590
|
+
live.set_size(lv.pct(100), lv.SIZE_CONTENT)
|
|
591
|
+
|
|
592
|
+
arc = lv.arc(live)
|
|
593
|
+
arc.set_bg_angles(0, 360)
|
|
594
|
+
arc.set_rotation(270)
|
|
595
|
+
arc.set_angles(0, 0)
|
|
596
|
+
arc.remove_style(None, lv.PART.KNOB)
|
|
597
|
+
arc.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
598
|
+
seconds_lbl = ui.label(arc, "0", big)
|
|
599
|
+
seconds_lbl.center()
|
|
600
|
+
|
|
601
|
+
side = _box(live, lv.FLEX_FLOW.COLUMN, pad // 2) if across else live
|
|
602
|
+
fps_lbl = ui.label(side, _fps_text(True), None, ui.MUTED)
|
|
603
|
+
fps_lbl.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
604
|
+
# The interpreter sits with the moving parts, which no screen drops, so
|
|
605
|
+
# twin boards on different Pythons tell apart at a glance. It never changes.
|
|
606
|
+
ui.label(side, _identity()["python"])
|
|
607
|
+
|
|
608
|
+
# Beside the arc, the buttons share a line to keep the card low.
|
|
609
|
+
buttons = _box(side, lv.FLEX_FLOW.ROW, pad) if across else side
|
|
610
|
+
_, tap_lbl = _button(buttons, "Tap 0", pad, tapped)
|
|
611
|
+
touch_lbl = None if across else ui.label(side, "touch -", None, ui.MUTED)
|
|
612
|
+
more_btn = None
|
|
613
|
+
if short >= SMALL:
|
|
614
|
+
more_btn, _ = _button(buttons, "More", pad, lambda: show_more(True))
|
|
615
|
+
more_btn.set_style_bg_color(ui.KEY, 0)
|
|
616
|
+
if touch_lbl is None:
|
|
617
|
+
touch_lbl = ui.label(side, "touch -", None, ui.MUTED)
|
|
618
|
+
|
|
619
|
+
# The rows, in order of importance, as many as fit.
|
|
620
|
+
info = _card(page, lv.FLEX_FLOW.COLUMN, pad)
|
|
621
|
+
info.set_flex_grow(1)
|
|
622
|
+
if landscape:
|
|
623
|
+
info.set_height(lv.pct(100))
|
|
624
|
+
else:
|
|
625
|
+
info.set_width(lv.pct(100))
|
|
626
|
+
line_h = font.line_height
|
|
627
|
+
values = []
|
|
628
|
+
for key, _fn in ROWS:
|
|
629
|
+
row = ui.plain(lv.obj(info))
|
|
630
|
+
row.set_width(lv.pct(100))
|
|
631
|
+
row.set_flex_flow(lv.FLEX_FLOW.ROW)
|
|
632
|
+
row.set_style_pad_column(pad, 0) # a key never runs into its value
|
|
633
|
+
row.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
|
634
|
+
ui.label(row, key, None, ui.MUTED)
|
|
635
|
+
v = lv.label(row)
|
|
636
|
+
v.set_flex_grow(1)
|
|
637
|
+
v.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
638
|
+
v.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
|
|
639
|
+
values.append(v)
|
|
640
|
+
|
|
641
|
+
def size_arc():
|
|
642
|
+
# The arc takes the room the live card's other parts leave.
|
|
643
|
+
page.update_layout()
|
|
644
|
+
if across:
|
|
645
|
+
d = min(max(min(W, H) // 3, side.get_height()), W - side.get_width() - 6 * pad)
|
|
646
|
+
elif not landscape: # a tall screen: the card is as high as it needs
|
|
647
|
+
d = min(W, H) * 2 // 5
|
|
648
|
+
else:
|
|
649
|
+
used = sum(live.get_child(i).get_height() for i in range(1, live.get_child_count()))
|
|
650
|
+
gaps = (live.get_child_count() - 1) * (pad // 2)
|
|
651
|
+
d = min(live.get_content_width(), live.get_content_height() - used - gaps)
|
|
652
|
+
d = max(d, 4 * line_h)
|
|
653
|
+
arc.set_size(d, d)
|
|
654
|
+
arc.set_style_arc_width(max(4, d // 12), lv.PART.MAIN)
|
|
655
|
+
arc.set_style_arc_width(max(4, d // 12), lv.PART.INDICATOR)
|
|
656
|
+
page.update_layout()
|
|
657
|
+
# The rows take the largest font at or below the screen's that fits
|
|
658
|
+
# them all in the room left; only the smallest one drops rows.
|
|
659
|
+
bottom = info.get_content_height()
|
|
660
|
+
# The choice is by height alone: a value too wide for its row ends in
|
|
661
|
+
# dots. The gap between rows gives way, down to 2 px, before the font.
|
|
662
|
+
n = len(ROWS)
|
|
663
|
+
sizes = _fonts(short // 20)
|
|
664
|
+
row_font = sizes[0]
|
|
665
|
+
for f in sizes:
|
|
666
|
+
if n * f.line_height + (n - 1) * 2 <= bottom:
|
|
667
|
+
row_font = f
|
|
668
|
+
gap = max(2, min(pad // 2, (bottom - n * row_font.line_height) // (n - 1)))
|
|
669
|
+
info.set_style_pad_gap(gap, 0)
|
|
670
|
+
info.set_style_text_font(row_font, 0)
|
|
671
|
+
for i in range(info.get_child_count()):
|
|
672
|
+
row = info.get_child(i)
|
|
673
|
+
row.set_height(row_font.line_height)
|
|
674
|
+
row.get_child(1).set_height(row_font.line_height)
|
|
675
|
+
page.update_layout()
|
|
676
|
+
# A row that would still run past the card's foot goes, and every row after it.
|
|
677
|
+
for i in range(info.get_child_count()):
|
|
678
|
+
row = info.get_child(i)
|
|
679
|
+
if row.get_y() + row.get_height() > bottom:
|
|
680
|
+
row.add_flag(lv.obj.FLAG.HIDDEN)
|
|
681
|
+
|
|
682
|
+
size_arc()
|
|
683
|
+
shown = [not info.get_child(i).has_flag(lv.obj.FLAG.HIDDEN) for i in range(len(ROWS))]
|
|
684
|
+
|
|
685
|
+
def read_rows(_t=None):
|
|
686
|
+
s = stats()
|
|
687
|
+
for i, (_key, fn) in enumerate(ROWS):
|
|
688
|
+
if shown[i]:
|
|
689
|
+
text = fn(s)
|
|
690
|
+
if values[i].get_text() != text:
|
|
691
|
+
values[i].set_text(text)
|
|
692
|
+
if more_page is not None and not more_page.has_flag(lv.obj.FLAG.HIDDEN):
|
|
693
|
+
more_text.set_text(_more_lines(scope.launcher, block[0]))
|
|
694
|
+
|
|
695
|
+
def pressed(e):
|
|
696
|
+
ind = lv.indev_active()
|
|
697
|
+
if ind is None:
|
|
698
|
+
return
|
|
699
|
+
p = lv.point_t()
|
|
700
|
+
ind.get_point(p)
|
|
701
|
+
_st["touch"] = (p.x, p.y)
|
|
702
|
+
touch_lbl.set_text("touch %d, %d" % (p.x, p.y))
|
|
703
|
+
|
|
704
|
+
page.add_event_cb(pressed, lv.EVENT.PRESSED, None)
|
|
705
|
+
|
|
706
|
+
# -- More: the switches, the restarts, the largest block and Wi-Fi --
|
|
707
|
+
more_page = more_text = None
|
|
708
|
+
block = [None]
|
|
709
|
+
|
|
710
|
+
def show_more(on):
|
|
711
|
+
if on:
|
|
712
|
+
more_page.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
713
|
+
page.add_flag(lv.obj.FLAG.HIDDEN)
|
|
714
|
+
more_text.set_text(_more_lines(scope.launcher, block[0]))
|
|
715
|
+
else:
|
|
716
|
+
page.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
717
|
+
more_page.add_flag(lv.obj.FLAG.HIDDEN)
|
|
718
|
+
|
|
719
|
+
if more_btn is not None:
|
|
720
|
+
more_page = ui.plain(lv.obj(root))
|
|
721
|
+
more_page.set_size(W, H)
|
|
722
|
+
more_page.set_style_text_font(_font_for(short * 3 // 4), 0) # a step down: it's a page of text
|
|
723
|
+
# On a round screen the page keeps to the square inside the circle.
|
|
724
|
+
more_page.set_style_pad_all(W * 3 // 20 if round_ else pad, 0)
|
|
725
|
+
more_page.set_style_pad_gap(pad, 0)
|
|
726
|
+
more_page.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
|
727
|
+
_dark(more_page)
|
|
728
|
+
more_page.add_flag(lv.obj.FLAG.HIDDEN)
|
|
729
|
+
text_card = _card(more_page, lv.FLEX_FLOW.COLUMN, pad)
|
|
730
|
+
text_card.set_width(lv.pct(100))
|
|
731
|
+
text_card.set_flex_grow(1)
|
|
732
|
+
text_card.add_flag(lv.obj.FLAG.SCROLLABLE)
|
|
733
|
+
more_text = lv.label(text_card)
|
|
734
|
+
more_text.set_width(lv.pct(100))
|
|
735
|
+
bar = _box(more_page, lv.FLEX_FLOW.ROW_WRAP, pad)
|
|
736
|
+
bar.set_width(lv.pct(100))
|
|
737
|
+
|
|
738
|
+
def measure():
|
|
739
|
+
block[0] = scope.launcher.heap()[1]
|
|
740
|
+
more_text.set_text(_more_lines(scope.launcher, block[0]))
|
|
741
|
+
|
|
742
|
+
def wifi():
|
|
743
|
+
# The picker joins networks, asking for a new one's password.
|
|
744
|
+
scope.launcher.shell.open_picker("net")
|
|
745
|
+
|
|
746
|
+
back, _ = _button(bar, lv.SYMBOL.LEFT + " Back", pad, lambda: show_more(False))
|
|
747
|
+
back.set_style_bg_color(ui.KEY, 0)
|
|
748
|
+
_button(bar, "Largest block", pad, measure)
|
|
749
|
+
_button(bar, "Wi-Fi", pad, wifi)
|
|
750
|
+
|
|
751
|
+
# -- the timers --
|
|
752
|
+
# The arc steps at the display's refresh period, so it changes every frame
|
|
753
|
+
# and the frame rate shown is the display's, not this app's pace. Its angle
|
|
754
|
+
# comes from the clock: one turn a second at any period, in step with the
|
|
755
|
+
# seconds counter, which shows if the two timers drift.
|
|
756
|
+
frame_ms = int(getattr(display_drv, "refresh_period_ms", 0) or 33)
|
|
757
|
+
t0 = _ticks_ms()
|
|
758
|
+
|
|
759
|
+
def step_arc(_t):
|
|
760
|
+
arc.set_angles(0, _ticks_diff(_ticks_ms(), t0) % 1000 * 360 // 1000)
|
|
761
|
+
|
|
762
|
+
def second(_t):
|
|
763
|
+
_st["seconds"] += 1
|
|
764
|
+
seconds_lbl.set_text(str(_st["seconds"]))
|
|
765
|
+
fps_lbl.set_text(_fps_text(not round_))
|
|
766
|
+
|
|
767
|
+
def time_gc(_t):
|
|
768
|
+
collect()
|
|
769
|
+
|
|
770
|
+
_st["seconds"] = 0
|
|
771
|
+
collect()
|
|
772
|
+
read_rows()
|
|
773
|
+
timers.append(lv.timer_create(step_arc, frame_ms, None))
|
|
774
|
+
timers.append(lv.timer_create(second, 1000, None))
|
|
775
|
+
timers.append(lv.timer_create(read_rows, ROWS_MS, None))
|
|
776
|
+
timers.append(lv.timer_create(time_gc, GC_MS, None))
|
|
777
|
+
|
|
778
|
+
def close():
|
|
779
|
+
for t in timers:
|
|
780
|
+
t.delete()
|
|
781
|
+
_st["seconds"] = None
|
|
782
|
+
if not measuring and hasattr(display_drv, "measure_fps"):
|
|
783
|
+
display_drv.measure_fps(False)
|
|
784
|
+
|
|
785
|
+
scope.on_close(close)
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
def _more_lines(launcher, block=None):
|
|
789
|
+
lines = [shell.heap_text()]
|
|
790
|
+
if block:
|
|
791
|
+
lines.append("largest free block %s" % _size(block))
|
|
792
|
+
base = launcher.baseline
|
|
793
|
+
if base and base[0]:
|
|
794
|
+
lines.append("at start: free %s; restart below %s free" % (_size(base[0]), _size(launcher.min_free or 0)))
|
|
795
|
+
lines.append("restarts in a row before this boot: %d; BOOT presses: %d" % (launcher.restarts, shell.boot_presses))
|
|
796
|
+
lines.append("")
|
|
797
|
+
lines.append("last switches (app, how, ms, free after the close):")
|
|
798
|
+
for name, how, ms, free in getattr(launcher, "history", ())[-8:]:
|
|
799
|
+
lines.append(
|
|
800
|
+
" %-12s %-7s %5s ms %s" % (name, how, ms if ms is not None else "-", _size(free) if free else "-")
|
|
801
|
+
)
|
|
802
|
+
if launcher.problems:
|
|
803
|
+
lines.append("last close reported: " + "; ".join(launcher.problems[:2]))
|
|
804
|
+
a = shell.audit()
|
|
805
|
+
lines.append("")
|
|
806
|
+
lines.append(
|
|
807
|
+
"audio pump %s, I2S %s, USB host devices %s, SD %s"
|
|
808
|
+
% (a.get("audiopump"), a.get("i2s"), a.get("host_devices"), a.get("sd") or "not mounted")
|
|
809
|
+
)
|
|
810
|
+
return "\n".join(lines)
|