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
dos
flow3r firmware
Commits
392c186c
Commit
392c186c
authored
1 year ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
sim: Implement full-screen mode
parent
85f04538
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sim/fakes/_sim.py
+57
-24
57 additions, 24 deletions
sim/fakes/_sim.py
sim/run.py
+4
-0
4 additions, 0 deletions
sim/run.py
with
61 additions
and
24 deletions
sim/fakes/_sim.py
+
57
−
24
View file @
392c186c
...
@@ -7,17 +7,23 @@ import sys
...
@@ -7,17 +7,23 @@ import sys
import
pygame
import
pygame
SCREENSHOT
=
False
SCREENSHOT_DELAY
=
5
FULL_SCREEN
=
os
.
environ
.
get
(
"
SIM_FULL_SCREEN
"
,
"
0
"
)
==
"
1
"
pygame
.
init
()
pygame
.
init
()
screen_w
=
814
if
FULL_SCREEN
:
screen_h
=
854
screen
=
pygame
.
display
.
set_mode
((
0
,
0
),
pygame
.
FULLSCREEN
)
screen
=
pygame
.
display
.
set_mode
(
size
=
(
screen_w
,
screen_h
))
else
:
screen
=
pygame
.
display
.
set_mode
(
size
=
(
814
,
854
))
screen_w
=
screen
.
get_width
()
screen_h
=
screen
.
get_height
()
simpath
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)))
simpath
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)))
bgpath
=
os
.
path
.
join
(
simpath
,
"
background.png
"
)
bgpath
=
os
.
path
.
join
(
simpath
,
"
background.png
"
)
background
=
pygame
.
image
.
load
(
bgpath
)
background
=
pygame
.
image
.
load
(
bgpath
)
OLED_SIZE
=
screen_h
//
2
if
FULL_SCREEN
else
240
SCREENSHOT
=
False
SCREENSHOT_DELAY
=
5
class
Input
:
class
Input
:
...
@@ -297,7 +303,9 @@ class Simulation:
...
@@ -297,7 +303,9 @@ class Simulation:
)
)
self
.
_petal_surface_dirty
=
True
self
.
_petal_surface_dirty
=
True
self
.
_full_surface
=
pygame
.
Surface
((
screen_w
,
screen_h
),
flags
=
pygame
.
SRCALPHA
)
self
.
_full_surface
=
pygame
.
Surface
((
screen_w
,
screen_h
),
flags
=
pygame
.
SRCALPHA
)
self
.
_oled_surface
=
pygame
.
Surface
((
240
,
240
),
flags
=
pygame
.
SRCALPHA
)
self
.
_oled_surface
=
pygame
.
Surface
(
(
OLED_SIZE
,
OLED_SIZE
),
flags
=
pygame
.
SRCALPHA
)
# Calculate OLED per-row offset.
# Calculate OLED per-row offset.
#
#
...
@@ -313,8 +321,12 @@ class Simulation:
...
@@ -313,8 +321,12 @@ class Simulation:
# that is True if the pixel corresponding to this mask's bit is part of
# that is True if the pixel corresponding to this mask's bit is part of
# the OLED disc, and false otherwise.
# the OLED disc, and false otherwise.
mask
=
[
mask
=
[
[
math
.
sqrt
((
x
-
120
)
**
2
+
(
y
-
120
)
**
2
)
<=
120
for
x
in
range
(
240
)]
[
for
y
in
range
(
240
)
math
.
sqrt
((
x
-
OLED_SIZE
//
2
)
**
2
+
(
y
-
OLED_SIZE
//
2
)
**
2
)
<=
OLED_SIZE
//
2
for
x
in
range
(
OLED_SIZE
)
]
for
y
in
range
(
OLED_SIZE
)
]
]
# Now, we iterate the mask row-by-row and find the first True bit in
# Now, we iterate the mask row-by-row and find the first True bit in
# it. The offset within that row is our per-row offset for the
# it. The offset within that row is our per-row offset for the
...
@@ -354,14 +366,14 @@ class Simulation:
...
@@ -354,14 +366,14 @@ class Simulation:
surface
.
fill
((
0
,
0
,
0
,
0
))
surface
.
fill
((
0
,
0
,
0
,
0
))
buf
=
surface
.
get_buffer
()
buf
=
surface
.
get_buffer
()
fb
=
fb
[:
240
*
240
*
4
]
fb
=
fb
[:
OLED_SIZE
*
OLED_SIZE
*
4
]
for
y
in
range
(
240
):
for
y
in
range
(
OLED_SIZE
):
# Use precalculated row offset to turn OLED disc into square
# Use precalculated row offset to turn OLED disc into square
# bounded plane.
# bounded plane.
offset
=
self
.
_oled_offset
[
y
]
offset
=
self
.
_oled_offset
[
y
]
start_offs_bytes
=
y
*
240
*
4
start_offs_bytes
=
y
*
OLED_SIZE
*
4
start_offs_bytes
+=
offset
*
4
start_offs_bytes
+=
offset
*
4
end_offs_bytes
=
(
y
+
1
)
*
240
*
4
end_offs_bytes
=
(
y
+
1
)
*
OLED_SIZE
*
4
end_offs_bytes
-=
offset
*
4
end_offs_bytes
-=
offset
*
4
buf
.
write
(
bytes
(
fb
[
start_offs_bytes
:
end_offs_bytes
]),
start_offs_bytes
)
buf
.
write
(
bytes
(
fb
[
start_offs_bytes
:
end_offs_bytes
]),
start_offs_bytes
)
...
@@ -378,27 +390,37 @@ class Simulation:
...
@@ -378,27 +390,37 @@ class Simulation:
need_overlays
=
False
need_overlays
=
False
if
self
.
_led_surface_dirty
or
self
.
_petal_surface_dirty
:
if
self
.
_led_surface_dirty
or
self
.
_petal_surface_dirty
:
full
.
fill
((
0
,
0
,
0
,
255
))
full
.
fill
((
0
,
0
,
0
,
255
))
if
not
FULL_SCREEN
:
full
.
blit
(
background
,
(
0
,
0
))
full
.
blit
(
background
,
(
0
,
0
))
need_overlays
=
True
need_overlays
=
True
if
self
.
_led_surface_dirty
:
if
self
.
_led_surface_dirty
:
if
not
FULL_SCREEN
:
self
.
_render_leds
(
self
.
_led_surface
)
self
.
_render_leds
(
self
.
_led_surface
)
self
.
_led_surface_dirty
=
False
self
.
_led_surface_dirty
=
False
if
need_overlays
:
if
need_overlays
:
full
.
blit
(
self
.
_led_surface
,
(
0
,
0
),
special_flags
=
pygame
.
BLEND_ADD
)
full
.
blit
(
self
.
_led_surface
,
(
0
,
0
),
special_flags
=
pygame
.
BLEND_ADD
)
if
self
.
_petal_surface_dirty
:
if
self
.
_petal_surface_dirty
:
if
not
FULL_SCREEN
:
self
.
_render_petal_markers
(
self
.
_petal_surface
)
self
.
_render_petal_markers
(
self
.
_petal_surface
)
self
.
_petal_surface_dirty
=
False
self
.
_petal_surface_dirty
=
False
if
need_overlays
:
if
need_overlays
:
if
not
FULL_SCREEN
:
full
.
blit
(
self
.
_petal_surface
,
(
0
,
0
))
full
.
blit
(
self
.
_petal_surface
,
(
0
,
0
))
# Always blit oled. Its' alpha blending is designed in a way that it
# Always blit oled. Its' alpha blending is designed in a way that it
# can be repeatedly applied to a dirty _full_surface without artifacts.
# can be repeatedly applied to a dirty _full_surface without artifacts.
center_x
=
408
center_x
=
screen_w
//
2
center_y
=
426
center_y
=
screen_h
//
2
off_x
=
center_x
-
(
240
//
2
)
if
FULL_SCREEN
:
off_y
=
center_y
-
(
240
//
2
)
off_x
=
center_x
-
(
screen_h
//
2
)
off_y
=
center_y
-
(
screen_h
//
2
)
new
=
pygame
.
transform
.
scale
(
self
.
_oled_surface
,
(
screen_h
,
screen_h
))
full
.
blit
(
new
,
(
off_x
,
off_y
))
else
:
off_x
=
center_x
-
(
OLED_SIZE
//
2
)
off_y
=
center_y
-
(
OLED_SIZE
//
2
)
full
.
blit
(
self
.
_oled_surface
,
(
off_x
,
off_y
))
full
.
blit
(
self
.
_oled_surface
,
(
off_x
,
off_y
))
screen
.
blit
(
full
,
(
0
,
0
))
screen
.
blit
(
full
,
(
0
,
0
))
...
@@ -447,8 +469,19 @@ class FramebufferManager:
...
@@ -447,8 +469,19 @@ class FramebufferManager:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
_free
=
[]
self
.
_free
=
[]
for
_
in
range
(
2
):
for
_
in
range
(
2
):
fb
,
c
=
ctx
.
_wasm
.
ctx_new_for_framebuffer
(
240
,
240
)
fb
,
c
=
ctx
.
_wasm
.
ctx_new_for_framebuffer
(
OLED_SIZE
,
OLED_SIZE
)
ctx
.
_wasm
.
ctx_apply_transform
(
c
,
1
,
0
,
120
,
0
,
1
,
120
,
0
,
0
,
1
)
ctx
.
_wasm
.
ctx_apply_transform
(
c
,
OLED_SIZE
/
240
,
0
,
OLED_SIZE
/
2
,
0
,
OLED_SIZE
/
240
,
OLED_SIZE
/
2
,
0
,
0
,
1
,
)
self
.
_free
.
append
((
fb
,
c
))
self
.
_free
.
append
((
fb
,
c
))
def
get
(
self
):
def
get
(
self
):
...
...
This diff is collapsed.
Click to expand it.
sim/run.py
+
4
−
0
View file @
392c186c
...
@@ -112,9 +112,13 @@ os.stat = _stat
...
@@ -112,9 +112,13 @@ os.stat = _stat
def
sim_main
():
def
sim_main
():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
--screenshot
"
,
action
=
"
store_true
"
,
default
=
False
)
parser
.
add_argument
(
"
--screenshot
"
,
action
=
"
store_true
"
,
default
=
False
)
parser
.
add_argument
(
"
--full-screen
"
,
dest
=
"
full_screen
"
,
action
=
"
store_true
"
,
default
=
False
)
parser
.
add_argument
(
"
override_app
"
,
nargs
=
"
?
"
)
parser
.
add_argument
(
"
override_app
"
,
nargs
=
"
?
"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
os
.
environ
[
"
SIM_FULL_SCREEN
"
]
=
"
1
"
if
args
.
full_screen
else
"
0
"
import
_sim
import
_sim
_sim
.
SCREENSHOT
=
args
.
screenshot
_sim
.
SCREENSHOT
=
args
.
screenshot
...
...
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