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
Martin Ling
firmware
Commits
24be7ca2
Commit
24be7ca2
authored
5 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parent
45b3a1a1
Branches
master
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
pycardium/modules/py/pov.py
+95
-0
95 additions, 0 deletions
pycardium/modules/py/pov.py
with
95 additions
and
0 deletions
pycardium/modules/py/pov.py
0 → 100644
+
95
−
0
View file @
24be7ca2
#this script reads a BMP file and displays it as POV. For optimal results use a BMP that is 11 pixels wide.
import
leds
,
utime
#default filename. Depending on how you want to run this, change it
FILENAME
=
"
Smiley.bmp
"
#Determines the Frame Rate, currently not used.
DELAY
=
0
#Determine Brightness Level. You might not wanna use the full values from the BMP
BRIGHTNESS
=
1.0
class
BMPError
(
Exception
):
pass
class
POV
:
def
__init__
(
self
,
filename
=
FILENAME
):
self
.
filename
=
filename
f
=
open
(
"
/
"
+
self
.
filename
,
"
rb
"
)
if
f
.
read
(
2
)
!=
b
'
BM
'
:
# check signature
raise
BMPError
(
"
Not BitMap file
"
)
#turn into int.from_bytes
bmpFileSize
=
int
.
from_bytes
(
f
.
read
(
4
),
'
little
'
)
f
.
read
(
4
)
# Read & ignore creator bytes
self
.
bmpImageOffset
=
self
.
read_le
(
f
.
read
(
4
))
# Start of image data
headerSize
=
self
.
read_le
(
f
.
read
(
4
))
self
.
bmpWidth
=
self
.
read_le
(
f
.
read
(
4
))
self
.
bmpHeight
=
self
.
read_le
(
f
.
read
(
4
))
flip
=
False
print
(
"
Size: %d
\n
Image offset: %d
\n
Header size: %d
"
%
(
bmpFileSize
,
self
.
bmpImageOffset
,
headerSize
))
print
(
"
Width: %d
\n
Height: %d
"
%
(
self
.
bmpWidth
,
self
.
bmpHeight
))
if
self
.
read_le
(
f
.
read
(
2
))
!=
1
:
raise
BMPError
(
"
Not singleplane
"
)
bmpDepth
=
self
.
read_le
(
f
.
read
(
2
))
# bits per pixel
print
(
"
Bit depth: %d
"
%
(
bmpDepth
))
if
bmpDepth
!=
24
:
raise
BMPError
(
"
Not 24-bit
"
)
if
self
.
read_le
(
f
.
read
(
2
))
!=
0
:
raise
BMPError
(
"
Compressed file
"
)
print
(
"
Image OK!
"
)
self
.
rowSize
=
(
self
.
bmpWidth
*
3
+
3
)
&
~
3
# 32-bit line boundary
self
.
fileOffset
=
f
.
tell
()
print
(
"
File Offset
"
+
str
(
self
.
fileOffset
))
f
.
close
()
self
.
read_image
()
def
correct_brightness
(
self
,
color
):
return
int
(
pow
((
color
*
BRIGHTNESS
)
/
255
,
2.7
)
*
255
+
0.5
)
def
getWidth
(
self
):
return
self
.
bmpWidth
def
setFileOffset
(
self
,
fileOffset
):
self
.
fileOffset
=
fileOffset
def
getFileOffset
(
self
):
return
self
.
fileOffset
def
read_le
(
self
,
bytes
):
return
int
.
from_bytes
(
bytes
,
'
little
'
)
def
read_image
(
self
):
self
.
imageArray
=
[]
flip
=
True
rowSize
=
(
self
.
bmpWidth
*
3
+
3
)
&
~
3
f
=
open
(
"
/
"
+
self
.
filename
,
"
rb
"
)
for
row
in
range
(
self
.
bmpHeight
):
rowArray
=
[]
if
flip
:
# Bitmap is stored bottom-to-top order (normal BMP)
pos
=
self
.
bmpImageOffset
+
(
self
.
bmpHeight
-
1
-
row
)
*
rowSize
else
:
# Bitmap is stored top-to-bottom
pos
=
self
.
bmpImageOffset
+
row
*
rowSize
f
.
seek
(
pos
)
for
col
in
range
(
self
.
bmpWidth
):
rgb
=
[
f
.
read
(
1
),
f
.
read
(
1
),
f
.
read
(
1
)]
rgb
=
[
int
.
from_bytes
(
x
,
"
little
"
)
for
x
in
rgb
]
#rgb = [self.correct_brightness(x) for x in rgb]
rowArray
+=
[
rgb
]
self
.
imageArray
+=
[
rowArray
]
def
getImageArray
(
self
):
return
self
.
imageArray
def
playMe
(
self
):
for
i
in
self
.
imageArray
:
leds
.
set_all
(
i
)
def
play
(
imagename
):
myPov
=
POV
(
imagename
)
while
True
:
myPov
.
playMe
()
play
(
"
Smiley.bmp
"
)
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