Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
firmware
Commits
7d98182e
"git@git.flow3r.garden:card10/openocd.git" did not exist on "447a615dc33f324d44c73b282174be44e876cf41"
Commit
7d98182e
authored
5 years ago
by
koalo
Browse files
Options
Downloads
Patches
Plain Diff
Reset confirmation
parent
ccbb0da1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/menu.py
+72
-28
72 additions, 28 deletions
preload/menu.py
with
72 additions
and
28 deletions
preload/menu.py
+
72
−
28
View file @
7d98182e
...
@@ -12,6 +12,9 @@ import os
...
@@ -12,6 +12,9 @@ import os
FACTORY_RESET_CMD
=
"
! RESET !
"
FACTORY_RESET_CMD
=
"
! RESET !
"
STATE_MAIN_MENU
=
"
MAIN
"
STATE_RESET
=
"
RESET
"
STATE_RESET_ARMED
=
"
RESET_ARMED
"
def
list_apps
():
def
list_apps
():
...
@@ -24,11 +27,29 @@ def list_apps():
...
@@ -24,11 +27,29 @@ def list_apps():
if
"
menu.py
"
in
apps
:
if
"
menu.py
"
in
apps
:
apps
.
remove
(
"
menu.py
"
)
apps
.
remove
(
"
menu.py
"
)
apps
.
append
(
FACTORY_RESET_CMD
)
return
apps
return
apps
def
list_extra_entries
():
return
[
FACTORY_RESET_CMD
]
def
activate_menu_entry
(
entryy
):
if
entryy
==
FACTORY_RESET_CMD
:
return
STATE_RESET
disp
.
clear
().
update
()
disp
.
close
()
try
:
os
.
exec
(
entryy
)
except
OSError
as
e
:
print
(
"
Loading failed:
"
,
e
)
os
.
exit
(
1
)
return
STATE_MAIN_MENU
def
button_events
():
def
button_events
():
"""
Iterate over button presses (event-loop).
"""
"""
Iterate over button presses (event-loop).
"""
yield
0
yield
0
...
@@ -55,13 +76,13 @@ def button_events():
...
@@ -55,13 +76,13 @@ def button_events():
COLOR1
,
COLOR2
=
(
color
.
CHAOSBLUE_DARK
,
color
.
CHAOSBLUE
)
COLOR1
,
COLOR2
=
(
color
.
CHAOSBLUE_DARK
,
color
.
CHAOSBLUE
)
def
draw_menu
(
disp
,
app
list
,
idx
,
offset
):
def
draw_menu
(
disp
,
menu
list
,
idx
,
offset
):
disp
.
clear
()
disp
.
clear
()
# Wrap around the app-list and draw entries from idx - 3 to idx + 4
# Wrap around the app-list and draw entries from idx - 3 to idx + 4
for
y
,
i
in
enumerate
(
range
(
len
(
app
list
)
+
idx
-
3
,
len
(
app
list
)
+
idx
+
4
)):
for
y
,
i
in
enumerate
(
range
(
len
(
menu
list
)
+
idx
-
3
,
len
(
menu
list
)
+
idx
+
4
)):
disp
.
print
(
disp
.
print
(
"
"
+
app
list
[
i
%
len
(
app
list
)]
+
"
"
,
"
"
+
menu
list
[
i
%
len
(
menu
list
)]
+
"
"
,
posy
=
offset
+
y
*
20
-
40
,
posy
=
offset
+
y
*
20
-
40
,
bg
=
COLOR1
if
i
%
2
==
0
else
COLOR2
,
bg
=
COLOR1
if
i
%
2
==
0
else
COLOR2
,
)
)
...
@@ -70,38 +91,61 @@ def draw_menu(disp, applist, idx, offset):
...
@@ -70,38 +91,61 @@ def draw_menu(disp, applist, idx, offset):
disp
.
update
()
disp
.
update
()
def
draw_reset
(
disp
,
armed
):
disp
.
clear
()
button
=
"
LEFT
"
if
not
armed
else
"
RIGHT
"
disp
.
print
(
"
Press %s
"
%
button
,
posy
=
0
)
disp
.
print
(
"
to perform
"
,
posy
=
20
)
disp
.
print
(
"
factory
"
,
posy
=
40
)
disp
.
print
(
"
reset
"
,
posy
=
60
)
disp
.
update
()
def
main
():
def
main
():
disp
=
display
.
open
()
disp
=
display
.
open
()
applist
=
list_apps
()
menulist
=
list_apps
()
numapps
=
len
(
applist
)
menulist
+=
list_extra_entries
()
numentries
=
len
(
menulist
)
current
=
0
current
=
0
state
=
STATE_MAIN_MENU
for
ev
in
button_events
():
for
ev
in
button_events
():
# Button handling
if
state
==
STATE_MAIN_MENU
:
if
ev
==
buttons
.
BOTTOM_RIGHT
:
if
ev
==
buttons
.
BOTTOM_RIGHT
:
# Scroll down
# Scroll down
draw_menu
(
disp
,
app
list
,
current
,
-
8
)
draw_menu
(
disp
,
menu
list
,
current
,
-
8
)
current
=
(
current
+
1
)
%
num
app
s
current
=
(
current
+
1
)
%
num
entrie
s
elif
ev
==
buttons
.
BOTTOM_LEFT
:
elif
ev
==
buttons
.
BOTTOM_LEFT
:
# Scroll up
# Scroll up
draw_menu
(
disp
,
app
list
,
current
,
8
)
draw_menu
(
disp
,
menu
list
,
current
,
8
)
current
=
(
current
+
num
app
s
-
1
)
%
num
app
s
current
=
(
current
+
num
entrie
s
-
1
)
%
num
entrie
s
elif
ev
==
buttons
.
TOP_RIGHT
:
elif
ev
==
buttons
.
TOP_RIGHT
:
# Select & start
# Select & start
disp
.
clear
().
update
()
state
=
activate_menu_entry
(
menulist
[
current
])
disp
.
close
()
elif
state
==
STATE_RESET
:
if
ev
==
buttons
.
BOTTOM_LEFT
:
if
applist
[
current
]
==
FACTORY_RESET_CMD
:
state
=
STATE_RESET_ARMED
else
:
state
=
STATE_MAIN_MENU
elif
state
==
STATE_RESET_ARMED
:
if
ev
==
buttons
.
BOTTOM_RIGHT
:
files
=
os
.
listdir
(
"
.
"
)
files
=
os
.
listdir
(
"
.
"
)
for
f
in
files
:
for
f
in
files
:
os
.
unlink
(
f
)
os
.
unlink
(
f
)
os
.
exit
(
0
)
os
.
exit
(
0
)
else
:
else
:
try
:
state
=
STATE_MAIN_MENU
os
.
exec
(
applist
[
current
])
except
OSError
as
e
:
# Output handling
print
(
"
Loading failed:
"
,
e
)
if
state
==
STATE_MAIN_MENU
:
os
.
exit
(
1
)
draw_menu
(
disp
,
menulist
,
current
,
0
)
elif
state
==
STATE_RESET
:
draw_menu
(
disp
,
applist
,
current
,
0
)
draw_reset
(
disp
,
False
)
elif
state
==
STATE_RESET_ARMED
:
draw_reset
(
disp
,
True
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment