Compare commits
2 Commits
dbf1900f56
...
69dfa4bbe8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
69dfa4bbe8 | ||
![]() |
d29f17b57b |
2
kill.sh
2
kill.sh
@ -1,2 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
killall ssh.sh
|
sudo killall rpitx pifmrds
|
||||||
|
67
main.py
67
main.py
@ -5,7 +5,12 @@ import datetime
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
|
|
||||||
PTT_IS_ON = 0
|
PTT_IS_ON = False
|
||||||
|
modulations = {
|
||||||
|
"ssb":"./modulations/ssb.sh",
|
||||||
|
"fmrds":"./modulations/fmrds.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# init GPIO
|
# init GPIO
|
||||||
pi = pigpio.pi()
|
pi = pigpio.pi()
|
||||||
@ -13,62 +18,36 @@ pi = pigpio.pi()
|
|||||||
pi.set_mode(10, pigpio.INPUT)
|
pi.set_mode(10, pigpio.INPUT)
|
||||||
|
|
||||||
async def run_command(*args):
|
async def run_command(*args):
|
||||||
"""Run command in subprocess.
|
process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||||
|
|
||||||
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)
|
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:
|
async def button_press(gpio:int, level) -> bool:
|
||||||
global PTT_IS_ON
|
global PTT_IS_ON
|
||||||
while True:
|
while True:
|
||||||
if(pi.read(gpio)!=0):
|
if(pi.read(gpio)!=0):
|
||||||
PTT_IS_ON = 1
|
PTT_IS_ON = True
|
||||||
if(pi.read(gpio)==0):
|
if(pi.read(gpio)==0):
|
||||||
PTT_IS_ON = 0
|
PTT_IS_ON = False
|
||||||
await asyncio.sleep(.5)
|
await asyncio.sleep(.5)
|
||||||
|
|
||||||
async def main():
|
async def main(mod, freq:float):
|
||||||
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
|
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
|
||||||
global PTT_IS_ON
|
global PTT_IS_ON
|
||||||
|
task_created = False
|
||||||
|
print("Ready")
|
||||||
while True:
|
while True:
|
||||||
if PTT_IS_ON == 1:
|
if (PTT_IS_ON and not task_created):
|
||||||
while PTT_IS_ON == 1:
|
asyncio.create_task(run_command(modulations[mod], str(freq)))
|
||||||
await run_command("./ssb.sh")
|
task_created = True
|
||||||
else:
|
elif (task_created and not PTT_IS_ON):
|
||||||
await run_command("./kill.sh")
|
await asyncio.sleep(1)
|
||||||
|
asyncio.create_task(run_command("./kill.sh"))
|
||||||
|
task_created = False
|
||||||
await asyncio.sleep(.5)
|
await asyncio.sleep(.5)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
try:
|
||||||
|
asyncio.run(main("fmrds", 430))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n")
|
||||||
|
2
modulations/fmrds.sh
Executable file
2
modulations/fmrds.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
arecord -q -c2 -t wav -f cd | sudo ./modulations/pifmrds -freq "$1" -audio -
|
BIN
modulations/pifmrds
Executable file
BIN
modulations/pifmrds
Executable file
Binary file not shown.
@ -1,37 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
echo $1
|
||||||
# Pin logic
|
echo $2
|
||||||
#selecting pin
|
#arecord -q -c2 -t wav -f dat | sudo rpitx -f $1 -i- - -m $2 -s 48000
|
||||||
|
|
||||||
GPIO=19
|
arecord -q -c2 -t wav -f dat | sudo rpitx -i - -m RF -f "$1" -s 48000
|
||||||
|
|
||||||
# "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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# old line
|
# | 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
|
||||||
#(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