Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
python-ev3dev2 (2.0.0~beta4) UNRELEASED; urgency=medium

[Daniel Walton]
* Display support via raspberry pi HDMI
* Update tests/README to include sphinx-build instructions
* LED animation support, brickpi3 LED corrected from BLUE to AMBER
* Sound: fallback to regular case of 'note' if uppercase is not found
Expand Down
38 changes: 23 additions & 15 deletions ev3dev2/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
except ImportError:
log.warning(library_load_warning_message("fcntl", "Display"))


class FbMem(object):

"""The framebuffer memory object.
Expand Down Expand Up @@ -114,6 +115,10 @@ class FbBitField(ctypes.Structure):
('msb_right', ctypes.c_uint32),
]

def __str__(self):
return "%s (offset %s, length %s, msg_right %s)" %\
(self.__class__.__name__, self.offset, self.length, self.msb_right)

"""The fb_var_screeninfo struct from fb.h."""

_fields_ = [
Expand All @@ -133,6 +138,11 @@ class FbBitField(ctypes.Structure):
('transp', FbBitField),
]

def __str__(self):
return ("%sx%s at (%s,%s), bpp %s, grayscale %s, red %s, green %s, blue %s, transp %s" %
(self.xres, self.yres, self.xoffset, self.yoffset, self.bits_per_pixel, self.grayscale,
self.red, self.green, self.blue, self.transp))

def __init__(self, fbdev=None):
"""Create the FbMem framebuffer memory object."""
fid = FbMem._open_fbdev(fbdev)
Expand All @@ -143,11 +153,6 @@ def __init__(self, fbdev=None):
self.var_info = FbMem._get_var_info(fid)
self.mmap = fbmmap

def __del__(self):
"""Close the FbMem framebuffer memory object."""
self.mmap.close()
FbMem._close_fbdev(self.fid)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have been testing on an EV3 and all seems fine without this __del__

@staticmethod
def _open_fbdev(fbdev=None):
"""Return the framebuffer file descriptor.
Expand All @@ -160,11 +165,6 @@ def _open_fbdev(fbdev=None):
fbfid = os.open(dev, os.O_RDWR)
return fbfid

@staticmethod
def _close_fbdev(fbfid):
"""Close the framebuffer file descriptor."""
os.close(fbfid)

@staticmethod
def _get_fix_info(fbfid):
"""Return the fix screen info from the framebuffer file descriptor."""
Expand Down Expand Up @@ -209,12 +209,16 @@ def __init__(self, desc='Display'):

if self.var_info.bits_per_pixel == 1:
im_type = "1"
elif self.var_info.bits_per_pixel == 16:
im_type = "RGB"

elif self.platform == "ev3" and self.var_info.bits_per_pixel == 32:
im_type = "L"

elif self.var_info.bits_per_pixel == 16 or self.var_info.bits_per_pixel == 32:
im_type = "RGB"

else:
raise Exception("Not supported")
raise Exception("Not supported - platform %s with bits_per_pixel %s" %
(self.platform, self.var_info.bits_per_pixel))

self._img = Image.new(
im_type,
Expand Down Expand Up @@ -295,12 +299,16 @@ def update(self):
if self.var_info.bits_per_pixel == 1:
b = self._img.tobytes("raw", "1;R")
self.mmap[:len(b)] = b

elif self.var_info.bits_per_pixel == 16:
self.mmap[:] = self._img_to_rgb565_bytes()
elif self.platform == "ev3" and self.var_info.bits_per_pixel == 32:

elif self.var_info.bits_per_pixel == 32:
self.mmap[:] = self._img.convert("RGB").tobytes("raw", "XRGB")

else:
raise Exception("Not supported")
raise Exception("Not supported - platform %s with bits_per_pixel %s" %
(self.platform, self.var_info.bits_per_pixel))

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

Expand Down