fancontrol/animation.py
2026-10-05 21:28:58 +00:00

159 lines
No EOL
2.8 KiB
Python

import asyncio
# animated tile set
# fan, four frames
FAN = [
[0b00000,
0b00100,
0b00100,
0b11111,
0b00100,
0b00100,
0b00000,
0b00000],
[0b00000,
0b00010,
0b11010,
0b00100,
0b01011,
0b01000,
0b00000,
0b00000],
[0b00000,
0b10001,
0b01010,
0b00100,
0b01010,
0b10001,
0b00000,
0b00000],
[0b00000,
0b01000,
0b01011,
0b00100,
0b11010,
0b00010,
0b00000,
0b00000]
]
# different fan, four frames
FAN2 = [
[0x01,
0x01,
0x1D,
0x12,
0x1D,
0x11,
0x11,
0x10],
[0x00,
0x01,
0x1D,
0x12,
0x1D,
0x11,
0x10,
0x10],
[0x00,
0x00,
0x1D,
0x12,
0x1D,
0x10,
0x10,
0x10],
[0x00,
0x01,
0x1D,
0x12,
0x1D,
0x11,
0x10,
0x10]
]
# wind, three frames
WIND = [
[0b01101,
0b10010,
0b00000,
0b01101,
0b10010,
0b00000,
0b01101,
0b10010],
[0b10110,
0b01001,
0b00000,
0b10110,
0b01001,
0b00000,
0b10110,
0b01001],
[0b11011,
0b00100,
0b00000,
0b11011,
0b00100,
0b00000,
0b11011,
0b00100]
]
# sparkling or steaming beverage, 4 frames
DRINK = [[2, 0, 8, 31, 31, 31, 31, 0],
[0, 8, 0, 31, 31, 31, 31, 0],
[8, 0, 2, 31, 31, 31, 31, 0],
[0, 2, 0, 31, 31, 31, 31, 0]]
# hand, two frames
HAND = [[0x00,0x00,0x00,0x0F,0x01,0x01,0x00,0x00],
[0x00,0x00,0x0F,0x01,0x01,0x00,0x00, 0x00]]
class cchar:
def __init__(self, disp, slides, delay):
self.disp = disp
self.slot = self.disp.alloc_cchar()
self.slides = slides
self.delay = delay
self.running = False
async def start(self):
self.running = True
while self.running:
for slide in self.slides:
await self.disp.device.async_set_char(self.slot, slide)
await asyncio.sleep(self.delay)
async def pause(self):
self.running = False
async def stop(self):
self.pause()
self.disp.free_cchar(self.slot)
class scene:
def __init__(self, disp, act, cchars = None, delays = None):
self.disp = disp
self.allocs = []
for idx, custom_char in enumerate(cchars):
self.allocs.append(cchar(disp, custom_char, delays[idx]))
act = act.replace(f"CCHAR{idx}", chr(idx))
self.act = act
self.line = None
async def action(self, row, offset = 0):
self.line = row
self.disp.write(self.line, self.act, offset)
async def cut(self):
self.disp.write(self.line, " " * self.disp.width)
async def wrap(self):
for alloc in self.allocs:
alloc.stop()