Skip to content

Commit 70b7b44

Browse files
authored
Update display for 4.14 kernel (#462)
* Update display for 4.14 kernel Fixes #455
1 parent c968ab1 commit 70b7b44

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

ev3dev2/display.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
import os
3232
import mmap
3333
import ctypes
34-
import ev3dev.fonts as fonts
3534
from PIL import Image, ImageDraw
35+
from . import fonts
36+
from . import get_current_platform
3637
from struct import pack
3738
import fcntl
3839

@@ -195,8 +196,19 @@ class Display(FbMem):
195196
def __init__(self, desc='Display'):
196197
FbMem.__init__(self)
197198

199+
self.platform = get_current_platform()
200+
201+
if self.var_info.bits_per_pixel == 1:
202+
im_type = "1"
203+
elif self.var_info.bits_per_pixel == 16:
204+
im_type = "RGB"
205+
elif self.platform == "ev3" and self.var_info.bits_per_pixel == 32:
206+
im_type = "L"
207+
else:
208+
raise Exception("Not supported")
209+
198210
self._img = Image.new(
199-
self.var_info.bits_per_pixel == 1 and "1" or "RGB",
211+
im_type,
200212
(self.fix_info.line_length * 8 // self.var_info.bits_per_pixel, self.yres),
201213
"white")
202214

@@ -266,6 +278,16 @@ def _img_to_rgb565_bytes(self):
266278
pixels = [self._color565(r, g, b) for (r, g, b) in self._img.getdata()]
267279
return pack('H' * len(pixels), *pixels)
268280

281+
def _color_xrgb(self, v):
282+
"""Convert red, green, blue components to a 32-bit XRGB value. Components
283+
should be values 0 to 255.
284+
"""
285+
return ((v << 16) | (v << 8) | v)
286+
287+
def _img_to_xrgb_bytes(self):
288+
pixels = [self._color_xrgb(v) for v in self._img.getdata()]
289+
return pack('I' * len(pixels), *pixels)
290+
269291
def update(self):
270292
"""
271293
Applies pending changes to the screen.
@@ -276,6 +298,8 @@ def update(self):
276298
self.mmap[:len(b)] = b
277299
elif self.var_info.bits_per_pixel == 16:
278300
self.mmap[:] = self._img_to_rgb565_bytes()
301+
elif self.platform == "ev3" and self.var_info.bits_per_pixel == 32:
302+
self.mmap[:] = self._img_to_xrgb_bytes()
279303
else:
280304
raise Exception("Not supported")
281305

0 commit comments

Comments
 (0)