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>
This commit is contained in:
parent
630989c0fe
commit
97927172f1
|
@ -109,19 +109,19 @@ class ST7920:
|
||||||
0x0c] # Enable display and hide cursor
|
0x0c] # Enable display and hide cursor
|
||||||
self.send(cmds)
|
self.send(cmds)
|
||||||
# Setup animated glyphs
|
# Setup animated glyphs
|
||||||
self.cache_glyph('fan1', 0)
|
self.cache_glyph('fan2', 'fan1', 0)
|
||||||
self.cache_glyph('fan2', 1)
|
self.cache_glyph('bed_heat2', 'bed_heat1', 1)
|
||||||
self.cache_glyph('bed_heat1', 2)
|
|
||||||
self.cache_glyph('bed_heat2', 3)
|
|
||||||
self.flush()
|
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]
|
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
|
pos = glyph_id*32 + i*2
|
||||||
b1, b2 = (bits >> 8) & 0xff, bits & 0xff
|
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.glyph_framebuffer[pos:pos+2] = [b1, b2]
|
||||||
self.all_framebuffers[1][1][pos:pos+2] = [b1 ^ 1, b2 ^ 1]
|
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):
|
def write_text(self, x, y, data):
|
||||||
if x + len(data) > 16:
|
if x + len(data) > 16:
|
||||||
data = data[:16 - min(x, 16)]
|
data = data[:16 - min(x, 16)]
|
||||||
|
@ -139,8 +139,8 @@ class ST7920:
|
||||||
glyph_id = self.cached_glyphs.get(glyph_name)
|
glyph_id = self.cached_glyphs.get(glyph_name)
|
||||||
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)
|
glyph_name = glyph_id[0]
|
||||||
return 2
|
self.write_text(x, y, glyph_id[1])
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue