30 lines
676 B
Python
30 lines
676 B
Python
#!/usr/bin/env python
|
|
import pigpio
|
|
import time
|
|
import datetime
|
|
import asyncio
|
|
from functools import wraps, partial
|
|
|
|
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:
|
|
while True:
|
|
if(pi.read(gpio)==0):
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(button_press()) |