fancontrol/fancontrol2.py
2026-10-08 20:09:34 +00:00

55 lines
1.7 KiB
Python

import asyncio
import asyncpio
import animation
from button import button
from decoder import decoder
from display import display
def wheel_handler(dir):
print(f"wheel: {dir}")
loop = asyncio.get_event_loop()
loop.create_task(disp.write(1, f"wheel: {dir}"))
# async def coffee_test():
# drink_char = disp.alloc_cchar()
# hand_char = disp.alloc_cchar()
# disp.device.set_char(0, [0x00,0x00,0x00,0x0F,0x01,0x01,0x00,0x00])
# drink = animation.animator(disp.device, 1, animation.DRINK, 0.4)
# await disp.write(1, f"[{chr(0x00)}{chr(0b10100101)}-{chr(0b11011111)}]{chr(0x00)} c[{chr(0x01)}]")
# await drink.start()
async def coffee_test():
coffee = animation.scene(disp, "[CCHAR0{chr(0b10100101)}-{chr(0b11011111)}]CCHAR0 c[CCHAR1]", [animation.HAND, animation.DRINK], [1.5, 0.4])
await coffee.action()
def button_test(*args):
print(args)
loop = asyncio.get_event_loop()
loop.create_task(disp.write(2, args))
async def tcpu_monitor():
loop = asyncio.get_event_loop()
while True:
with open("/sys/class/thermal/thermal_zone0/temp") as temp:
loop.create_task(disp.write(4, f"{int(temp.read())/1000:4.1f}{chr(0b11011111)}C", 14))
await asyncio.sleep(1)
async def main():
pi = asyncpio.pi()
dec = decoder(pi, 27, 17, wheel_handler)
b1 = button(pi, 23, button_test)
b2 = button(pi, 24, button_test)
await pi.connect()
await dec.start()
await b1.start()
await b2.start()
if __name__ == "__main__":
disp = display()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.create_task(main())
loop.create_task(tcpu_monitor())
loop.create_task(coffee_test())
loop.run_forever()