-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (79 loc) · 2.17 KB
/
main.py
File metadata and controls
83 lines (79 loc) · 2.17 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# >>>> config memory <<<<
import gc
_threshold = (gc.mem_free() * 60) // 100 # 60% gc auto collect
gc.threshold(_threshold)
print("gc threshold has been set to", _threshold)
del _threshold
# utils in repl
def _clean_up():
from play32sys import path
for file in [
"/.mpypack_sha256.json",
"/framework_debug",
"/boot.py",
"/main.py",
"/lib",
]:
if path.exist(file):
path.rmtree(file)
# >>>> recovery mode <<<<
def check_rec():
import hal_keypad
hal_keypad.init()
hal_keypad.clear_key_status([hal_keypad.KEY_A, hal_keypad.KEY_B])
__count = 0
for event in hal_keypad.get_key_event():
event_type, key = hal_keypad.parse_key_event(event)
if event_type == hal_keypad.EVENT_KEY_PRESS:
if key in [hal_keypad.KEY_A, hal_keypad.KEY_B]:
__count += 1
if __count >= 2:
# enter recovery mode
import updater
updater._on_enter_recovery_mode_()
# >>>> main <<<<
del __count
# >>>> main <<<<
check_rec()
while True:
from play32hw.hw_config import ResetException
import gc
gc.collect()
print("Free:", gc.mem_free())
try:
import hal_keypad
hal_keypad.init()
from play32sys import app
app._on_boot_()
print("==== End Main ====")
except ResetException:
# deinit
import hal_keypad
hal_keypad.clear_key_status([
hal_keypad.KEY_A,
hal_keypad.KEY_B,
hal_keypad.KEY_UP,
hal_keypad.KEY_DOWN,
hal_keypad.KEY_LEFT,
hal_keypad.KEY_RIGHT,
])
from play32hw import ports
ports.before_reset()
# clear as much references as possible
import usys
keys = list(usys.modules.keys())
for name in keys:
if name == "boot_params":
print("Reset: Skip clear 'boot_params' module.")
continue
del usys.modules[name]
globals().clear()
locals().clear()
import gc
gc.collect()
continue
except Exception as e:
import usys
usys.print_exception(e)
break
# test below