Made some starting efforts for controlling the frequency and the modulation
This commit is contained in:
parent
24e30d7e12
commit
efc5ac36f6
39
main.py
39
main.py
@ -4,25 +4,27 @@ import time
|
|||||||
import datetime
|
import datetime
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
|
from itertools import cycle
|
||||||
|
|
||||||
PTT_IS_ON = False
|
PTT_IS_ON:bool = False
|
||||||
modulations = {
|
MODULATION:str = None
|
||||||
"ssb":"./modulations/ssb.sh",
|
FREQUENCY:float = float(430)
|
||||||
"fmrds":"./modulations/fmrds.sh"
|
modulations = cycle(["./modulations/ssb.sh", "./modulations/fmrds.sh"])
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# init GPIO
|
# init GPIO
|
||||||
pi = pigpio.pi()
|
pi = pigpio.pi()
|
||||||
# button pin
|
# button pin
|
||||||
pi.set_mode(10, pigpio.INPUT)
|
pi.set_mode(10, pigpio.INPUT)
|
||||||
|
# modulation change pin(change this)
|
||||||
|
pi.set_mode(11)
|
||||||
|
|
||||||
async def run_command(*args):
|
async def run_command(*args):
|
||||||
process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
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)
|
print("Started: %s, pid=%s" % (args, process.pid), flush=True)
|
||||||
|
|
||||||
|
|
||||||
async def button_press(gpio:int, level) -> bool:
|
async def button_press(gpio:int, level):
|
||||||
global PTT_IS_ON
|
global PTT_IS_ON
|
||||||
while True:
|
while True:
|
||||||
if(pi.read(gpio)!=0):
|
if(pi.read(gpio)!=0):
|
||||||
@ -31,14 +33,28 @@ async def button_press(gpio:int, level) -> bool:
|
|||||||
PTT_IS_ON = False
|
PTT_IS_ON = False
|
||||||
await asyncio.sleep(.5)
|
await asyncio.sleep(.5)
|
||||||
|
|
||||||
async def main(mod, freq:float):
|
|
||||||
|
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):
|
||||||
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
|
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
|
||||||
global PTT_IS_ON
|
# TODO change after figuring out the logic
|
||||||
task_created = False
|
asyncio.create_task(modulation_change(11, pigpio.EITHER_EDGE))
|
||||||
|
task_created = False
|
||||||
|
|
||||||
print("Ready")
|
print("Ready")
|
||||||
while True:
|
while True:
|
||||||
if (PTT_IS_ON and not task_created):
|
if (PTT_IS_ON and not task_created):
|
||||||
asyncio.create_task(run_command(modulations[mod], str(freq)))
|
asyncio.create_task(run_command(MODULATION, str(freq)))
|
||||||
task_created = True
|
task_created = True
|
||||||
elif (task_created and not PTT_IS_ON):
|
elif (task_created and not PTT_IS_ON):
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
@ -46,8 +62,9 @@ async def main(mod, freq:float):
|
|||||||
task_created = False
|
task_created = False
|
||||||
await asyncio.sleep(.5)
|
await asyncio.sleep(.5)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
asyncio.run(main("fmrds", 430))
|
asyncio.run(main("", 430))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n")
|
print("\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user