display: Use write_glyph() when writing special characters

Always use the write_glyph() method when writing special characters
during status screen updates.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-09-20 13:01:51 -04:00 committed by KevinOConnor
parent c8d9d575a1
commit 30a49d3186
4 changed files with 20 additions and 23 deletions

View File

@ -89,15 +89,15 @@ class PrinterLCD:
# Heaters # Heaters
if self.extruder0 is not None: if self.extruder0 is not None:
info = self.extruder0.get_heater().get_status(eventtime) info = self.extruder0.get_heater().get_status(eventtime)
lcd_chip.write_text(0, 0, lcd_chip.char_thermometer) lcd_chip.write_glyph(0, 0, 'extruder')
self.draw_heater(1, 0, info) self.draw_heater(1, 0, info)
if self.extruder1 is not None: if self.extruder1 is not None:
info = self.extruder1.get_heater().get_status(eventtime) info = self.extruder1.get_heater().get_status(eventtime)
lcd_chip.write_text(0, 1, lcd_chip.char_thermometer) lcd_chip.write_glyph(0, 1, 'extruder')
self.draw_heater(1, 1, info) self.draw_heater(1, 1, info)
if self.heater_bed is not None: if self.heater_bed is not None:
info = self.heater_bed.get_status(eventtime) info = self.heater_bed.get_status(eventtime)
lcd_chip.write_text(10, 0, lcd_chip.char_heater_bed) lcd_chip.write_glyph(10, 0, 'bed')
self.draw_heater(11, 0, info) self.draw_heater(11, 0, info)
# Fan speed # Fan speed
if self.fan is not None: if self.fan is not None:
@ -106,14 +106,14 @@ class PrinterLCD:
self.draw_percent(14, 1, 4, info['speed']) self.draw_percent(14, 1, 4, info['speed'])
# G-Code speed factor # G-Code speed factor
gcode_info = self.gcode.get_status(eventtime) gcode_info = self.gcode.get_status(eventtime)
lcd_chip.write_text(0, 2, lcd_chip.char_speed_factor) lcd_chip.write_glyph(0, 2, 'feedrate')
self.draw_percent(1, 2, 4, gcode_info['speed_factor']) self.draw_percent(1, 2, 4, gcode_info['speed_factor'])
# Print progress # Print progress
progress = None progress = None
toolhead_info = self.toolhead.get_status(eventtime) toolhead_info = self.toolhead.get_status(eventtime)
if self.progress is not None: if self.progress is not None:
progress = self.progress / 100. progress = self.progress / 100.
lcd_chip.write_text(8, 2, lcd_chip.char_usb) lcd_chip.write_glyph(8, 2, 'usb')
if toolhead_info['status'] != "Printing": if toolhead_info['status'] != "Printing":
# 5 second timeout when not printing # 5 second timeout when not printing
self.prg_time -= .5 self.prg_time -= .5
@ -122,10 +122,10 @@ class PrinterLCD:
elif self.sdcard is not None: elif self.sdcard is not None:
info = self.sdcard.get_status(eventtime) info = self.sdcard.get_status(eventtime)
progress = info['progress'] progress = info['progress']
lcd_chip.write_text(8, 2, lcd_chip.char_sd) lcd_chip.write_glyph(8, 2, 'sd')
if progress is not None: if progress is not None:
self.draw_percent(9, 2, 4, progress) self.draw_percent(9, 2, 4, progress)
lcd_chip.write_text(14, 2, lcd_chip.char_clock) lcd_chip.write_glyph(14, 2, 'clock')
self.draw_time(15, 2, toolhead_info['printing_time']) self.draw_time(15, 2, toolhead_info['printing_time'])
# If there is a message set by M117, display it instead of toolhead info # If there is a message set by M117, display it instead of toolhead info
if self.message: if self.message:
@ -212,16 +212,23 @@ class PrinterLCD:
else: else:
self.draw_status(0, 3, gcode_info, toolhead_info) self.draw_status(0, 3, gcode_info, toolhead_info)
# Screen update helpers # Screen update helpers
def draw_text(self, x, y, mixed_text):
pos = x
for i, text in enumerate(mixed_text.split('~')):
if i & 1 == 0:
# write text
self.lcd_chip.write_text(pos, y, text)
pos += len(text)
else:
# write glyph
pos += self.lcd_chip.write_glyph(pos, y, text)
def draw_heater(self, x, y, info): def draw_heater(self, x, y, info):
temperature, target = info['temperature'], info['target'] temperature, target = info['temperature'], info['target']
if target and abs(temperature - target) > 2.: if target and abs(temperature - target) > 2.:
s = "%3.0f%s%.0f" % ( self.draw_text(x, y, "%3.0f~right_arrow~%.0f~degrees~" % (
temperature, self.lcd_chip.char_right_arrow, target) temperature, target))
else: else:
s = "%3.0f" % (temperature,) self.draw_text(x, y, "%3.0f~degrees~" % (temperature,))
if self.lcd_type == 'hd44780':
s += self.lcd_chip.char_degrees
self.lcd_chip.write_text(x, y, s)
def draw_percent(self, x, y, width, value, align='^'): def draw_percent(self, x, y, width, value, align='^'):
self.lcd_chip.write_text(x, y, '{:{}{}.0%}'.format(value, align, width)) self.lcd_chip.write_text(x, y, '{:{}{}.0%}'.format(value, align, width))
def draw_time(self, x, y, seconds): def draw_time(self, x, y, seconds):

View File

@ -11,14 +11,6 @@ BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
HD44780_DELAY = .000037 HD44780_DELAY = .000037
class HD44780: class HD44780:
char_right_arrow = '\x7e'
char_thermometer = '\x00'
char_heater_bed = '\x01'
char_speed_factor = '\x02'
char_clock = '\x03'
char_degrees = '\x04'
char_usb = '\x05'
char_sd = '\x06'
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() self.printer = config.get_printer()
# pin config # pin config

View File

@ -15,7 +15,6 @@ ST7920_SYNC_DELAY = .000045
TextGlyphs = { 'right_arrow': '\x1a' } TextGlyphs = { 'right_arrow': '\x1a' }
class ST7920: class ST7920:
char_right_arrow = '\x1a'
def __init__(self, config): def __init__(self, config):
printer = config.get_printer() printer = config.get_printer()
# pin config # pin config

View File

@ -12,7 +12,6 @@ BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
TextGlyphs = { 'right_arrow': '\x1a' } TextGlyphs = { 'right_arrow': '\x1a' }
class UC1701: class UC1701:
char_right_arrow = '\x1a'
CURRENT_BUF, OLD_BUF = 0, 1 CURRENT_BUF, OLD_BUF = 0, 1
EMPTY_CHAR = (0, 32, 255) EMPTY_CHAR = (0, 32, 255)
def __init__(self, config): def __init__(self, config):