mirror of https://github.com/Desuuuu/klipper.git
display: Add a new PrinterDisplayTemplate class for tracking template macros
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
35ff49e546
commit
a6ab56c0a6
|
@ -1,6 +1,6 @@
|
||||||
# Basic LCD display support
|
# Basic LCD display support
|
||||||
#
|
#
|
||||||
# Copyright (C) 2018-2020 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2018-2022 Kevin O'Connor <kevin@koconnor.net>
|
||||||
# Copyright (C) 2018 Aleph Objects, Inc <marcio@alephobjects.com>
|
# Copyright (C) 2018 Aleph Objects, Inc <marcio@alephobjects.com>
|
||||||
# Copyright (C) 2018 Eric Callahan <arksine.code@gmail.com>
|
# Copyright (C) 2018 Eric Callahan <arksine.code@gmail.com>
|
||||||
#
|
#
|
||||||
|
@ -83,47 +83,20 @@ class DisplayGroup:
|
||||||
display.draw_text(row, col, text.replace('\n', ''), eventtime)
|
display.draw_text(row, col, text.replace('\n', ''), eventtime)
|
||||||
context.clear() # Remove circular references for better gc
|
context.clear() # Remove circular references for better gc
|
||||||
|
|
||||||
class PrinterLCD:
|
# Global cache of DisplayTemplate, DisplayGroup, and glyphs
|
||||||
|
class PrinterDisplayTemplate:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
self.reactor = self.printer.get_reactor()
|
|
||||||
# Load low-level lcd handler
|
|
||||||
self.lcd_chip = config.getchoice('lcd_type', LCD_chips)(config)
|
|
||||||
# Load menu and display_status
|
|
||||||
self.menu = None
|
|
||||||
name = config.get_name()
|
|
||||||
if name == 'display':
|
|
||||||
# only load menu for primary display
|
|
||||||
self.menu = menu.MenuManager(config, self)
|
|
||||||
self.printer.load_object(config, "display_status")
|
|
||||||
# Configurable display
|
|
||||||
self.display_templates = {}
|
self.display_templates = {}
|
||||||
self.display_data_groups = {}
|
self.display_data_groups = {}
|
||||||
|
self.display_glyphs = {}
|
||||||
self.load_config(config)
|
self.load_config(config)
|
||||||
dgroup = "_default_16x4"
|
def get_display_templates(self):
|
||||||
if self.lcd_chip.get_dimensions()[0] == 20:
|
return self.display_templates
|
||||||
dgroup = "_default_20x4"
|
def get_display_data_groups(self):
|
||||||
dgroup = config.get('display_group', dgroup)
|
return self.display_data_groups
|
||||||
self.show_data_group = self.display_data_groups.get(dgroup)
|
def get_display_glyphs(self):
|
||||||
if self.show_data_group is None:
|
return self.display_glyphs
|
||||||
raise config.error("Unknown display_data group '%s'" % (dgroup,))
|
|
||||||
# Screen updating
|
|
||||||
self.printer.register_event_handler("klippy:ready", self.handle_ready)
|
|
||||||
self.screen_update_timer = self.reactor.register_timer(
|
|
||||||
self.screen_update_event)
|
|
||||||
self.redraw_request_pending = False
|
|
||||||
self.redraw_time = 0.
|
|
||||||
# Register g-code commands
|
|
||||||
gcode = self.printer.lookup_object("gcode")
|
|
||||||
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', name,
|
|
||||||
self.cmd_SET_DISPLAY_GROUP,
|
|
||||||
desc=self.cmd_SET_DISPLAY_GROUP_help)
|
|
||||||
if name == 'display':
|
|
||||||
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', None,
|
|
||||||
self.cmd_SET_DISPLAY_GROUP)
|
|
||||||
def get_dimensions(self):
|
|
||||||
return self.lcd_chip.get_dimensions()
|
|
||||||
# Configurable display
|
|
||||||
def _parse_glyph(self, config, glyph_name, data, width, height):
|
def _parse_glyph(self, config, glyph_name, data, width, height):
|
||||||
glyph_data = []
|
glyph_data = []
|
||||||
for line in data.split('\n'):
|
for line in data.split('\n'):
|
||||||
|
@ -170,7 +143,7 @@ class PrinterLCD:
|
||||||
self.display_data_groups[group_name] = dg
|
self.display_data_groups[group_name] = dg
|
||||||
# Load display glyphs
|
# Load display glyphs
|
||||||
dg_prefix = 'display_glyph '
|
dg_prefix = 'display_glyph '
|
||||||
icons = {}
|
self.display_glyphs = icons = {}
|
||||||
dg_main = config.get_prefix_sections(dg_prefix)
|
dg_main = config.get_prefix_sections(dg_prefix)
|
||||||
dg_main_names = {c.get_name(): 1 for c in dg_main}
|
dg_main_names = {c.get_name(): 1 for c in dg_main}
|
||||||
dg_def = [c for c in dconfig.get_prefix_sections(dg_prefix)
|
dg_def = [c for c in dconfig.get_prefix_sections(dg_prefix)
|
||||||
|
@ -188,8 +161,56 @@ class PrinterLCD:
|
||||||
slot = dg.getint('hd44780_slot', minval=0, maxval=7)
|
slot = dg.getint('hd44780_slot', minval=0, maxval=7)
|
||||||
idata = self._parse_glyph(config, glyph_name, data, 5, 8)
|
idata = self._parse_glyph(config, glyph_name, data, 5, 8)
|
||||||
icons.setdefault(glyph_name, {})['icon5x8'] = (slot, idata)
|
icons.setdefault(glyph_name, {})['icon5x8'] = (slot, idata)
|
||||||
self.lcd_chip.set_glyphs(icons)
|
|
||||||
# Initialization
|
def lookup_display_templates(config):
|
||||||
|
printer = config.get_printer()
|
||||||
|
dt = printer.lookup_object("display_template", None)
|
||||||
|
if dt is None:
|
||||||
|
dt = PrinterDisplayTemplate(config)
|
||||||
|
printer.add_object("display_template", dt)
|
||||||
|
return dt
|
||||||
|
|
||||||
|
class PrinterLCD:
|
||||||
|
def __init__(self, config):
|
||||||
|
self.printer = config.get_printer()
|
||||||
|
self.reactor = self.printer.get_reactor()
|
||||||
|
# Load low-level lcd handler
|
||||||
|
self.lcd_chip = config.getchoice('lcd_type', LCD_chips)(config)
|
||||||
|
# Load menu and display_status
|
||||||
|
self.menu = None
|
||||||
|
name = config.get_name()
|
||||||
|
if name == 'display':
|
||||||
|
# only load menu for primary display
|
||||||
|
self.menu = menu.MenuManager(config, self)
|
||||||
|
self.printer.load_object(config, "display_status")
|
||||||
|
# Configurable display
|
||||||
|
templates = lookup_display_templates(config)
|
||||||
|
self.display_templates = templates.get_display_templates()
|
||||||
|
self.display_data_groups = templates.get_display_data_groups()
|
||||||
|
self.lcd_chip.set_glyphs(templates.get_display_glyphs())
|
||||||
|
dgroup = "_default_16x4"
|
||||||
|
if self.lcd_chip.get_dimensions()[0] == 20:
|
||||||
|
dgroup = "_default_20x4"
|
||||||
|
dgroup = config.get('display_group', dgroup)
|
||||||
|
self.show_data_group = self.display_data_groups.get(dgroup)
|
||||||
|
if self.show_data_group is None:
|
||||||
|
raise config.error("Unknown display_data group '%s'" % (dgroup,))
|
||||||
|
# Screen updating
|
||||||
|
self.printer.register_event_handler("klippy:ready", self.handle_ready)
|
||||||
|
self.screen_update_timer = self.reactor.register_timer(
|
||||||
|
self.screen_update_event)
|
||||||
|
self.redraw_request_pending = False
|
||||||
|
self.redraw_time = 0.
|
||||||
|
# Register g-code commands
|
||||||
|
gcode = self.printer.lookup_object("gcode")
|
||||||
|
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', name,
|
||||||
|
self.cmd_SET_DISPLAY_GROUP,
|
||||||
|
desc=self.cmd_SET_DISPLAY_GROUP_help)
|
||||||
|
if name == 'display':
|
||||||
|
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', None,
|
||||||
|
self.cmd_SET_DISPLAY_GROUP)
|
||||||
|
def get_dimensions(self):
|
||||||
|
return self.lcd_chip.get_dimensions()
|
||||||
def handle_ready(self):
|
def handle_ready(self):
|
||||||
self.lcd_chip.init()
|
self.lcd_chip.init()
|
||||||
# Start screen update timer
|
# Start screen update timer
|
||||||
|
|
Loading…
Reference in New Issue