Compare commits

..

2 Commits

Author SHA1 Message Date
ABelliqueux 485586af3e Remove pgpiod code 2024-12-19 09:33:04 +01:00
ABelliqueux 1a0b03d991 Switch to rotary encoder 2024-12-19 07:25:50 +01:00
1 changed files with 27 additions and 41 deletions

View File

@ -17,21 +17,6 @@ from luma.core.render import canvas
from luma.oled.device import ssd1306
from PIL import Image, ImageDraw, ImageFont
# Pot_cap
import pigpio
import pot_cap
min_val = 8
max_val = 298
vol_mult = 100/(max_val-min_val)
volume = 0
v_1 = 0
v_2 = 0
ctrlc_pressed = False
pot_cap_gpio = 23
drain_ms = 0.8
timeout_s = 1.0
jfont = ImageFont.truetype('DejaVuSansMono.ttf', 10)
# MPD config
@ -46,6 +31,14 @@ GPIO.setmode(GPIO.BCM)
RELAIS_1_GPIO = 17
GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Assign mode
# Rotary encoder
clk = 27
dt = 22
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
volume = 0
clkLastState = GPIO.input(clk)
# Buttons GPIO
BTNS = { 'BTN_1' : dict(GPIO=7, state=1),
'BTN_2' : dict(GPIO=8, state=1),
@ -357,11 +350,6 @@ def send_mpd_cmd(client, cmd:str, ui_state:dict):
def main(args):
# Idle timer
ui_idle_for = 0
# Pot_cap
# Connect to Pi.
pi = pigpio.pi()
# Instantiate Pot/Cap reader.
pc = pot_cap.reader(pi, pot_cap_gpio, drain_ms, timeout_s)
start = time()
previous_song_id = None
@ -397,23 +385,22 @@ def main(args):
global static_ui
static_ui = generate_static_ui(current_mode)
while ctrlc_pressed is False:
# pot_cap
global v_1
global v_2
global volume
s, v, r = pc.read()
if s and r < 4:
volume = round(v*vol_mult)
if (abs(volume - v_1) > 1) and (abs(volume - v_2) > 2):
print("Volume: {}".format(volume))
if volume < min_val:
volume = 0
if volume > 100:
volume = 100
client.setvol(100-volume)
ui_idle_for = 0
v_2 = v_1
v_1 = volume
global volume, clkLastState
# Rotary encoder
clkState = GPIO.input(clk)
dtState = GPIO.input(dt)
if clkState != clkLastState:
if dtState != clkState:
if volume < 100:
volume += 1
else:
if volume > 0:
volume -= 1
print(volume)
client.setvol(volume)
ui_idle_for = 0
# ~ clkLastState = clkState
# ~ sleep(0.01)
# MPD
mpd_status = client.status()
if len(mpd_status):
@ -470,12 +457,11 @@ def main(args):
# Avoid further execution
ui_idle_for = 11
device.hide()
# pot_cap
pc.cancel() # Cancel the reader.
pi.stop() # Disconnect from Pi.
clkLastState = clkState
device.cleanup()
client.disconnect()
GPIO.cleanup()
return 0