Compare commits
No commits in common. "69dfa4bbe8803a1cb085f492274c594ef744bd79" and "dbf1900f56f88fb9ca3a33441da8e81b7f080a8c" have entirely different histories.
69dfa4bbe8
...
dbf1900f56
67
main.py
67
main.py
@ -5,12 +5,7 @@ import datetime
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
PTT_IS_ON = False
|
||||
modulations = {
|
||||
"ssb":"./modulations/ssb.sh",
|
||||
"fmrds":"./modulations/fmrds.sh"
|
||||
}
|
||||
|
||||
PTT_IS_ON = 0
|
||||
|
||||
# init GPIO
|
||||
pi = pigpio.pi()
|
||||
@ -18,36 +13,62 @@ pi = pigpio.pi()
|
||||
pi.set_mode(10, pigpio.INPUT)
|
||||
|
||||
async def run_command(*args):
|
||||
process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||
"""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:
|
||||
if(pi.read(gpio)!=0):
|
||||
PTT_IS_ON = True
|
||||
PTT_IS_ON = 1
|
||||
if(pi.read(gpio)==0):
|
||||
PTT_IS_ON = False
|
||||
PTT_IS_ON = 0
|
||||
await asyncio.sleep(.5)
|
||||
|
||||
async def main(mod, freq:float):
|
||||
async def main():
|
||||
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
|
||||
global PTT_IS_ON
|
||||
task_created = False
|
||||
print("Ready")
|
||||
while True:
|
||||
if (PTT_IS_ON and not task_created):
|
||||
asyncio.create_task(run_command(modulations[mod], str(freq)))
|
||||
task_created = True
|
||||
elif (task_created and not PTT_IS_ON):
|
||||
await asyncio.sleep(1)
|
||||
asyncio.create_task(run_command("./kill.sh"))
|
||||
task_created = False
|
||||
if PTT_IS_ON == 1:
|
||||
while PTT_IS_ON == 1:
|
||||
await run_command("./ssb.sh")
|
||||
else:
|
||||
await run_command("./kill.sh")
|
||||
await asyncio.sleep(.5)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
asyncio.run(main("fmrds", 430))
|
||||
except KeyboardInterrupt:
|
||||
print("\n")
|
||||
asyncio.run(main())
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
arecord -q -c2 -t wav -f cd | sudo ./modulations/pifmrds -freq "$1" -audio -
|
Binary file not shown.
@ -1,11 +1,37 @@
|
||||
#!/bin/bash
|
||||
echo $1
|
||||
echo $2
|
||||
#arecord -q -c2 -t wav -f dat | sudo rpitx -f $1 -i- - -m $2 -s 48000
|
||||
|
||||
arecord -q -c2 -t wav -f dat | sudo rpitx -i - -m RF -f "$1" -s 48000
|
||||
#!/bin/sh
|
||||
|
||||
# Pin logic
|
||||
#selecting pin
|
||||
|
||||
GPIO=19
|
||||
|
||||
# "Prepare" it, whatever that means, I just copied it from SO
|
||||
if [ ! -d /sys/class/gpio/gpio${GPIO} ]; then
|
||||
echo "${GPIO}" > /sys/class/gpio/export
|
||||
fi
|
||||
echo "in" > /sys/class/gpio/gpio"${GPIO}"/direction
|
||||
|
||||
|
||||
|
||||
# | 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 430000000 -t float e6 -l
|
||||
# old line
|
||||
#(while true; do cat sampleaudio.wav; done)
|
||||
|
||||
while true; do
|
||||
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
|
||||
|
||||
else
|
||||
echo "Not pressed"
|
||||
|
||||
# do arecord -l or arecord -L to find your audio card and change hw:0,7 to the corresponding value
|
||||
# maybe i just need to extract this command and put it in a subprocess... 🤔
|
||||
|
||||
fi
|
||||
sleep .5
|
||||
done
|
||||
|
||||
# this should work
|
||||
# screen will probably be operated using python, so all we need to do there is to killall ssb.sh, then run a new one with new freq async subproc
|
||||
# usage: bash ssb.sh "freq"
|
Loading…
x
Reference in New Issue
Block a user