aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/Config_Reference.md4
-rw-r--r--klippy/extras/display/hd44780.py23
2 files changed, 19 insertions, 8 deletions
diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md
index 869c9c94..9036dfe0 100644
--- a/docs/Config_Reference.md
+++ b/docs/Config_Reference.md
@@ -2983,6 +2983,10 @@ lcd_type:
#d7_pin:
# The pins connected to an hd44780 type lcd. These parameters must
# be provided when using an hd44780 display.
+#line_length:
+# Set the number of characters per line for an hd44780 type lcd.
+# Possible values are 20 (default) and 16. The number of lines is
+# fixed to 4.
#cs_pin:
#sclk_pin:
#sid_pin:
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)