display: Support writing single character glyphs using write_glyph()

Add write_glyph() support to hd44780.py.  Update uc1701.py and
st7920.py to support writing single character glyphs via
write_glyph().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-09-20 12:40:30 -04:00 committed by KevinOConnor
parent 2a5778be3a
commit c8d9d575a1
5 changed files with 43 additions and 7 deletions

View File

@ -142,12 +142,12 @@ 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)
self.lcd_chip.write_glyph(0, 0, 'nozzle') self.lcd_chip.write_glyph(0, 0, 'extruder')
self.draw_heater(2, 0, info) self.draw_heater(2, 0, info)
extruder_count = 1 extruder_count = 1
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)
self.lcd_chip.write_glyph(0, 1, 'nozzle') self.lcd_chip.write_glyph(0, 1, 'extruder')
self.draw_heater(2, 1, info) self.draw_heater(2, 1, info)
extruder_count = 2 extruder_count = 2
if self.heater_bed is not None: if self.heater_bed is not None:

View File

@ -100,11 +100,18 @@ class HD44780:
data = data[:20 - min(x, 20)] data = data[:20 - min(x, 20)]
pos = [0, 40, 20, 60][y] + x pos = [0, 40, 20, 60][y] + x
self.text_framebuffer[0][pos:pos+len(data)] = data self.text_framebuffer[0][pos:pos+len(data)] = data
def write_glyph(self, x, y, glyph_name):
char = TextGlyphs.get(glyph_name)
if char is not None:
# Draw character
self.write_text(x, y, char)
return 1
return 0
def clear(self): def clear(self):
self.text_framebuffer[0][:] = ' '*80 self.text_framebuffer[0][:] = ' '*80
HD44780_chars = [ HD44780_chars = [
# Thermometer # Extruder (a thermometer)
0b00100, 0b00100,
0b01010, 0b01010,
0b01010, 0b01010,
@ -122,7 +129,7 @@ HD44780_chars = [
0b11111, 0b11111,
0b00000, 0b00000,
0b00000, 0b00000,
# Speed factor # Feed rate
0b11100, 0b11100,
0b10000, 0b10000,
0b11000, 0b11000,
@ -168,3 +175,14 @@ HD44780_chars = [
0b11111, 0b11111,
0b00000, 0b00000,
] ]
TextGlyphs = {
'right_arrow': '\x7e',
'extruder': '\x00',
'bed': '\x01',
'feedrate': '\x02',
'clock': '\x03',
'degrees': '\x04',
'usb': '\x05',
'sd': '\x06',
}

View File

@ -4,7 +4,7 @@
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
nozzle_icon = [ extruder_icon = [
0b0000000000000000, 0b0000000000000000,
0b0000000000000000, 0b0000000000000000,
0b0000111111110000, 0b0000111111110000,
@ -138,7 +138,7 @@ feedrate_icon = [
] ]
Icons16x16 = { Icons16x16 = {
'nozzle': nozzle_icon, 'extruder': extruder_icon,
'bed': bed_icon, 'bed_heat1': bed_heat1_icon, 'bed_heat2': bed_heat2_icon, 'bed': bed_icon, 'bed_heat1': bed_heat1_icon, 'bed_heat2': bed_heat2_icon,
'fan1': fan1_icon, 'fan2': fan2_icon, 'fan1': fan1_icon, 'fan2': fan2_icon,
'feedrate': feedrate_icon, 'feedrate': feedrate_icon,

View File

@ -12,6 +12,8 @@ BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
ST7920_CMD_DELAY = .000020 ST7920_CMD_DELAY = .000020
ST7920_SYNC_DELAY = .000045 ST7920_SYNC_DELAY = .000045
TextGlyphs = { 'right_arrow': '\x1a' }
class ST7920: class ST7920:
char_right_arrow = '\x1a' char_right_arrow = '\x1a'
def __init__(self, config): def __init__(self, config):
@ -132,12 +134,19 @@ class ST7920:
if glyph_id is not None and x & 1 == 0: if glyph_id is not None and x & 1 == 0:
# Render cached icon using character generator # Render cached icon using character generator
self.write_text(x, y, glyph_id) self.write_text(x, y, glyph_id)
return return 2
icon = icons.Icons16x16.get(glyph_name) icon = icons.Icons16x16.get(glyph_name)
if icon is not None: if icon is not None:
# Draw icon in graphics mode # Draw icon in graphics mode
for i, bits in enumerate(icon): for i, bits in enumerate(icon):
self.write_graphics(x, y, i, [(bits >> 8) & 0xff, bits & 0xff]) self.write_graphics(x, y, i, [(bits >> 8) & 0xff, bits & 0xff])
return 2
char = TextGlyphs.get(glyph_name)
if char is not None:
# Draw character
self.write_text(x, y, char)
return 1
return 0
def clear(self): def clear(self):
self.text_framebuffer[0][:] = ' '*64 self.text_framebuffer[0][:] = ' '*64
zeros = bytearray(32) zeros = bytearray(32)

View File

@ -9,6 +9,8 @@ import icons, font8x14
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000 BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
TextGlyphs = { 'right_arrow': '\x1a' }
class UC1701: class UC1701:
char_right_arrow = '\x1a' char_right_arrow = '\x1a'
CURRENT_BUF, OLD_BUF = 0, 1 CURRENT_BUF, OLD_BUF = 0, 1
@ -153,6 +155,13 @@ class UC1701:
# Draw icon in graphics mode # Draw icon in graphics mode
for i, bits in enumerate(icon): for i, bits in enumerate(icon):
self.write_graphics(x, y, i, [(bits >> 8) & 0xff, bits & 0xff]) self.write_graphics(x, y, i, [(bits >> 8) & 0xff, bits & 0xff])
return 2
char = TextGlyphs.get(glyph_name)
if char is not None:
# Draw character
self.write_text(x, y, char)
return 1
return 0
def clear(self): def clear(self):
zeros = bytearray(128) zeros = bytearray(128)
for page in self.vram[self.CURRENT_BUF]: for page in self.vram[self.CURRENT_BUF]: