RaspiQRP/main.py

30 lines
676 B
Python
Raw Normal View History

2022-07-20 17:22:05 +03:00
#!/usr/bin/env python
import pigpio
import time
import datetime
2022-07-20 17:29:35 +03:00
import asyncio
from functools import wraps, partial
2022-07-20 17:02:17 +03:00
2022-07-20 17:29:35 +03:00
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)
2022-07-20 17:02:17 +03:00
2022-07-20 17:29:35 +03:00
@async_wrap
def button_press(gpio:int, level) -> bool:
while True:
2022-07-20 17:22:05 +03:00
if(pi.read(gpio)==0):
2022-07-20 17:29:35 +03:00
return True
2022-07-20 17:02:17 +03:00
2022-07-20 17:29:35 +03:00
if __name__ == "__main__":
asyncio.run(button_press())