Skip to content

Commit 83eebc1

Browse files
committed
Use framebuffer info rather than hard-coding ev3-specific values
1 parent 27e1f80 commit 83eebc1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ev3dev.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,9 @@ class FbMem(object):
20232023
FBIOGET_VSCREENINFO = 0x4600
20242024
FBIOGET_FSCREENINFO = 0x4602
20252025

2026+
FB_VISUAL_MONO01 = 0
2027+
FB_VISUAL_MONO10 = 1
2028+
20262029
class FixScreenInfo(ctypes.Structure):
20272030

20282031
"""The fb_fix_screeninfo from fb.h."""
@@ -2150,12 +2153,10 @@ class Screen(FbMem):
21502153
def __init__(self):
21512154
FbMem.__init__(self)
21522155

2153-
def alignup(n, m):
2154-
r = n % m
2155-
if r == 0: return n
2156-
return n - r + m
2157-
2158-
self._img = Image.new("1", (alignup(self.xres, 32), self.yres), "white")
2156+
self._img = Image.new(
2157+
"%s" % self.var_info.bits_per_pixel,
2158+
(self.fix_info.line_length * 8 / self.var_info.bits_per_pixel, self.yres),
2159+
"white")
21592160

21602161
self._draw = ImageDraw.Draw(self._img)
21612162

@@ -2200,5 +2201,6 @@ def update(self):
22002201
Applies pending changes to the screen.
22012202
Nothing will be drawn on the screen until this function is called.
22022203
"""
2203-
self.mmap[:] = self._img.tobytes("raw", "1;IR")
2204+
self.mmap[:] = self._img.tobytes("raw", "%s;I%s" % (self.var_info.bits_per_pixel,
2205+
self.fix_info.visual in [FbMem.FB_VISUAL_MONO01, FbMem.FB_VISUAL_MONO10] and "R" or ""))
22042206

0 commit comments

Comments
 (0)