This commit is contained in:
Boyan 2022-07-29 17:10:43 +03:00
parent d50b67fed1
commit b66ad843a7
3 changed files with 13 additions and 74 deletions

16
main.py
View File

@ -6,8 +6,12 @@ import asyncio
import os import os
from itertools import cycle from itertools import cycle
# 1. Hook up the screen and buttons
# * the screen should show the frequency we're at
# * read the buttons
# 2. Encoder
# * Change frequency in the scope of a given band
PTT_IS_ON:bool = False PTT_IS_ON:bool = False
MODULATION:str = None
FREQUENCY:float = float(430) FREQUENCY:float = float(430)
modulations = cycle(["./modulations/ssb.sh", "./modulations/fmrds.sh"]) modulations = cycle(["./modulations/ssb.sh", "./modulations/fmrds.sh"])
@ -35,24 +39,16 @@ async def button_press(gpio:int, level):
await asyncio.sleep(.5) await asyncio.sleep(.5)
async def moduation_change(gpio:int, level):
global MODULATION
# 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): 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):
# TODO change after figuring out the logic # TODO change after figuring out the logic
task_created = False task_created = False
print("Ready") print("Ready")
while True: while True:
await moduation_change(gpio, level)
await button_press(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)))

View File

@ -1,62 +0,0 @@
#!/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")

View File

@ -9,8 +9,10 @@ bands = {
"2m":[144,146], "2m":[144,146],
"70cm":[430,440] "70cm":[430,440]
} }
band = iter(bands) band = iter(bands)
CURRENT_BAND = None CURRENT_BAND = None
def setup_encoder(ranges:list): def setup_encoder(ranges:list):
def rotary_callback(counter): def rotary_callback(counter):
print("Counter value: ", round(counter, 2)) print("Counter value: ", round(counter, 2))
@ -40,11 +42,14 @@ def change_band(plus:bool=False, minus:bool=False):
CURRENT_BAND = next(band) CURRENT_BAND = next(band)
if minus: if minus:
try: try:
CURRENT_BAND = bands[list(bands.keys)[list(bands.keys()).index(CURRENT_BAND)-1]] CURRENT_BAND = bands[list(bands)[list(bands.keys()).index(CURRENT_BAND)-1]]
print(CURRENT_BAND) print(CURRENT_BAND)
except Exception as e: except Exception as e:
print(e) print(e)
encoder = setup_encoder(bands[CURRENT_BAND]) try:
encoder = setup_encoder(bands[CURRENT_BAND])
except Exception as e:
print(e)
print(CURRENT_BAND) print(CURRENT_BAND)
return encoder return encoder