Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r 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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
f376fe00
Commit
f376fe00
authored
1 year ago
by
q3k
Committed by
q3k
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
py: show battery indicator
parent
5c2303e9
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
python_payload/st3m/ui/elements/overlays.py
+60
-6
60 additions, 6 deletions
python_payload/st3m/ui/elements/overlays.py
with
60 additions
and
6 deletions
python_payload/st3m/ui/elements/overlays.py
+
60
−
6
View file @
f376fe00
...
@@ -11,6 +11,7 @@ from st3m.goose import Dict, Enum, List, ABCBase, abstractmethod, Optional
...
@@ -11,6 +11,7 @@ from st3m.goose import Dict, Enum, List, ABCBase, abstractmethod, Optional
from
st3m.utils
import
tau
from
st3m.utils
import
tau
from
st3m.ui.view
import
ViewManager
from
st3m.ui.view
import
ViewManager
from
st3m.input
import
power
from
st3m.input
import
power
from
st3m.power
import
approximate_battery_percentage
from
ctx
import
Context
from
ctx
import
Context
import
st3m.wifi
import
st3m.wifi
...
@@ -347,6 +348,8 @@ class Icon(Responder):
...
@@ -347,6 +348,8 @@ class Icon(Responder):
that contains it.
that contains it.
"""
"""
WIDTH
:
int
=
25
@abstractmethod
@abstractmethod
def
visible
(
self
)
->
bool
:
def
visible
(
self
)
->
bool
:
...
...
...
@@ -359,6 +362,8 @@ class USBIcon(Icon):
...
@@ -359,6 +362,8 @@ class USBIcon(Icon):
Might or might not be related to a certain serial bus.
Might or might not be related to a certain serial bus.
"""
"""
WIDTH
:
int
=
20
def
visible
(
self
)
->
bool
:
def
visible
(
self
)
->
bool
:
return
sys_kernel
.
usb_connected
()
return
sys_kernel
.
usb_connected
()
...
@@ -378,6 +383,8 @@ class USBIcon(Icon):
...
@@ -378,6 +383,8 @@ class USBIcon(Icon):
class
WifiIcon
(
Icon
):
class
WifiIcon
(
Icon
):
WIDTH
:
int
=
15
def
__init__
(
self
)
->
None
:
def
__init__
(
self
)
->
None
:
super
().
__init__
()
super
().
__init__
()
self
.
_rssi
:
float
=
-
120
self
.
_rssi
:
float
=
-
120
...
@@ -404,6 +411,50 @@ class WifiIcon(Icon):
...
@@ -404,6 +411,50 @@ class WifiIcon(Icon):
self
.
_rssi
=
st3m
.
wifi
.
rssi
()
self
.
_rssi
=
st3m
.
wifi
.
rssi
()
class
BatteryIcon
(
Icon
):
def
__init__
(
self
)
->
None
:
super
().
__init__
()
self
.
_percent
=
100.0
self
.
_charging
=
False
def
visible
(
self
)
->
bool
:
return
True
def
draw
(
self
,
ctx
:
Context
)
->
None
:
if
self
.
_percent
>
30
:
ctx
.
rgb
(
0.17
,
0.55
,
0.04
)
else
:
ctx
.
rgb
(
0.52
,
0.04
,
0.17
)
height
=
160
*
self
.
_percent
/
100
ctx
.
rectangle
(
-
80
,
-
50
,
height
,
100
)
ctx
.
fill
()
ctx
.
gray
(
0.8
)
ctx
.
line_width
=
10.0
ctx
.
rectangle
(
80
,
-
50
,
-
160
,
100
)
ctx
.
stroke
()
ctx
.
rectangle
(
100
,
-
30
,
-
20
,
60
)
ctx
.
fill
()
if
self
.
_charging
:
ctx
.
gray
(
1
)
ctx
.
line_width
=
20
ctx
.
move_to
(
10
,
-
65
-
10
)
ctx
.
line_to
(
-
30
,
20
-
10
)
ctx
.
line_to
(
30
,
-
20
-
10
)
ctx
.
line_to
(
-
10
,
65
-
10
)
ctx
.
line_to
(
-
20
,
35
-
10
)
ctx
.
stroke
()
ctx
.
move_to
(
-
10
,
65
-
10
)
ctx
.
line_to
(
40
,
35
-
10
)
ctx
.
stroke
()
def
think
(
self
,
ins
:
InputState
,
delta_ms
:
int
)
->
None
:
self
.
_percent
=
approximate_battery_percentage
(
power
.
battery_voltage
)
self
.
_charging
=
power
.
battery_charging
class
IconTray
(
Overlay
):
class
IconTray
(
Overlay
):
"""
"""
An overlay which renders Icons.
An overlay which renders Icons.
...
@@ -413,6 +464,7 @@ class IconTray(Overlay):
...
@@ -413,6 +464,7 @@ class IconTray(Overlay):
def
__init__
(
self
)
->
None
:
def
__init__
(
self
)
->
None
:
self
.
icons
=
[
self
.
icons
=
[
BatteryIcon
(),
USBIcon
(),
USBIcon
(),
WifiIcon
(),
WifiIcon
(),
]
]
...
@@ -424,14 +476,16 @@ class IconTray(Overlay):
...
@@ -424,14 +476,16 @@ class IconTray(Overlay):
v
.
think
(
ins
,
delta_ms
)
v
.
think
(
ins
,
delta_ms
)
def
draw
(
self
,
ctx
:
Context
)
->
None
:
def
draw
(
self
,
ctx
:
Context
)
->
None
:
nicons
=
len
(
self
.
visible
)
if
len
(
self
.
visible
)
<
1
:
dist
=
25
return
width
=
(
nicons
-
1
)
*
dist
width
=
0
x0
=
width
/
-
2
for
icon
in
self
.
visible
:
width
+=
icon
.
WIDTH
x0
=
width
/
-
2
+
self
.
visible
[
0
].
WIDTH
/
2
for
i
,
v
in
enumerate
(
self
.
visible
):
for
i
,
v
in
enumerate
(
self
.
visible
):
x
=
x0
+
i
*
dist
ctx
.
save
()
ctx
.
save
()
ctx
.
translate
(
x
,
-
100
)
ctx
.
translate
(
x
0
,
-
100
)
ctx
.
scale
(
0.1
,
0.1
)
ctx
.
scale
(
0.1
,
0.1
)
v
.
draw
(
ctx
)
v
.
draw
(
ctx
)
ctx
.
restore
()
ctx
.
restore
()
x0
=
x0
+
v
.
WIDTH
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