almost got the PTT working
This commit is contained in:
parent
a367c27c92
commit
dbf1900f56
54
main.py
54
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())
|
||||
asyncio.run(main())
|
@ -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 == "$(</sys/class/gpio/gpio"${GPIO}"/value)" ]; then
|
||||
if 1 == "$(</sys/class/gpio/gpio"${GPIO}"/value)" ]; then
|
||||
arecord -q -f cd -r 44100 -c2 -D hw:0,7 -t raw | csdr convert_i16_f \ | csdr fir_interpolate_cc 2 | csdr dsb_fc \ | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff \ | sudo sendiq -i /dev/stdin -s 96000 -f "$1" -t float
|
||||
|
||||
# REMOVE THIS
|
||||
echo "Not pressed"
|
||||
|
||||
else
|
||||
echo "Not pressed"
|
||||
|
||||
# do arecord -l or arecord -L to find your audio card and change hw:0,7 to the corresponding value
|
||||
arecord -q -f cd -r 44100 -c2 -D hw:0,7 -t raw | csdr convert_i16_f \ | csdr fir_interpolate_cc 2 | csdr dsb_fc \ | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff \ | sudo ./sendiq -i /dev/stdin -s 96000 -f "$1" -t float
|
||||
# maybe i just need to extract this command and put it in a subprocess... 🤔
|
||||
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user