65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
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
|
|
|
|
|
|
def next_band():
|
|
global CURRENT_BAND
|
|
CURRENT_BAND = next(band)
|
|
counter = bands[CURRENT_BAND][0]
|
|
print(counter)
|
|
print(CURRENT_BAND)
|
|
|
|
return counter
|
|
|
|
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
|
|
|
|
async def main_loop(clk, dt, sw):
|
|
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)
|
|
except KeyboardInterrupt:
|
|
print("\nBye")
|
|
finally:
|
|
print("AAAAA")
|
|
GPIO.cleanup()
|