aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-10-04 13:46:28 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-10-04 13:49:00 -0400
commit97927172f15c96dc941743f559575ca5ddcf55e1 (patch)
tree0b73f46697e88d9022c850b062e71f3402433ca9 /klippy
parent630989c0fe286bc82360e246a29979c2a15b42d6 (diff)
downloadkutter-97927172f15c96dc941743f559575ca5ddcf55e1.tar.gz
kutter-97927172f15c96dc941743f559575ca5ddcf55e1.tar.xz
kutter-97927172f15c96dc941743f559575ca5ddcf55e1.zip
st7920: Use display xor capability when animating glyphs
Use the xor capability of the display to animate the glyphs, which reduces the number of glyphs needed from 4 to 2. This should make it easier to add future animations if desired. Suggested by @marcio-ao. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/extras/display/st7920.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/klippy/extras/display/st7920.py b/klippy/extras/display/st7920.py
index 9d575218..1c725ab5 100644
--- a/klippy/extras/display/st7920.py
+++ b/klippy/extras/display/st7920.py
@@ -109,19 +109,19 @@ class ST7920:
0x0c] # Enable display and hide cursor
self.send(cmds)
# Setup animated glyphs
- self.cache_glyph('fan1', 0)
- self.cache_glyph('fan2', 1)
- self.cache_glyph('bed_heat1', 2)
- self.cache_glyph('bed_heat2', 3)
+ self.cache_glyph('fan2', 'fan1', 0)
+ self.cache_glyph('bed_heat2', 'bed_heat1', 1)
self.flush()
- def cache_glyph(self, glyph_name, glyph_id):
+ def cache_glyph(self, glyph_name, base_glyph_name, glyph_id):
icon = icons.Icons16x16[glyph_name]
- for i, bits in enumerate(icon):
+ base_icon = icons.Icons16x16[base_glyph_name]
+ for i, (bits, base_bits) in enumerate(zip(icon, base_icon)):
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.cached_glyphs[glyph_name] = (0, glyph_id*2)
+ self.cached_glyphs[glyph_name] = (base_glyph_name, (0, glyph_id*2))
def write_text(self, x, y, data):
if x + len(data) > 16:
data = data[:16 - min(x, 16)]
@@ -139,8 +139,8 @@ class ST7920:
glyph_id = self.cached_glyphs.get(glyph_name)
if glyph_id is not None and x & 1 == 0:
# Render cached icon using character generator
- self.write_text(x, y, glyph_id)
- return 2
+ glyph_name = glyph_id[0]
+ self.write_text(x, y, glyph_id[1])
icon = icons.Icons16x16.get(glyph_name)
if icon is not None:
# Draw icon in graphics mode