Compare commits

..

No commits in common. "485586af3eea649e82bbb6bf1d8bdf640c116715" and "9fed2a710b33d6e6125f2856005ea728d7866c13" have entirely different histories.

1 changed files with 41 additions and 27 deletions

View File

@ -17,6 +17,21 @@ 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
@ -31,14 +46,6 @@ 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),
@ -350,6 +357,11 @@ 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
@ -385,22 +397,23 @@ def main(args):
global static_ui
static_ui = generate_static_ui(current_mode)
while ctrlc_pressed is False:
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)
# 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
# MPD
mpd_status = client.status()
if len(mpd_status):
@ -457,11 +470,12 @@ def main(args):
# Avoid further execution
ui_idle_for = 11
device.hide()
clkLastState = clkState
# pot_cap
pc.cancel() # Cancel the reader.
pi.stop() # Disconnect from Pi.
device.cleanup()
client.disconnect()
GPIO.cleanup()
return 0