tried some dry optimization(w/o raspi)
This commit is contained in:
parent
efc5ac36f6
commit
2b086083cd
29
main.py
29
main.py
@ -24,35 +24,36 @@ async def run_command(*args):
|
|||||||
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):
|
async def button_press(gpio:int, level):
|
||||||
|
# TODO: light an LED
|
||||||
global PTT_IS_ON
|
global PTT_IS_ON
|
||||||
while True:
|
if(pi.read(gpio)!=0):
|
||||||
if(pi.read(gpio)!=0):
|
PTT_IS_ON = True
|
||||||
PTT_IS_ON = True
|
if(pi.read(gpio)==0):
|
||||||
if(pi.read(gpio)==0):
|
PTT_IS_ON = False
|
||||||
PTT_IS_ON = False
|
await asyncio.sleep(.5)
|
||||||
await asyncio.sleep(.5)
|
|
||||||
|
|
||||||
|
|
||||||
async def moduation_change(gpio:int, level):
|
async def moduation_change(gpio:int, level):
|
||||||
global MODULATION
|
global MODULATION
|
||||||
while True:
|
|
||||||
# given that the logic is the same
|
# given that the logic is the same
|
||||||
# if it isn't: TODO: rewrite this func
|
# if it isn't: TODO: rewrite this func
|
||||||
if(pi.read(gpio)!=0):
|
if(pi.read(gpio)!=0):
|
||||||
MODULATION = next(modulations)
|
MODULATION = next(modulations)
|
||||||
await asyncio.sleep(.5)
|
await asyncio.sleep(.5)
|
||||||
|
|
||||||
async def frequency(gpio):
|
async def frequency(gpio):
|
||||||
# TODO write this function after hooking up the encoder
|
# TODO write this function after hooking up the encoder
|
||||||
async def main(freq:float):
|
async def main(freq:float):
|
||||||
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
|
|
||||||
# TODO change after figuring out the logic
|
# TODO change after figuring out the logic
|
||||||
asyncio.create_task(modulation_change(11, pigpio.EITHER_EDGE))
|
|
||||||
task_created = False
|
task_created = False
|
||||||
|
|
||||||
print("Ready")
|
print("Ready")
|
||||||
while True:
|
while True:
|
||||||
|
await moduation_change(gpio, level)
|
||||||
|
await button_press(gpio, level)
|
||||||
if (PTT_IS_ON and not task_created):
|
if (PTT_IS_ON and not task_created):
|
||||||
asyncio.create_task(run_command(MODULATION, str(freq)))
|
asyncio.create_task(run_command(MODULATION, str(freq)))
|
||||||
task_created = True
|
task_created = True
|
||||||
|
62
main_classes.py
Normal file
62
main_classes.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#!/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")
|
Loading…
x
Reference in New Issue
Block a user