test
This commit is contained in:
parent
1bbe4f4086
commit
815221a3d2
26
main.py
26
main.py
@ -2,8 +2,16 @@
|
|||||||
import pigpio
|
import pigpio
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import asyncio
|
from multiprocessing import Process
|
||||||
from functools import wraps, partial
|
|
||||||
|
def run_in_parallel(*fns):
|
||||||
|
proc = []
|
||||||
|
for fn in fns:
|
||||||
|
p = Process(target=fn)
|
||||||
|
p.start()
|
||||||
|
proc.append(p)
|
||||||
|
for p in proc:
|
||||||
|
p.join()
|
||||||
|
|
||||||
PTT_IS_ON = 0
|
PTT_IS_ON = 0
|
||||||
|
|
||||||
@ -12,22 +20,18 @@ pi = pigpio.pi()
|
|||||||
# button pin
|
# button pin
|
||||||
pi.set_mode(10, pigpio.INPUT)
|
pi.set_mode(10, pigpio.INPUT)
|
||||||
|
|
||||||
async def button_press(gpio:int, level) -> bool:
|
def button_press(gpio:int, level) -> bool:
|
||||||
while True:
|
while True:
|
||||||
print("a")
|
|
||||||
if(pi.read(gpio)!=0):
|
if(pi.read(gpio)!=0):
|
||||||
PTT_IS_ON = 1
|
PTT_IS_ON = 1
|
||||||
if(pi.read(gpio)==0):
|
if(pi.read(gpio)==0):
|
||||||
PTT_IS_ON = 0
|
PTT_IS_ON = 0
|
||||||
asyncio.sleep(.5)
|
time.sleep(.5)
|
||||||
|
|
||||||
async def ptt():
|
def ptt():
|
||||||
while True:
|
while True:
|
||||||
print("b")
|
|
||||||
if PTT_IS_ON == 1:
|
if PTT_IS_ON == 1:
|
||||||
print("HEEEEEE")
|
print("HEEEEEE")
|
||||||
|
time.sleep(.5)
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
loop = asyncio.get_event_loop()
|
run_in_parallel(button_press(10, pigpio.EITHER_EDGE), ptt())
|
||||||
tasks = asyncio.gather(button_press(10, pigpio.EITHER_EDGE), ptt())
|
|
||||||
asyncio.get_event_loop().run_until_complete(tasks)
|
|
Loading…
x
Reference in New Issue
Block a user