Skip to content

Commit

Permalink
fix(tests): fix testdisplay, add hwdisplay example
Browse files Browse the repository at this point in the history
  • Loading branch information
Carglglz committed Dec 25, 2024
1 parent 12955be commit a6fffea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
26 changes: 26 additions & 0 deletions tests/hwdisplay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import lvgl as lv
import pyb


class HwDisplayDriver:
def __init__(self, width=240, height=320, color_format=lv.COLOR_FORMAT.RGB565):
self.width = width
self.height = height
self.color_depth = lv.color_format_get_bpp(color_format)
self.color_size = lv.color_format_get_size(color_format)
self._debug = False

@property
def debug(self):
return self._debug

@debug.setter
def debug(self, x):
self._debug = x

def blit(self, x1, y1, w, h, buff):
pyb.LED((y1 % 4) + 1).toggle()
...


display = HwDisplayDriver()
33 changes: 24 additions & 9 deletions tests/testdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ def blit(self, x1, y1, w, h, buff):
tdisp = DummyDisplay(color_format=lv.COLOR_FORMAT.RGB888)


alloc_buffer = lambda buffersize: memoryview(bytearray(buffer_size))
# alloc_buffer = lambda buffersize: memoryview(bytearray(buffer_size))

factor = 10 ### Must be 1 if using an RGBBus
double_buf = True ### Must be False if using an RGBBus
# factor = 10 ### Must be 1 if using an RGBBus
# double_buf = True ### Must be False if using an RGBBus

buffer_size = tdisp.width * tdisp.height * (tdisp.color_depth // 8) // factor
# buffer_size = tdisp.width * tdisp.height * (tdisp.color_depth // 8) // factor

fbuf1 = alloc_buffer(buffer_size)
fbuf2 = alloc_buffer(buffer_size) if double_buf else None
# fbuf1 = alloc_buffer(buffer_size)
# fbuf2 = alloc_buffer(buffer_size) if double_buf else None


def get_display(
Expand All @@ -241,7 +241,22 @@ def get_display(
except Exception as e:
if sys.platform not in ["darwin", "linux"]:
sys.print_exception(e)
if hasattr(disp, "width") and hasattr(disp, "height"):
disp.width = width
disp.height = height
assert hasattr(disp, "width") is True, "expected width attribute in display driver"
assert (
hasattr(disp, "height") is True
), "expected height attribute in display driver"

assert (
hasattr(disp, "color_depth") is True
), "expected color_depth attribute in display driver"

alloc_buffer = lambda buffersize: memoryview(bytearray(buffer_size))

factor = 10 ### Must be 1 if using an RGBBus
double_buf = True ### Must be False if using an RGBBus

buffer_size = disp.width * disp.height * (disp.color_depth // 8) // factor

fbuf1 = alloc_buffer(buffer_size)
fbuf2 = alloc_buffer(buffer_size) if double_buf else None
return TestDisplayDriver(disp, fbuf1, fbuf2, color_format, mode, pointer)

0 comments on commit a6fffea

Please sign in to comment.