RaspiQRP/rotary.py

65 lines
1.5 KiB
Python
Raw Normal View History

from functools import wraps, partial
from RPi import GPIO
from time import sleep
from itertools import cycle
clkLastState = GPIO.input(clk)
counter = next_band()
bands = {
"80m":[3.5, 4],
"40m":[7, 7.3],
"20m":[14, 14.35],
"10m":[28, 29.7],
"2m":[144,146],
"70cm":[430,440]
}
# Setup for encoder
band = cycle(bands)
CURRENT_BAND = None
step = 0.025
2022-07-29 17:49:26 +01:00
def next_band():
global CURRENT_BAND
CURRENT_BAND = next(band)
counter = bands[CURRENT_BAND][0]
print(counter)
print(CURRENT_BAND)
2022-07-29 17:49:26 +01:00
return counter
2022-07-29 17:49:26 +01:00
def prev_band():
global CURRENT_BAND
CURRENT_BAND = list(bands.keys())[list(bands.keys()).index(CURRENT_BAND)-1]
print(CURRENT_BAND)
counter = bands[CURRENT_BAND][0] + 1
return counter
2022-07-29 17:49:26 +01:00
async def main_loop(clk, dt, sw):
2022-07-29 17:49:26 +01:00
try:
clkState = GPIO.input(clk)
dtState = GPIO.input(dt)
swState = GPIO.input(sw)
if swState == GPIO.HIGH:
print("yeet")
if clkState != clkLastState:
if counter > bands[CURRENT_BAND][1]:
counter = next_band()
if counter < bands[CURRENT_BAND][0]:
counter = prev_band()
if dtState != clkState:
counter += step
else:
counter -= step
# print(round(counter, 3))
clkLastState = clkState
sleep(0.01)
2022-07-29 17:49:26 +01:00
except KeyboardInterrupt:
print("\nBye")
2022-07-29 17:49:26 +01:00
finally:
print("AAAAA")
GPIO.cleanup()