From 8b4670e57c7a9931984a4076310076742a451788 Mon Sep 17 00:00:00 2001 From: Benjamin Tayehanpour Date: Thu, 8 Oct 2026 20:09:34 +0000 Subject: [PATCH] stuff --- fancontrol2.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 fancontrol2.py diff --git a/fancontrol2.py b/fancontrol2.py new file mode 100644 index 0000000..51b6a64 --- /dev/null +++ b/fancontrol2.py @@ -0,0 +1,55 @@ +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()