2022-07-20 17:22:05 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import pigpio
|
|
|
|
import time
|
|
|
|
import datetime
|
2022-07-20 19:28:27 +03:00
|
|
|
import asyncio
|
2022-07-20 19:03:17 +01:00
|
|
|
import os
|
2022-07-25 16:30:01 +03:00
|
|
|
from itertools import cycle
|
2022-07-20 19:22:13 +03:00
|
|
|
|
2022-07-25 16:30:01 +03:00
|
|
|
PTT_IS_ON:bool = False
|
|
|
|
MODULATION:str = None
|
|
|
|
FREQUENCY:float = float(430)
|
|
|
|
modulations = cycle(["./modulations/ssb.sh", "./modulations/fmrds.sh"])
|
2022-07-21 01:47:08 +01:00
|
|
|
|
2022-07-20 17:29:35 +03:00
|
|
|
|
|
|
|
# init GPIO
|
|
|
|
pi = pigpio.pi()
|
|
|
|
# button pin
|
|
|
|
pi.set_mode(10, pigpio.INPUT)
|
2022-07-25 16:30:01 +03:00
|
|
|
# modulation change pin(change this)
|
|
|
|
pi.set_mode(11)
|
2022-07-20 17:02:17 +03:00
|
|
|
|
2022-07-20 19:03:17 +01:00
|
|
|
async def run_command(*args):
|
2022-07-21 01:47:08 +01:00
|
|
|
process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
2022-07-20 19:03:17 +01:00
|
|
|
print("Started: %s, pid=%s" % (args, process.pid), flush=True)
|
|
|
|
|
|
|
|
|
2022-07-25 16:30:01 +03:00
|
|
|
async def button_press(gpio:int, level):
|
2022-07-20 19:03:17 +01:00
|
|
|
global PTT_IS_ON
|
2022-07-20 19:31:34 +03:00
|
|
|
while True:
|
|
|
|
if(pi.read(gpio)!=0):
|
2022-07-21 01:47:08 +01:00
|
|
|
PTT_IS_ON = True
|
2022-07-20 19:31:34 +03:00
|
|
|
if(pi.read(gpio)==0):
|
2022-07-21 01:47:08 +01:00
|
|
|
PTT_IS_ON = False
|
2022-07-20 19:03:17 +01:00
|
|
|
await asyncio.sleep(.5)
|
2022-07-20 15:41:07 +01:00
|
|
|
|
2022-07-25 16:30:01 +03:00
|
|
|
|
|
|
|
async def moduation_change(gpio:int, level):
|
|
|
|
global MODULATION
|
|
|
|
while True:
|
|
|
|
# given that the logic is the same
|
|
|
|
# if it isn't: TODO: rewrite this func
|
|
|
|
if(pi.read(gpio)!=0):
|
|
|
|
MODULATION = next(modulations)
|
|
|
|
await asyncio.sleep(.5)
|
|
|
|
|
|
|
|
async def frequency(gpio):
|
|
|
|
# TODO write this function after hooking up the encoder
|
|
|
|
async def main(freq:float):
|
2022-07-20 19:32:26 +03:00
|
|
|
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
|
2022-07-25 16:30:01 +03:00
|
|
|
# TODO change after figuring out the logic
|
|
|
|
asyncio.create_task(modulation_change(11, pigpio.EITHER_EDGE))
|
|
|
|
task_created = False
|
|
|
|
|
2022-07-21 01:47:08 +01:00
|
|
|
print("Ready")
|
2022-07-20 19:18:34 +03:00
|
|
|
while True:
|
2022-07-21 01:47:08 +01:00
|
|
|
if (PTT_IS_ON and not task_created):
|
2022-07-25 16:30:01 +03:00
|
|
|
asyncio.create_task(run_command(MODULATION, str(freq)))
|
2022-07-21 01:47:08 +01:00
|
|
|
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
|
2022-07-20 19:03:17 +01:00
|
|
|
await asyncio.sleep(.5)
|
2022-07-20 19:28:27 +03:00
|
|
|
|
2022-07-25 16:30:01 +03:00
|
|
|
|
2022-07-20 17:29:35 +03:00
|
|
|
if __name__ == "__main__":
|
2022-07-21 01:47:08 +01:00
|
|
|
try:
|
2022-07-25 16:30:01 +03:00
|
|
|
asyncio.run(main("", 430))
|
2022-07-21 01:47:08 +01:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("\n")
|