Skip to content

Commit e821b47

Browse files
authored
HDMI display support for raspberry pi based platforms (#610)
1 parent b16b826 commit e821b47

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
python-ev3dev2 (2.0.0~beta4) UNRELEASED; urgency=medium
22

33
[Daniel Walton]
4+
* Display support via raspberry pi HDMI
45
* Update tests/README to include sphinx-build instructions
56
* LED animation support, brickpi3 LED corrected from BLUE to AMBER
67
* Sound: fallback to regular case of 'note' if uppercase is not found

ev3dev2/display.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
except ImportError:
4848
log.warning(library_load_warning_message("fcntl", "Display"))
4949

50+
5051
class FbMem(object):
5152

5253
"""The framebuffer memory object.
@@ -114,6 +115,10 @@ class FbBitField(ctypes.Structure):
114115
('msb_right', ctypes.c_uint32),
115116
]
116117

118+
def __str__(self):
119+
return "%s (offset %s, length %s, msg_right %s)" %\
120+
(self.__class__.__name__, self.offset, self.length, self.msb_right)
121+
117122
"""The fb_var_screeninfo struct from fb.h."""
118123

119124
_fields_ = [
@@ -133,6 +138,11 @@ class FbBitField(ctypes.Structure):
133138
('transp', FbBitField),
134139
]
135140

141+
def __str__(self):
142+
return ("%sx%s at (%s,%s), bpp %s, grayscale %s, red %s, green %s, blue %s, transp %s" %
143+
(self.xres, self.yres, self.xoffset, self.yoffset, self.bits_per_pixel, self.grayscale,
144+
self.red, self.green, self.blue, self.transp))
145+
136146
def __init__(self, fbdev=None):
137147
"""Create the FbMem framebuffer memory object."""
138148
fid = FbMem._open_fbdev(fbdev)
@@ -143,11 +153,6 @@ def __init__(self, fbdev=None):
143153
self.var_info = FbMem._get_var_info(fid)
144154
self.mmap = fbmmap
145155

146-
def __del__(self):
147-
"""Close the FbMem framebuffer memory object."""
148-
self.mmap.close()
149-
FbMem._close_fbdev(self.fid)
150-
151156
@staticmethod
152157
def _open_fbdev(fbdev=None):
153158
"""Return the framebuffer file descriptor.
@@ -160,11 +165,6 @@ def _open_fbdev(fbdev=None):
160165
fbfid = os.open(dev, os.O_RDWR)
161166
return fbfid
162167

163-
@staticmethod
164-
def _close_fbdev(fbfid):
165-
"""Close the framebuffer file descriptor."""
166-
os.close(fbfid)
167-
168168
@staticmethod
169169
def _get_fix_info(fbfid):
170170
"""Return the fix screen info from the framebuffer file descriptor."""
@@ -209,12 +209,16 @@ def __init__(self, desc='Display'):
209209

210210
if self.var_info.bits_per_pixel == 1:
211211
im_type = "1"
212-
elif self.var_info.bits_per_pixel == 16:
213-
im_type = "RGB"
212+
214213
elif self.platform == "ev3" and self.var_info.bits_per_pixel == 32:
215214
im_type = "L"
215+
216+
elif self.var_info.bits_per_pixel == 16 or self.var_info.bits_per_pixel == 32:
217+
im_type = "RGB"
218+
216219
else:
217-
raise Exception("Not supported")
220+
raise Exception("Not supported - platform %s with bits_per_pixel %s" %
221+
(self.platform, self.var_info.bits_per_pixel))
218222

219223
self._img = Image.new(
220224
im_type,
@@ -295,12 +299,16 @@ def update(self):
295299
if self.var_info.bits_per_pixel == 1:
296300
b = self._img.tobytes("raw", "1;R")
297301
self.mmap[:len(b)] = b
302+
298303
elif self.var_info.bits_per_pixel == 16:
299304
self.mmap[:] = self._img_to_rgb565_bytes()
300-
elif self.platform == "ev3" and self.var_info.bits_per_pixel == 32:
305+
306+
elif self.var_info.bits_per_pixel == 32:
301307
self.mmap[:] = self._img.convert("RGB").tobytes("raw", "XRGB")
308+
302309
else:
303-
raise Exception("Not supported")
310+
raise Exception("Not supported - platform %s with bits_per_pixel %s" %
311+
(self.platform, self.var_info.bits_per_pixel))
304312

305313
def image_filename(self, filename, clear_screen=True, x1=0, y1=0, x2=None, y2=None):
306314

0 commit comments

Comments
 (0)