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 <kevin@koconnor.net>
This commit is contained in:
parent
41dd53f62c
commit
2e7f38eadd
|
@ -28,11 +28,12 @@ class HD44780:
|
||||||
self.mcu.register_config_callback(self.build_config)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
self.send_data_cmd = self.send_cmds_cmd = None
|
self.send_data_cmd = self.send_cmds_cmd = None
|
||||||
# framebuffers
|
# framebuffers
|
||||||
self.text_framebuffer = bytearray(' '*80)
|
self.text_framebuffers = [bytearray(' '*40), bytearray(' '*40)]
|
||||||
self.glyph_framebuffer = bytearray(64)
|
self.glyph_framebuffer = bytearray(64)
|
||||||
self.all_framebuffers = [
|
self.all_framebuffers = [
|
||||||
# Text framebuffer
|
# Text framebuffers
|
||||||
(self.text_framebuffer, bytearray('~'*80), 0x80),
|
(self.text_framebuffers[0], bytearray('~'*40), 0x80),
|
||||||
|
(self.text_framebuffers[1], bytearray('~'*40), 0xc0),
|
||||||
# Glyph framebuffer
|
# Glyph framebuffer
|
||||||
(self.glyph_framebuffer, bytearray('~'*64), 0x40) ]
|
(self.glyph_framebuffer, bytearray('~'*64), 0x40) ]
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
|
@ -71,8 +72,6 @@ class HD44780:
|
||||||
# Transmit changes
|
# Transmit changes
|
||||||
for pos, count in diffs:
|
for pos, count in diffs:
|
||||||
chip_pos = pos
|
chip_pos = pos
|
||||||
if fb_id == 0x80 and pos >= 40:
|
|
||||||
chip_pos += 0x40 - 40
|
|
||||||
self.send([fb_id + chip_pos])
|
self.send([fb_id + chip_pos])
|
||||||
self.send(new_data[pos:pos+count], is_data=True)
|
self.send(new_data[pos:pos+count], is_data=True)
|
||||||
old_data[:] = new_data
|
old_data[:] = new_data
|
||||||
|
@ -89,13 +88,13 @@ class HD44780:
|
||||||
# Add custom fonts
|
# Add custom fonts
|
||||||
self.glyph_framebuffer[:len(HD44780_chars)] = HD44780_chars
|
self.glyph_framebuffer[:len(HD44780_chars)] = HD44780_chars
|
||||||
for i in range(len(self.glyph_framebuffer)):
|
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()
|
self.flush()
|
||||||
def write_text(self, x, y, data):
|
def write_text(self, x, y, data):
|
||||||
if x + len(data) > 20:
|
if x + len(data) > 20:
|
||||||
data = data[:20 - min(x, 20)]
|
data = data[:20 - min(x, 20)]
|
||||||
pos = [0, 40, 20, 60][y] + x
|
pos = x + ((y & 0x02) >> 1) * 20
|
||||||
self.text_framebuffer[pos:pos+len(data)] = data
|
self.text_framebuffers[y & 1][pos:pos+len(data)] = data
|
||||||
def write_glyph(self, x, y, glyph_name):
|
def write_glyph(self, x, y, glyph_name):
|
||||||
char = TextGlyphs.get(glyph_name)
|
char = TextGlyphs.get(glyph_name)
|
||||||
if char is not None:
|
if char is not None:
|
||||||
|
@ -104,7 +103,9 @@ class HD44780:
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.text_framebuffer[:] = ' '*80
|
spaces = ' ' * 40
|
||||||
|
self.text_framebuffers[0][:] = spaces
|
||||||
|
self.text_framebuffers[1][:] = spaces
|
||||||
def get_dimensions(self):
|
def get_dimensions(self):
|
||||||
return (20, 4)
|
return (20, 4)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue