Skip to content

Commit

Permalink
Rename x0,y0,x1,y1 to left,top,right,bottom; Fix test data
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed Oct 26, 2020
1 parent a0f98de commit 8fcd861
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions luma/lcd/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,16 +1007,16 @@ def display(self, image):
if self.framebuffer.redraw_required(image):
self._cleanup_custom(image)
# Expand bounding box to align to cell boundaries (5,8)
x0, y0, x1, y1 = self.framebuffer.bounding_box
x0 = x0 // 5 * 5
x1 = x1 // 5 * 5 if not x1 % 5 else (x1 // 5 + 1) * 5
y0 = y0 // 8 * 8
y1 = y1 // 8 * 8 if not y1 % 8 else (y1 // 8 + 1) * 8
self.framebuffer.bounding_box = (x0, y0, x1, y1)

for j in range(y0 // 8, y1 // 8):
left, top, right, bottom = self.framebuffer.bounding_box
left = left // 5 * 5
right = right // 5 * 5 if not right % 5 else (right // 5 + 1) * 5
top = top // 8 * 8
bottom = bottom // 8 * 8 if not bottom % 8 else (bottom // 8 + 1) * 8
self.framebuffer.bounding_box = (left, top, right, bottom)

for j in range(top // 8, bottom // 8):
buf = []
for i in range(x0 // 5, x1 // 5):
for i in range(left // 5, right // 5):
img = self.framebuffer.image.crop((i * 5, j * 8,
(i + 1) * 5, (j + 1) * 8))
bytes = img.tobytes()
Expand All @@ -1026,7 +1026,7 @@ def display(self, image):
self._make_custom(img)
c = self._custom.get(bytes, ord(self._undefined))
buf.append(c)
self.command(self._const.DDRAMADDR | (self._const.LINES[j] + (x0 // 5)))
self.command(self._const.DDRAMADDR | (self._const.LINES[j] + (left // 5)))
self.data(buf)

def _make_custom(self, img):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_hd44780.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_display():
Test the display with a line of text and a rectangle to demonstrate correct
functioning of the auto-create feature
"""
device = hd44780(interface, bitmode=8, gpio=gpio)
device = hd44780(interface, bitmode=8, gpio=gpio, framebuffer="full_frame")
interface.reset_mock()

# Use canvas to create a screen worth of data
Expand All @@ -102,16 +102,16 @@ def test_display():
drw.rectangle((10, 10, 49, 14), fill='white', outline='white')

# Send DDRAMADDR and ascii for the line of text
line1 = [call.command(0x81)] + \
[call.data([0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74])]
line1 = [call.command(0x80)] + \
[call.data([0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20])]

# Create custom characters for the scrollbar
custom = [call.command(0x40), call.data([0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x00])] + \
[call.command(0x48), call.data([0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x1f, 0x00])] + \
[call.command(0x50), call.data([0x00, 0x00, 0x1f, 0x01, 0x01, 0x01, 0x1f, 0x00])]

# Print the resulting custom characters to form the image of the scrollbar
line2 = [call.command(0xc1), call.data([0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x20])]
line2 = [call.command(0xc0), call.data([0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x20, 0x20])]

interface.assert_has_calls(line1 + custom + line2)

Expand All @@ -120,7 +120,7 @@ def test_custom_full():
"""
Auto-create feature runs out of custom character space
"""
device = hd44780(interface, bitmode=8, gpio=gpio)
device = hd44780(interface, bitmode=8, gpio=gpio, framebuffer="diff_to_previous")

# Consume 8 special character positions
img = Image.new('1', (80, 16), 0)
Expand Down

0 comments on commit 8fcd861

Please sign in to comment.