RaspiQRP/main_classes.py

63 lines
1.7 KiB
Python
Raw Normal View History

2022-07-25 23:11:33 +03:00
#!/usr/bin/env python
import pigpio
import time
import datetime
import asyncio
import os
from itertools import cycle
PTT_IS_ON:bool = False
MODULATION:str = None
FREQUENCY:float = float(430)
modulations = cycle(["./modulations/ssb.sh", "./modulations/fmrds.sh"])
pi = pigpio.pi() # init GPIO
async def run_command(*args):
process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
print("Started: %s, pid=%s" % (args, process.pid), flush=True)
class GPIO:
def __init__(self, pin:int, level, led):
self.pin = pin
pi.set_mode(pin, pigpio.INPUT)
self.level = level
self.led = led
async def is_clicked(self) -> bool:
if(pi.read(self.pin)!=0):
clicked = True
self.led = "ON"
if(pi.read(self.pin)==0):
clicked = False
await asyncio.sleep(.5)
return clicked
async def frequency(gpio):
# TODO write this function after hooking up the encoder
pass
async def main(freq:float):
task_created = False
print("Ready")
while True:
ptt = await GPIO(10, pigpio.EITHER_EDGE, 13).is_clicked() # 13 is not an actual pin #
# TODO: if works, do the modulation change trigger
if (ptt and not task_created):
asyncio.create_task(run_command(MODULATION, str(freq)))
task_created = True
elif (task_created and not ptt):
await asyncio.sleep(1)
asyncio.create_task(run_command("./kill.sh"))
task_created = False
await asyncio.sleep(.5)
if __name__ == "__main__":
try:
asyncio.run(main("", 430))
except KeyboardInterrupt:
print("\n")