first commit from raspi

This commit is contained in:
PiFestim 2022-07-20 15:41:07 +01:00
parent c3df43733b
commit 5b1415e471

14
main.py
View File

@ -6,28 +6,20 @@ import asyncio
from functools import wraps, partial
PTT_IS_ON = 0
def async_wrap(func):
@wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
loop = asyncio.get_event_loop()
pfunc = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, pfunc)
return run
# init GPIO
pi = pigpio.pi()
# button pin
pi.set_mode(10, pigpio.INPUT)
@async_wrap
def button_press(gpio:int, level) -> bool:
async def button_press(gpio:int, level) -> bool:
while True:
if(pi.read(gpio)!=0):
PTT_IS_ON = 1
if(pi.read(gpio)==0):
PTT_IS_ON = 0
asyncio.sleep(.5)
if __name__ == "__main__":
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
while True: