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
External 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
fpletz
firmware
Commits
c2935c8c
Commit
c2935c8c
authored
5 years ago
by
Daniel Hoffend
Browse files
Options
Downloads
Patches
Plain Diff
fixed syntax
parent
3017591a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/menu.py
+69
-14
69 additions, 14 deletions
preload/menu.py
with
69 additions
and
14 deletions
preload/menu.py
+
69
−
14
View file @
c2935c8c
...
...
@@ -17,12 +17,14 @@ BUTTON_TIMER_POPPED = -1
COLOR1
,
COLOR2
=
(
color
.
CHAOSBLUE_DARK
,
color
.
CHAOSBLUE
)
MAXCHARS
=
11
def
create_folders
():
try
:
os
.
mkdir
(
"
/apps
"
)
except
:
pass
def
read_metadata
(
app_folder
):
try
:
info_file
=
"
/apps/%s/metadata.json
"
%
(
app_folder
)
...
...
@@ -31,7 +33,14 @@ def read_metadata(app_folder):
return
ujson
.
loads
(
information
)
except
BaseException
as
e
:
sys
.
print_exception
(
e
)
return
{
'
author
'
:
''
,
'
name
'
:
app_folder
,
'
description
'
:
''
,
'
category
'
:
''
,
'
revision
'
:
0
}
return
{
"
author
"
:
""
,
"
name
"
:
app_folder
,
"
descriptionr
"
:
""
,
"
category
"
:
""
,
"
revision
"
:
0
,
}
def
list_apps
():
"""
Create a list of available apps.
"""
...
...
@@ -40,26 +49,60 @@ def list_apps():
# add main application
for
mainFile
in
os
.
listdir
(
"
/
"
):
if
mainFile
==
"
main.py
"
:
apps
.
append
([
"
/main.py
"
,
{
'
author
'
:
''
,
'
name
'
:
'
Main Clock
'
,
'
description
'
:
''
,
'
category
'
:
''
,
'
revision
'
:
0
}])
apps
.
append
(
[
"
/main.py
"
,
{
"
author
"
:
"
card10badge Team
"
,
"
name
"
:
"
Main Clock
"
,
"
description
"
:
""
,
"
category
"
:
""
,
"
revision
"
:
0
,
},
]
)
# list all hatchary style apps (not .elf and not .py)
# with or without metadata.json
for
appFolder
in
sorted
(
os
.
listdir
(
"
/apps
"
)):
if
not
(
appFolder
.
endswith
(
"
.py
"
)
or
appFolder
.
endswith
(
"
.elf
"
)):
if
not
(
appFolder
.
endswith
(
"
.py
"
)
or
appFolder
.
endswith
(
"
.elf
"
)):
apps
.
append
([
"
/apps/%s/__init__.py
"
%
appFolder
,
read_metadata
(
appFolder
)])
# list simple python scripts
for
pyFile
in
sorted
(
os
.
listdir
(
"
/apps
"
)):
if
pyFile
.
endswith
(
"
.py
"
):
apps
.
append
([
"
/apps/%s
"
%
pyFile
,
{
'
author
'
:
''
,
'
name
'
:
pyFile
,
'
description
'
:
''
,
'
category
'
:
''
,
'
revision
'
:
0
}])
apps
.
append
(
[
"
/apps/%s
"
%
pyFile
,
{
"
author
"
:
""
,
"
name
"
:
pyFile
,
"
description
"
:
""
,
"
category
"
:
""
,
"
revision
"
:
0
,
},
]
)
# list simple elf binaries
for
elfFile
in
sorted
(
os
.
listdir
(
"
/apps
"
)):
if
elfFile
.
endswith
(
"
.elf
"
):
apps
.
append
([
"
/apps/%s
"
%
elfFile
,
{
'
author
'
:
''
,
'
name
'
:
elfFile
,
'
description
'
:
''
,
'
category
'
:
''
,
'
revision
'
:
0
}])
apps
.
append
(
[
"
/apps/%s
"
%
elfFile
,
{
"
author
"
:
""
,
"
name
"
:
elfFile
,
"
description
"
:
""
,
"
category
"
:
""
,
"
revision
"
:
0
,
},
]
)
return
apps
def
button_events
(
timeout
=
0
):
"""
Iterate over button presses (event-loop).
"""
yield
0
...
...
@@ -90,19 +133,21 @@ def button_events(timeout=0):
utime
.
sleep_ms
(
10
)
def
triangle
(
disp
,
x
,
y
,
left
,
scale
=
6
,
color
=
[
255
,
0
,
0
]):
def
triangle
(
disp
,
x
,
y
,
left
,
scale
=
6
,
color
=
[
255
,
0
,
0
]):
"""
Draw a triangle to show there
'
s more text in this line
"""
yf
=
1
if
left
else
-
1
disp
.
line
(
x
-
scale
*
yf
,
int
(
y
+
scale
/
2
),
x
,
y
,
col
=
color
)
disp
.
line
(
x
,
y
,
x
,
y
+
scale
,
col
=
color
)
disp
.
line
(
x
,
y
+
scale
,
x
-
scale
*
yf
,
y
+
int
(
scale
/
2
),
col
=
color
)
def
draw_menu
(
disp
,
applist
,
pos
,
appcount
,
lineoffset
):
disp
.
clear
()
start
=
0
if
pos
>
0
:
start
=
pos
-
1
start
=
pos
-
1
if
start
+
4
>
appcount
:
start
=
appcount
-
4
if
start
<
0
:
...
...
@@ -113,24 +158,31 @@ def draw_menu(disp, applist, pos, appcount, lineoffset):
break
if
i
>=
start
:
disp
.
rect
(
0
,
(
i
-
start
)
*
20
,
159
,
(
i
-
start
)
*
20
+
20
,
col
=
COLOR1
if
i
==
pos
else
COLOR2
0
,
(
i
-
start
)
*
20
,
159
,
(
i
-
start
)
*
20
+
20
,
col
=
COLOR1
if
i
==
pos
else
COLOR2
,
)
line
=
app
[
1
][
'
name
'
]
line
=
app
[
1
][
"
name
"
]
linelength
=
len
(
line
)
off
=
0
# calc line offset for scrolling
if
i
==
pos
and
linelength
>
(
MAXCHARS
-
1
)
and
lineoffset
>
0
:
off
=
lineoffset
if
lineoffset
+
(
MAXCHARS
-
1
)
<
linelength
else
linelength
-
(
MAXCHARS
-
1
)
off
=
(
lineoffset
if
lineoffset
+
(
MAXCHARS
-
1
)
<
linelength
else
linelength
-
(
MAXCHARS
-
1
)
)
if
lineoffset
>
linelength
:
off
=
0
disp
.
print
(
"
"
+
line
[
off
:
(
off
+
(
MAXCHARS
-
1
))],
"
"
+
line
[
off
:
(
off
+
(
MAXCHARS
-
1
))],
posy
=
(
i
-
start
)
*
20
,
bg
=
COLOR1
if
i
==
pos
else
COLOR2
bg
=
COLOR1
if
i
==
pos
else
COLOR2
,
)
if
i
==
pos
:
disp
.
print
(
"
>
"
,
posy
=
(
i
-
start
)
*
20
,
fg
=
color
.
COMMYELLOW
,
bg
=
COLOR1
)
...
...
@@ -191,7 +243,10 @@ def main():
elif
ev
==
BUTTON_TIMER_POPPED
:
timercountpopped
+=
1
if
timercountpopped
>=
timerstartscroll
and
(
timercountpopped
-
timerstartscroll
)
%
timerscrollspeed
==
0
:
if
(
timercountpopped
>=
timerstartscroll
and
(
timercountpopped
-
timerstartscroll
)
%
timerscrollspeed
==
0
):
lineoffset
+=
1
elif
ev
==
buttons
.
TOP_RIGHT
:
...
...
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