From 6e3bb75aebfd4713b9a2f7fb3e736bf6d8b570d4 Mon Sep 17 00:00:00 2001 From: Benjamin Tayehanpour Date: Sat, 26 Sep 2026 20:29:12 +0000 Subject: [PATCH] stuff --- kladd/asyncpio.py => asyncpio.py | 0 button.py | 12 ++++++++++++ display.py | 21 +++++++++++++-------- fancontrol.py | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) rename kladd/asyncpio.py => asyncpio.py (100%) create mode 100644 button.py diff --git a/kladd/asyncpio.py b/asyncpio.py similarity index 100% rename from kladd/asyncpio.py rename to asyncpio.py diff --git a/button.py b/button.py new file mode 100644 index 0000000..d45064d --- /dev/null +++ b/button.py @@ -0,0 +1,12 @@ +import asyncio +import asyncpio + +class button: + def __init__(self, pi, gpio, callback): + self.pi = pi + self.gpio = gpio + self.callback = callback + async def start(self): + await self.pi.set_mode(self.gpio, asyncpio.INPUT) + await self.pi.set_pull_up_down(self.gpio, asyncpio.PUD_UP) + self.cb = await self.pi.callback(self.gpio, asyncpio.EITHER_EDGE, self.callback) \ No newline at end of file diff --git a/display.py b/display.py index f01ffb3..ca56439 100644 --- a/display.py +++ b/display.py @@ -1,18 +1,23 @@ +import asyncio from LCD import LCD class display: - def __init__(self, width=16, height=4, i2c_addr=0x27): + async def __init__(self, width=20, height=4, i2c_addr=0x27): self.width = width self.height = height self.device = LCD(2, i2c_addr, True) self.contents = [""] * self.height - def redraw(self): - for row, line in enumerate(self.contents): - self.device.message(row + 1, line) + async def redraw(self, row = None): + if row == None: + for row, line in enumerate(self.contents): + await self.device.async_message(row + 1, line) + else: + await self.device.async_message(row + 1, line) - def read(self): - pass + async def read(self, row): + return self.contents[row] - def write(self): - pass \ No newline at end of file + async def write(self, row, data, offset = 0): + self.contents[row] = f'{self.contents[row][:offset]}{data}{self.contents[row][offset+len(data):]}' + self.redraw(row) \ No newline at end of file diff --git a/fancontrol.py b/fancontrol.py index 0736881..af7fed1 100644 --- a/fancontrol.py +++ b/fancontrol.py @@ -1,4 +1,26 @@ import asyncio +from button import button from decoder import decoder from display import display +async def wheel_handler(dir): + print(f"wheel: {dir}") + +async def button_test(**args): + print(args) + +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.get_event_loop() + loop.create_task(main()) + loop.run_forever() \ No newline at end of file