diff --git a/kill.sh b/kill.sh new file mode 100755 index 0000000..d4c29e7 --- /dev/null +++ b/kill.sh @@ -0,0 +1,2 @@ +#!/bin/bash +killall ssh.sh \ No newline at end of file diff --git a/main.py b/main.py index 1de6545..5b6cfe0 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import pigpio import time import datetime import asyncio +import os PTT_IS_ON = 0 @@ -11,20 +12,63 @@ pi = pigpio.pi() # button pin pi.set_mode(10, pigpio.INPUT) +async def run_command(*args): + """Run command in subprocess. + + Example from: + http://asyncio.readthedocs.io/en/latest/subprocess.html + """ + # Create subprocess + process = await asyncio.create_subprocess_exec( + *args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE + ) + + # Status + print("Started: %s, pid=%s" % (args, process.pid), flush=True) + + # Wait for the subprocess to finish + stdout, stderr = asyncio.get_event_loop().create_task(process.communicate()) + + # Progress + if process.returncode == 0: + print( + "Done: %s, pid=%s, result: %s" + % (args, process.pid, stdout.decode().strip()), + flush=True, + ) + else: + print( + "Failed: %s, pid=%s, result: %s" + % (args, process.pid, stderr.decode().strip()), + flush=True, + ) + + # Result + result = stdout.decode().strip() + asyncio.sleep(5) + + # Return stdout + return result + async def button_press(gpio:int, level) -> bool: + global PTT_IS_ON while True: - print("a") if(pi.read(gpio)!=0): PTT_IS_ON = 1 if(pi.read(gpio)==0): PTT_IS_ON = 0 - asyncio.sleep(.5) + await asyncio.sleep(.5) -async def ptt(): +async def main(): asyncio.create_task(button_press(10, pigpio.EITHER_EDGE)) + global PTT_IS_ON while True: if PTT_IS_ON == 1: - print("HEEEEEE") + while PTT_IS_ON == 1: + await run_command("./ssb.sh") + else: + await run_command("./kill.sh") + await asyncio.sleep(.5) if __name__ == "__main__": - asyncio.run(ptt()) \ No newline at end of file + asyncio.run(main()) \ No newline at end of file diff --git a/modulations/ssb.sh b/modulations/ssb.sh index 4585869..49f9c7c 100755 --- a/modulations/ssb.sh +++ b/modulations/ssb.sh @@ -3,7 +3,7 @@ # Pin logic #selecting pin -GPIO=26 +GPIO=19 # "Prepare" it, whatever that means, I just copied it from SO if [ ! -d /sys/class/gpio/gpio${GPIO} ]; then @@ -17,15 +17,15 @@ echo "in" > /sys/class/gpio/gpio"${GPIO}"/direction #(while true; do cat sampleaudio.wav; done) while true; do - if [ 1 == "$(