first commit from raspi
This commit is contained in:
parent
c3df43733b
commit
5b1415e471
14
main.py
14
main.py
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user