-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconsole_advanced_demo.py
58 lines (43 loc) · 1.58 KB
/
console_advanced_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
console_advanced_demo.py - Advanced demo of the mpconsole module
"""
from board_config import display_drv
from palettes import get_palette
from console import Console
from sys import implementation, platform
from graphics import text16
SSID = "<ssid>"
PASSPHRASE = "<passphrase>"
pal = get_palette()
# Have to use a lambda to map the way Console calls char_writer to the way display_drv.text expects it
char_writer = lambda char, x, y, fg, bg: text16(display_drv, char, x, y, fg) # noqa: E731
console = Console(display_drv, char_writer, cwidth=8, lheight=16)
maj, min, *_ = implementation.version
try:
import wifi
wifi.radio.connect(SSID, PASSPHRASE)
console.label(
Console.TITLE,
f"{implementation.name} {maj}.{min} @ {wifi.radio.ipv4_address}",
pal.BLACK,
)
except ImportError:
console.label(Console.TITLE, f"{implementation.name} {maj}.{min}", pal.BLACK)
try:
import gc
console.label(Console.RIGHT, lambda: f"mf={gc.mem_free():,}", pal.BLUE)
except ImportError:
from psutil import virtual_memory
console.label(Console.RIGHT, lambda: f"mf={virtual_memory().free:,}", pal.BLUE)
try:
import os
os.dupterm(console)
help()
except ImportError:
console.write("REPL not available.\n", pal.YELLOW)
console.label(Console.LEFT, platform, pal.RED)
#### Example commands
# console.cls() # Clear the console screen
# console.write("Hello, World!") # Write text to the console
# console.hide() # Hide the console screen
# console.show() # Show the console screen after hiding it