mirror of https://github.com/Desuuuu/klipper.git
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>
This commit is contained in:
parent
c6f0884140
commit
fcb78e50e5
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue