stuff
This commit is contained in:
parent
b0b4012973
commit
6e3bb75aeb
4 changed files with 47 additions and 8 deletions
12
button.py
Normal file
12
button.py
Normal file
|
|
@ -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)
|
||||||
19
display.py
19
display.py
|
|
@ -1,18 +1,23 @@
|
||||||
|
import asyncio
|
||||||
from LCD import LCD
|
from LCD import LCD
|
||||||
|
|
||||||
class display:
|
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.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.device = LCD(2, i2c_addr, True)
|
self.device = LCD(2, i2c_addr, True)
|
||||||
self.contents = [""] * self.height
|
self.contents = [""] * self.height
|
||||||
|
|
||||||
def redraw(self):
|
async def redraw(self, row = None):
|
||||||
|
if row == None:
|
||||||
for row, line in enumerate(self.contents):
|
for row, line in enumerate(self.contents):
|
||||||
self.device.message(row + 1, line)
|
await self.device.async_message(row + 1, line)
|
||||||
|
else:
|
||||||
|
await self.device.async_message(row + 1, line)
|
||||||
|
|
||||||
def read(self):
|
async def read(self, row):
|
||||||
pass
|
return self.contents[row]
|
||||||
|
|
||||||
def write(self):
|
async def write(self, row, data, offset = 0):
|
||||||
pass
|
self.contents[row] = f'{self.contents[row][:offset]}{data}{self.contents[row][offset+len(data):]}'
|
||||||
|
self.redraw(row)
|
||||||
|
|
@ -1,4 +1,26 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from button import button
|
||||||
from decoder import decoder
|
from decoder import decoder
|
||||||
from display import display
|
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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue