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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toerb
flow3r firmware
Commits
2ead48d3
Commit
2ead48d3
authored
1 year ago
by
q3k
Browse files
Options
Downloads
Patches
Plain Diff
sim: support for new gfx and input apis
parent
bd52d71d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sim/fakes/ctx.py
+11
-8
11 additions, 8 deletions
sim/fakes/ctx.py
sim/fakes/hardware.py
+48
-14
48 additions, 14 deletions
sim/fakes/hardware.py
with
59 additions
and
22 deletions
sim/fakes/ctx.py
+
11
−
8
View file @
2ead48d3
...
...
@@ -57,6 +57,9 @@ class Wasm:
BRGA8
=
5
return
fb
,
self
.
_i
.
exports
.
ctx_new_for_framebuffer
(
fb
,
width
,
height
,
width
*
4
,
BRGA8
)
def
ctx_new_drawlist
(
self
,
width
,
height
):
return
self
.
_i
.
exports
.
ctx_new_drawlist
(
width
,
height
)
def
ctx_apply_transform
(
self
,
ctx
,
*
args
):
args
=
[
float
(
a
)
for
a
in
args
]
return
self
.
_i
.
exports
.
ctx_apply_transform
(
ctx
,
*
args
)
...
...
@@ -72,6 +75,12 @@ class Wasm:
self
.
free
(
p
)
return
res
def
ctx_destroy
(
self
,
ctx
):
return
self
.
_i
.
exports
.
ctx_destroy
(
ctx
)
def
ctx_render_ctx
(
self
,
ctx
,
dctx
):
return
self
.
_i
.
exports
.
ctx_render_ctx
(
ctx
,
dctx
)
_wasm
=
Wasm
()
class
Ctx
:
...
...
@@ -87,19 +96,13 @@ class Ctx:
END
=
'
end
'
MIDDLE
=
'
middle
'
def
__init__
(
self
):
self
.
_fb
,
self
.
_ctx
=
_wasm
.
ctx_new_for_framebuffer
(
240
,
240
)
# Place (0, 0) in the center of the screen, mathing what the real badge
# software does.
_wasm
.
ctx_apply_transform
(
self
.
_ctx
,
1
,
0
,
120
,
0
,
1
,
120
,
0
,
0
,
1
)
def
__init__
(
self
,
_ctx
):
self
.
_ctx
=
_ctx
self
.
text_align
=
'
start
'
self
.
text_baseline
=
'
alphabetic
'
self
.
font_size
=
10.0
def
_get_fb
(
self
):
return
_wasm
.
_i
.
exports
.
memory
.
uint8_view
(
self
.
_fb
)
def
_emit
(
self
,
text
):
_wasm
.
ctx_parse
(
self
.
_ctx
,
text
)
...
...
This diff is collapsed.
Click to expand it.
sim/fakes/hardware.py
+
48
−
14
View file @
2ead48d3
...
...
@@ -194,11 +194,10 @@ class Simulation:
b2
=
b
/
(
20
-
i
)
pygame
.
draw
.
circle
(
surface
,
(
r2
,
g2
,
b2
),
(
x
,
y
),
radius
)
def
_render_oled
(
self
,
surface
):
def
_render_oled
(
self
,
surface
,
fb
):
surface
.
fill
((
0
,
0
,
0
,
0
))
buf
=
surface
.
get_buffer
()
fb
=
get_ctx
().
_get_fb
()
fb
=
fb
[:
240
*
240
*
4
]
for
y
in
range
(
240
):
# Use precalculated row offset to turn OLED disc into square
...
...
@@ -263,14 +262,14 @@ class Simulation:
elif
time
.
time
()
-
self
.
last_gui_render
>
d
:
self
.
render_gui_now
()
def
render_display
(
self
):
def
render_display
(
self
,
fb
):
"""
Render the OLED surface from Ctx state.
Afterwards, render_gui_{lazy,now} should still be called to actually
present the new OLED surface state to the user.
"""
self
.
_render_oled
(
self
.
_oled_surface
)
self
.
_render_oled
(
self
.
_oled_surface
,
fb
)
def
set_led_rgb
(
self
,
ix
,
r
,
g
,
b
):
self
.
led_state_buf
[
ix
]
=
(
r
,
g
,
b
)
...
...
@@ -297,21 +296,52 @@ def captouch_calibration_active():
return
False
_global_ctx
=
None
def
get_ctx
():
global
_global_ctx
import
ctx
if
_global_ctx
is
None
:
_global_ctx
=
ctx
.
Ctx
()
return
_global_ctx
class
FramebufferManager
:
def
__init__
(
self
):
self
.
_free
=
[]
for
_
in
range
(
2
):
fb
,
c
=
ctx
.
_wasm
.
ctx_new_for_framebuffer
(
240
,
240
)
ctx
.
_wasm
.
ctx_apply_transform
(
c
,
1
,
0
,
120
,
0
,
1
,
120
,
0
,
0
,
1
)
self
.
_free
.
append
((
fb
,
c
))
def
get
(
self
):
if
len
(
self
.
_free
)
==
0
:
return
None
,
None
fb
,
ctx
=
self
.
_free
[
0
]
self
.
_free
=
self
.
_free
[
1
:]
return
fb
,
ctx
def
put
(
self
,
fb
,
ctx
):
self
.
_free
.
append
((
fb
,
ctx
))
fbm
=
FramebufferManager
()
def
get_ctx
():
dctx
=
ctx
.
_wasm
.
ctx_new_drawlist
(
240
,
240
)
return
ctx
.
Ctx
(
dctx
)
def
display_update
():
def
display_update
(
subctx
):
_sim
.
process_events
()
_sim
.
render_display
()
fbp
,
c
=
fbm
.
get
()
if
fbp
is
None
:
return
ctx
.
_wasm
.
ctx_render_ctx
(
subctx
.
_ctx
,
c
)
ctx
.
_wasm
.
ctx_destroy
(
subctx
.
_ctx
)
fb
=
ctx
.
_wasm
.
_i
.
exports
.
memory
.
uint8_view
(
fbp
)
_sim
.
render_display
(
fb
)
_sim
.
render_gui_now
()
fbm
.
put
(
fbp
,
c
)
def
display_pipe_full
():
return
False
def
set_led_rgb
(
ix
,
r
,
g
,
b
):
ix
=
((
39
-
ix
)
+
1
+
32
)
%
40
;
...
...
@@ -404,3 +434,7 @@ def captouch_get_petal_phi(a):
def
captouch_get_petal_pad
(
i
,
x
):
return
0
def
freertos_sleep
(
ms
):
import
_time
_time
.
sleep
(
ms
/
1000.0
)
\ No newline at end of file
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