From 2e7f38eaddd070c9712230321b9175ca12411a4c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 1 Dec 2019 19:11:03 -0500 Subject: [PATCH] hd44780: Use two separate text framebuffers There is concern that some lcd boards that emulate the hd44780 don't support text updates that wrap the two text framebuffers. Update the code to treat the two text areas as two separate framebuffers. Signed-off-by: Kevin O'Connor --- klippy/extras/display/hd44780.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/klippy/extras/display/hd44780.py b/klippy/extras/display/hd44780.py index 7a56720b..77fd3b40 100644 --- a/klippy/extras/display/hd44780.py +++ b/klippy/extras/display/hd44780.py @@ -28,11 +28,12 @@ class HD44780: self.mcu.register_config_callback(self.build_config) self.send_data_cmd = self.send_cmds_cmd = None # framebuffers - self.text_framebuffer = bytearray(' '*80) + self.text_framebuffers = [bytearray(' '*40), bytearray(' '*40)] self.glyph_framebuffer = bytearray(64) self.all_framebuffers = [ - # Text framebuffer - (self.text_framebuffer, bytearray('~'*80), 0x80), + # Text framebuffers + (self.text_framebuffers[0], bytearray('~'*40), 0x80), + (self.text_framebuffers[1], bytearray('~'*40), 0xc0), # Glyph framebuffer (self.glyph_framebuffer, bytearray('~'*64), 0x40) ] def build_config(self): @@ -71,8 +72,6 @@ class HD44780: # Transmit changes for pos, count in diffs: chip_pos = pos - if fb_id == 0x80 and pos >= 40: - chip_pos += 0x40 - 40 self.send([fb_id + chip_pos]) self.send(new_data[pos:pos+count], is_data=True) old_data[:] = new_data @@ -89,13 +88,13 @@ class HD44780: # Add custom fonts self.glyph_framebuffer[:len(HD44780_chars)] = HD44780_chars for i in range(len(self.glyph_framebuffer)): - self.all_framebuffers[1][1][i] = self.glyph_framebuffer[i] ^ 1 + self.all_framebuffers[2][1][i] = self.glyph_framebuffer[i] ^ 1 self.flush() def write_text(self, x, y, data): if x + len(data) > 20: data = data[:20 - min(x, 20)] - pos = [0, 40, 20, 60][y] + x - self.text_framebuffer[pos:pos+len(data)] = data + pos = x + ((y & 0x02) >> 1) * 20 + self.text_framebuffers[y & 1][pos:pos+len(data)] = data def write_glyph(self, x, y, glyph_name): char = TextGlyphs.get(glyph_name) if char is not None: @@ -104,7 +103,9 @@ class HD44780: return 1 return 0 def clear(self): - self.text_framebuffer[:] = ' '*80 + spaces = ' ' * 40 + self.text_framebuffers[0][:] = spaces + self.text_framebuffers[1][:] = spaces def get_dimensions(self): return (20, 4)