mirror of https://github.com/Desuuuu/klipper.git
display: Support requesting a screen redraw on a menu key press
Add a request_redraw() method and call it when a key menu event occurs. Limit these proactive screen redraws to no more than 4 per second. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
1bdf705524
commit
8fa1c97767
|
@ -100,9 +100,12 @@ class PrinterLCD:
|
||||||
self.show_data_group = self.display_data_groups.get(dgroup)
|
self.show_data_group = self.display_data_groups.get(dgroup)
|
||||||
if self.show_data_group is None:
|
if self.show_data_group is None:
|
||||||
raise config.error("Unknown display_data group '%s'" % (dgroup,))
|
raise config.error("Unknown display_data group '%s'" % (dgroup,))
|
||||||
|
# Screen updating
|
||||||
self.printer.register_event_handler("klippy:ready", self.handle_ready)
|
self.printer.register_event_handler("klippy:ready", self.handle_ready)
|
||||||
self.screen_update_timer = self.reactor.register_timer(
|
self.screen_update_timer = self.reactor.register_timer(
|
||||||
self.screen_update_event)
|
self.screen_update_event)
|
||||||
|
self.redraw_request_pending = False
|
||||||
|
self.redraw_time = 0.
|
||||||
# Register g-code commands
|
# Register g-code commands
|
||||||
gcode = self.printer.lookup_object("gcode")
|
gcode = self.printer.lookup_object("gcode")
|
||||||
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', name,
|
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', name,
|
||||||
|
@ -111,6 +114,8 @@ class PrinterLCD:
|
||||||
if name == 'display':
|
if name == 'display':
|
||||||
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', None,
|
gcode.register_mux_command('SET_DISPLAY_GROUP', 'DISPLAY', None,
|
||||||
self.cmd_SET_DISPLAY_GROUP)
|
self.cmd_SET_DISPLAY_GROUP)
|
||||||
|
def get_dimensions(self):
|
||||||
|
return self.lcd_chip.get_dimensions()
|
||||||
# Configurable display
|
# 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 = []
|
||||||
|
@ -184,19 +189,28 @@ class PrinterLCD:
|
||||||
self.reactor.update_timer(self.screen_update_timer, self.reactor.NOW)
|
self.reactor.update_timer(self.screen_update_timer, self.reactor.NOW)
|
||||||
# Screen updating
|
# Screen updating
|
||||||
def screen_update_event(self, eventtime):
|
def screen_update_event(self, eventtime):
|
||||||
|
if self.redraw_request_pending:
|
||||||
|
self.redraw_request_pending = False
|
||||||
|
self.redraw_time = eventtime + 0.250
|
||||||
|
self.lcd_chip.clear()
|
||||||
# update menu component
|
# update menu component
|
||||||
if self.menu is not None:
|
if self.menu is not None:
|
||||||
ret = self.menu.screen_update_event(eventtime)
|
ret = self.menu.screen_update_event(eventtime)
|
||||||
if ret:
|
if ret:
|
||||||
return ret
|
self.lcd_chip.flush()
|
||||||
|
return eventtime + .500
|
||||||
# Update normal display
|
# Update normal display
|
||||||
self.lcd_chip.clear()
|
|
||||||
try:
|
try:
|
||||||
self.show_data_group.show(self, self.display_templates, eventtime)
|
self.show_data_group.show(self, self.display_templates, eventtime)
|
||||||
except:
|
except:
|
||||||
logging.exception("Error during display screen update")
|
logging.exception("Error during display screen update")
|
||||||
self.lcd_chip.flush()
|
self.lcd_chip.flush()
|
||||||
return eventtime + .500
|
return eventtime + .500
|
||||||
|
def request_redraw(self):
|
||||||
|
if self.redraw_request_pending:
|
||||||
|
return
|
||||||
|
self.redraw_request_pending = True
|
||||||
|
self.reactor.update_timer(self.screen_update_timer, self.redraw_time)
|
||||||
def draw_text(self, row, col, mixed_text, eventtime):
|
def draw_text(self, row, col, mixed_text, eventtime):
|
||||||
pos = col
|
pos = col
|
||||||
for i, text in enumerate(mixed_text.split('~')):
|
for i, text in enumerate(mixed_text.split('~')):
|
||||||
|
|
|
@ -616,7 +616,6 @@ menu_items = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MENU_UPDATE_DELAY = .100
|
|
||||||
TIMER_DELAY = .100
|
TIMER_DELAY = .100
|
||||||
|
|
||||||
|
|
||||||
|
@ -636,7 +635,7 @@ class MenuManager:
|
||||||
self.context = {}
|
self.context = {}
|
||||||
self.root = None
|
self.root = None
|
||||||
self._root = config.get('menu_root', '__main')
|
self._root = config.get('menu_root', '__main')
|
||||||
self.cols, self.rows = self.display.lcd_chip.get_dimensions()
|
self.cols, self.rows = self.display.get_dimensions()
|
||||||
self.timeout = config.getint('menu_timeout', 0)
|
self.timeout = config.getint('menu_timeout', 0)
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
self.eventtime = 0
|
self.eventtime = 0
|
||||||
|
@ -808,14 +807,11 @@ class MenuManager:
|
||||||
|
|
||||||
def screen_update_event(self, eventtime):
|
def screen_update_event(self, eventtime):
|
||||||
# screen update
|
# screen update
|
||||||
if self.is_running():
|
if not self.is_running():
|
||||||
self.display.lcd_chip.clear()
|
return False
|
||||||
for y, line in enumerate(self.render(eventtime)):
|
for y, line in enumerate(self.render(eventtime)):
|
||||||
self.display.draw_text(y, 0, line, eventtime)
|
self.display.draw_text(y, 0, line, eventtime)
|
||||||
self.display.lcd_chip.flush()
|
return True
|
||||||
return eventtime + MENU_UPDATE_DELAY
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def up(self, fast_rate=False):
|
def up(self, fast_rate=False):
|
||||||
container = self.stack_peek()
|
container = self.stack_peek()
|
||||||
|
@ -998,6 +994,7 @@ class MenuManager:
|
||||||
self.down(True)
|
self.down(True)
|
||||||
elif key == 'back':
|
elif key == 'back':
|
||||||
self.back()
|
self.back()
|
||||||
|
self.display.request_redraw()
|
||||||
|
|
||||||
# Collection of manager class helper methods
|
# Collection of manager class helper methods
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue