aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/display/hd44780.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-09-20 14:16:24 -0400
committerKevinOConnor <kevin@koconnor.net>2018-09-21 16:39:38 -0400
commit7cca8d970ac7d19784d621865100470de2fa8092 (patch)
tree8fac6a258d0607dd0a13fdad9f66da29e61d9ea5 /klippy/extras/display/hd44780.py
parent742d6481a9b0b946739861423c7958bce405be94 (diff)
downloadkutter-7cca8d970ac7d19784d621865100470de2fa8092.tar.gz
kutter-7cca8d970ac7d19784d621865100470de2fa8092.tar.xz
kutter-7cca8d970ac7d19784d621865100470de2fa8092.zip
hd44780: Simplify framebuffer access
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/display/hd44780.py')
-rw-r--r--klippy/extras/display/hd44780.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/klippy/extras/display/hd44780.py b/klippy/extras/display/hd44780.py
index 2bdf3a30..243a3fcb 100644
--- a/klippy/extras/display/hd44780.py
+++ b/klippy/extras/display/hd44780.py
@@ -28,9 +28,13 @@ 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), bytearray('~'*80), 0x80)
- self.glyph_framebuffer = (bytearray(64), bytearray('~'*64), 0x40)
- self.framebuffers = [self.text_framebuffer, self.glyph_framebuffer]
+ self.text_framebuffer = bytearray(' '*80)
+ self.glyph_framebuffer = bytearray(64)
+ self.all_framebuffers = [
+ # Text framebuffer
+ (self.text_framebuffer, bytearray('~'*80), 0x80),
+ # Glyph framebuffer
+ (self.glyph_framebuffer, bytearray('~'*64), 0x40) ]
def build_config(self):
self.mcu.add_config_cmd(
"config_hd44780 oid=%d rs_pin=%s e_pin=%s"
@@ -51,7 +55,7 @@ class HD44780:
#logging.debug("hd44780 %d %s", is_data, repr(cmds))
def flush(self):
# Find all differences in the framebuffers and send them to the chip
- for new_data, old_data, fb_id in self.framebuffers:
+ for new_data, old_data, fb_id in self.all_framebuffers:
if new_data == old_data:
continue
# Find the position of all changed bytes in this framebuffer
@@ -83,15 +87,15 @@ class HD44780:
minclock = self.mcu.print_time_to_clock(print_time + i * .100)
self.send_cmds_cmd.send([self.oid, cmds], minclock=minclock)
# Add custom fonts
- self.glyph_framebuffer[0][:len(HD44780_chars)] = HD44780_chars
- for i in range(len(self.glyph_framebuffer[0])):
- self.glyph_framebuffer[1][i] = self.glyph_framebuffer[0][i] ^ 1
+ 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.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[0][pos:pos+len(data)] = data
+ self.text_framebuffer[pos:pos+len(data)] = data
def write_glyph(self, x, y, glyph_name):
char = TextGlyphs.get(glyph_name)
if char is not None:
@@ -100,7 +104,7 @@ class HD44780:
return 1
return 0
def clear(self):
- self.text_framebuffer[0][:] = ' '*80
+ self.text_framebuffer[:] = ' '*80
HD44780_chars = [
# Extruder (a thermometer)