aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-06-10 20:58:45 -0400
committerKevin O'Connor <kevin@koconnor.net>2020-06-11 00:18:23 -0400
commit9465618adb0ad5c93209f661c0cb3c3c38926ba8 (patch)
tree9396f784d05b41735b309039eb2d2f2c354eaac6
parent467e8e6f40445005cc1da4fb3a7ec1ad0ed45479 (diff)
downloadkutter-9465618adb0ad5c93209f661c0cb3c3c38926ba8.tar.gz
kutter-9465618adb0ad5c93209f661c0cb3c3c38926ba8.tar.xz
kutter-9465618adb0ad5c93209f661c0cb3c3c38926ba8.zip
display: Rework write_graphics() to take one character cell at a time
Change write_graphics() from taking one pixel row of n characters to taking all the rows and columns for one character cell. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/extras/display/display.py23
-rw-r--r--klippy/extras/display/hd44780.py2
-rw-r--r--klippy/extras/display/st7920.py44
-rw-r--r--klippy/extras/display/uc1701.py33
4 files changed, 46 insertions, 56 deletions
diff --git a/klippy/extras/display/display.py b/klippy/extras/display/display.py
index 7115877e..fdeb3e4c 100644
--- a/klippy/extras/display/display.py
+++ b/klippy/extras/display/display.py
@@ -168,7 +168,9 @@ class PrinterLCD:
data = dg.get('data', None)
if data is not None:
idata = self._parse_glyph(config, glyph_name, data, 16, 16)
- icons.setdefault(glyph_name, {})['icon16x16'] = idata
+ icon1 = [(bits >> 8) & 0xff for bits in idata]
+ icon2 = [bits & 0xff for bits in idata]
+ icons.setdefault(glyph_name, {})['icon16x16'] = (icon1, icon2)
data = dg.get('hd44780_data', None)
if data is not None:
slot = dg.getint('hd44780_slot', minval=0, maxval=7)
@@ -206,22 +208,11 @@ class PrinterLCD:
# write glyph
pos += self.lcd_chip.write_glyph(pos, row, text)
def draw_progress_bar(self, row, col, width, value):
- value = int(value * 100.)
- data = [0x00] * width
- char_pcnt = int(100/width)
+ pixels = -1 << int(width * 8 * (1. - value) + .5)
+ pixels |= (1 << (width * 8 - 1)) | 1
for i in range(width):
- if (i+1)*char_pcnt <= value:
- # Draw completely filled bytes
- data[i] |= 0xFF
- elif (i*char_pcnt) < value:
- # Draw partially filled bytes
- data[i] |= (-1 << 8-((value % char_pcnt)*8/char_pcnt)) & 0xff
- data[0] |= 0x80
- data[-1] |= 0x01
- self.lcd_chip.write_graphics(col, row, 0, [0xff]*width)
- for i in range(1, 15):
- self.lcd_chip.write_graphics(col, row, i, data)
- self.lcd_chip.write_graphics(col, row, 15, [0xff]*width)
+ data = [0xff] + [(pixels >> (i * 8)) & 0xff] * 14 + [0xff]
+ self.lcd_chip.write_graphics(col + width - 1 - i, row, data)
return ""
cmd_SET_DISPLAY_GROUP_help = "Set the active display group"
def cmd_SET_DISPLAY_GROUP(self, gcmd):
diff --git a/klippy/extras/display/hd44780.py b/klippy/extras/display/hd44780.py
index 8ef4102c..7c2477cb 100644
--- a/klippy/extras/display/hd44780.py
+++ b/klippy/extras/display/hd44780.py
@@ -112,7 +112,7 @@ class HD44780:
self.write_text(x, y, char)
return 1
return 0
- def write_graphics(self, x, y, pixel_row, pixel_col):
+ def write_graphics(self, x, y, data):
pass
def clear(self):
spaces = ' ' * 40
diff --git a/klippy/extras/display/st7920.py b/klippy/extras/display/st7920.py
index e368d869..19828943 100644
--- a/klippy/extras/display/st7920.py
+++ b/klippy/extras/display/st7920.py
@@ -115,34 +115,35 @@ class ST7920:
base_icon = self.icons.get(base_glyph_name)
if icon is None or base_icon is None:
return
- for i, (bits, base_bits) in enumerate(zip(icon, base_icon)):
+ all_bits = zip(icon[0], icon[1], base_icon[0], base_icon[1])
+ for i, (ic1, ic2, b1, b2) in enumerate(all_bits):
+ x1, x2 = ic1 ^ b1, ic2 ^ b2
pos = glyph_id*32 + i*2
- b1, b2 = (bits >> 8) & 0xff, bits & 0xff
- b1, b2 = b1 ^ (base_bits >> 8) & 0xff, b2 ^ base_bits & 0xff
- self.glyph_framebuffer[pos:pos+2] = [b1, b2]
- self.all_framebuffers[1][1][pos:pos+2] = [b1 ^ 1, b2 ^ 1]
+ self.glyph_framebuffer[pos:pos+2] = [x1, x2]
+ self.all_framebuffers[1][1][pos:pos+2] = [x1 ^ 1, x2 ^ 1]
self.cached_glyphs[glyph_name] = (base_glyph_name, (0, glyph_id*2))
+ def set_glyphs(self, glyphs):
+ for glyph_name, glyph_data in glyphs.items():
+ icon = glyph_data.get('icon16x16')
+ if icon is not None:
+ self.icons[glyph_name] = icon
+ # Setup animated glyphs
+ self.cache_glyph('fan2', 'fan1', 0)
+ self.cache_glyph('bed_heat2', 'bed_heat1', 1)
def write_text(self, x, y, data):
if x + len(data) > 16:
data = data[:16 - min(x, 16)]
pos = [0, 32, 16, 48][y] + x
self.text_framebuffer[pos:pos+len(data)] = data
- def write_graphics(self, x, y, row, data):
- if x + len(data) > 16:
- data = data[:16 - min(x, 16)]
- gfx_fb = y * 16 + row
+ def write_graphics(self, x, y, data):
+ if x >= 16 or y >= 4 or len(data) != 16:
+ return
+ gfx_fb = y * 16
if gfx_fb >= 32:
gfx_fb -= 32
x += 16
- self.graphics_framebuffers[gfx_fb][x:x+len(data)] = data
- def set_glyphs(self, glyphs):
- for glyph_name, glyph_data in glyphs.items():
- data = glyph_data.get('icon16x16')
- if data is not None:
- self.icons[glyph_name] = data
- # Setup animated glyphs
- self.cache_glyph('fan2', 'fan1', 0)
- self.cache_glyph('bed_heat2', 'bed_heat1', 1)
+ for i, bits in enumerate(data):
+ self.graphics_framebuffers[gfx_fb + i][x] = bits
def write_glyph(self, x, y, glyph_name):
glyph_id = self.cached_glyphs.get(glyph_name)
if glyph_id is not None and x & 1 == 0:
@@ -152,8 +153,8 @@ class ST7920:
icon = self.icons.get(glyph_name)
if icon is not None:
# Draw icon in graphics mode
- for i, bits in enumerate(icon):
- self.write_graphics(x, y, i, [(bits >> 8) & 0xff, bits & 0xff])
+ self.write_graphics(x, y, icon[0])
+ self.write_graphics(x + 1, y, icon[1])
return 2
char = TextGlyphs.get(glyph_name)
if char is not None:
@@ -163,8 +164,7 @@ class ST7920:
font = CharGlyphs.get(glyph_name)
if font is not None:
# Draw single width character
- for i, bits in enumerate(font):
- self.write_graphics(x, y, i, [bits])
+ self.write_graphics(x, y, font)
return 1
return 0
def clear(self):
diff --git a/klippy/extras/display/uc1701.py b/klippy/extras/display/uc1701.py
index 8f9d1d53..cb6e3763 100644
--- a/klippy/extras/display/uc1701.py
+++ b/klippy/extras/display/uc1701.py
@@ -57,6 +57,13 @@ class DisplayBase:
bits_top[col] |= ((data[row] >> (7 - col)) & 1) << row
bits_bot[col] |= ((data[row + 8] >> (7 - col)) & 1) << row
return (bits_top, bits_bot)
+ def set_glyphs(self, glyphs):
+ for glyph_name, glyph_data in glyphs.items():
+ icon = glyph_data.get('icon16x16')
+ if icon is not None:
+ top1, bot1 = self._swizzle_bits(icon[0])
+ top2, bot2 = self._swizzle_bits(icon[1])
+ self.icons[glyph_name] = (top1 + top2, bot1 + bot2)
def write_text(self, x, y, data):
if x + len(data) > 16:
data = data[:16 - min(x, 16)]
@@ -68,24 +75,16 @@ class DisplayBase:
page_top[pix_x:pix_x+8] = bits_top
page_bot[pix_x:pix_x+8] = bits_bot
pix_x += 8
- def write_graphics(self, x, y, row, data):
- if x + len(data) > 16:
- data = data[:16 - min(x, 16)]
- page = self.vram[y * 2 + (row >= 8)]
- bit = 1 << (row % 8)
+ def write_graphics(self, x, y, data):
+ if x >= 16 or y >= 4 or len(data) != 16:
+ return
+ bits_top, bits_bot = self._swizzle_bits(data)
pix_x = x * 8
- for bits in data:
- for col in range(8):
- if (bits << col) & 0x80:
- page[pix_x] ^= bit
- pix_x += 1
- def set_glyphs(self, glyphs):
- for glyph_name, glyph_data in glyphs.items():
- data = glyph_data.get('icon16x16')
- if data is not None:
- top1, bot1 = self._swizzle_bits([d >> 8 for d in data])
- top2, bot2 = self._swizzle_bits(data)
- self.icons[glyph_name] = (top1 + top2, bot1 + bot2)
+ page_top = self.vram[y * 2]
+ page_bot = self.vram[y * 2 + 1]
+ for i in range(8):
+ page_top[pix_x + i] ^= bits_top[i]
+ page_bot[pix_x + i] ^= bits_bot[i]
def write_glyph(self, x, y, glyph_name):
icon = self.icons.get(glyph_name)
if icon is not None and x < 15: