diff options
author | Martin Hierholzer <martin.hierholzer@desy.de> | 2020-11-20 20:49:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-20 14:49:38 -0500 |
commit | fcb78e50e50dae67d4f335464704e98bff26b8d9 (patch) | |
tree | cf0a55dd511574a0c8b22286a2e657c32b4ec03d /klippy/extras/display | |
parent | c6f0884140e8b5d2076af688b149c632336d9a29 (diff) | |
download | kutter-fcb78e50e50dae67d4f335464704e98bff26b8d9.tar.gz kutter-fcb78e50e50dae67d4f335464704e98bff26b8d9.tar.xz kutter-fcb78e50e50dae67d4f335464704e98bff26b8d9.zip |
hd44780: allow to configure line length (#3543)
This allows to use 16x4 displays rather than only 20x4.
Signed-off-by: Martin Hierholzer <hier@beta-centauri.de>
Diffstat (limited to 'klippy/extras/display')
-rw-r--r-- | klippy/extras/display/hd44780.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/klippy/extras/display/hd44780.py b/klippy/extras/display/hd44780.py index a868a736..3b56eb6e 100644 --- a/klippy/extras/display/hd44780.py +++ b/klippy/extras/display/hd44780.py @@ -7,6 +7,8 @@ import logging BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000 +LINE_LENGTH_DEFAULT="20" +LINE_LENGTH_OPTIONS={"16":16, "20":20} TextGlyphs = { 'right_arrow': '\x7e' } @@ -19,6 +21,8 @@ class HD44780: ppins = self.printer.lookup_object('pins') pins = [ppins.lookup_pin(config.get(name + '_pin')) for name in ['rs', 'e', 'd4', 'd5', 'd6', 'd7']] + self.line_length = config.getchoice('line_length', LINE_LENGTH_OPTIONS, + LINE_LENGTH_DEFAULT) mcu = None for pin_params in pins: if mcu is not None and pin_params['chip'] != mcu: @@ -31,12 +35,15 @@ class HD44780: self.send_data_cmd = self.send_cmds_cmd = None self.icons = {} # framebuffers - self.text_framebuffers = [bytearray(' '*40), bytearray(' '*40)] + self.text_framebuffers = [bytearray(' '*2*self.line_length), + bytearray(' '*2*self.line_length)] self.glyph_framebuffer = bytearray(64) self.all_framebuffers = [ # Text framebuffers - (self.text_framebuffers[0], bytearray('~'*40), 0x80), - (self.text_framebuffers[1], bytearray('~'*40), 0xc0), + (self.text_framebuffers[0], bytearray('~'*2*self.line_length), + 0x80), + (self.text_framebuffers[1], bytearray('~'*2*self.line_length), + 0xc0), # Glyph framebuffer (self.glyph_framebuffer, bytearray('~'*64), 0x40) ] def build_config(self): @@ -90,9 +97,9 @@ class HD44780: self.send_cmds_cmd.send([self.oid, cmds], minclock=minclock) self.flush() def write_text(self, x, y, data): - if x + len(data) > 20: - data = data[:20 - min(x, 20)] - pos = x + ((y & 0x02) >> 1) * 20 + if x + len(data) > self.line_length: + data = data[:self.line_length - min(x, self.line_length)] + pos = x + ((y & 0x02) >> 1) * self.line_length self.text_framebuffers[y & 1][pos:pos+len(data)] = data def set_glyphs(self, glyphs): for glyph_name, glyph_data in glyphs.items(): @@ -115,8 +122,8 @@ class HD44780: def write_graphics(self, x, y, data): pass def clear(self): - spaces = ' ' * 40 + spaces = ' ' * 2*self.line_length self.text_framebuffers[0][:] = spaces self.text_framebuffers[1][:] = spaces def get_dimensions(self): - return (20, 4) + return (self.line_length, 4) |