From b66ad843a789baecfcbaa0d52566ce9a4f375aa0 Mon Sep 17 00:00:00 2001 From: Boyan Date: Fri, 29 Jul 2022 17:10:43 +0300 Subject: [PATCH] lmao --- main.py | 16 +++++-------- main_classes.py | 62 ------------------------------------------------- rotary.py | 9 +++++-- 3 files changed, 13 insertions(+), 74 deletions(-) delete mode 100644 main_classes.py diff --git a/main.py b/main.py index 2be61f7..94210df 100644 --- a/main.py +++ b/main.py @@ -6,8 +6,12 @@ import asyncio import os 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 -MODULATION:str = None FREQUENCY:float = float(430) modulations = cycle(["./modulations/ssb.sh", "./modulations/fmrds.sh"]) @@ -35,24 +39,16 @@ async def button_press(gpio:int, level): 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): # TODO write this function after hooking up the encoder + async def main(freq:float): # TODO change after figuring out the logic task_created = False print("Ready") while True: - await moduation_change(gpio, level) await button_press(gpio, level) if (PTT_IS_ON and not task_created): asyncio.create_task(run_command(MODULATION, str(freq))) diff --git a/main_classes.py b/main_classes.py deleted file mode 100644 index 7fb2934..0000000 --- a/main_classes.py +++ /dev/null @@ -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") diff --git a/rotary.py b/rotary.py index 909ab8f..802aeba 100644 --- a/rotary.py +++ b/rotary.py @@ -9,8 +9,10 @@ bands = { "2m":[144,146], "70cm":[430,440] } + band = iter(bands) CURRENT_BAND = None + def setup_encoder(ranges:list): def rotary_callback(counter): print("Counter value: ", round(counter, 2)) @@ -40,11 +42,14 @@ def change_band(plus:bool=False, minus:bool=False): CURRENT_BAND = next(band) if minus: 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) except Exception as 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) return encoder