#!/bin/sh

# Pin logic
#selecting pin

GPIO=26

# "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
#(while true; do cat sampleaudio.wav; done)

while true; do
  	if [ 1 == "$(</sys/class/gpio/gpio"${GPIO}"/value)" ]; then

		# REMOVE THIS
		echo "Not pressed"

  	else

# 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
	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"