MPD: vu-meter
This commit is contained in:
parent
aaeafaae54
commit
7a4f8aa4af
25
mpd_dot3k.py
25
mpd_dot3k.py
|
@ -8,6 +8,8 @@ import queue
|
||||||
import threading
|
import threading
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
import audioop
|
||||||
import dot3k.lcd as lcd
|
import dot3k.lcd as lcd
|
||||||
import dot3k.backlight as backlight
|
import dot3k.backlight as backlight
|
||||||
import dot3k.joystick as nav
|
import dot3k.joystick as nav
|
||||||
|
@ -51,6 +53,21 @@ char_stop = [
|
||||||
|
|
||||||
q = queue.Queue()
|
q = queue.Queue()
|
||||||
|
|
||||||
|
def vumeter():
|
||||||
|
fifo = os.open('/tmp/mpd.fifo', os.O_RDONLY)
|
||||||
|
while run_event.is_set():
|
||||||
|
try:
|
||||||
|
rawStream = os.read(fifo, 4096)
|
||||||
|
except OSError as err:
|
||||||
|
if err.errno == errno.EAGAIN or err.errno == errno.EWOULDBLOCK:
|
||||||
|
rawStream = None
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
if rawStream:
|
||||||
|
backlight.set_graph(audioop.rms(rawStream,2)/32768)
|
||||||
|
backlight.set_graph(0)
|
||||||
|
|
||||||
|
|
||||||
def stringrotate(text, width, step):
|
def stringrotate(text, width, step):
|
||||||
if len(text) > width:
|
if len(text) > width:
|
||||||
fulltext = text + " - "
|
fulltext = text + " - "
|
||||||
|
@ -71,10 +88,13 @@ def display():
|
||||||
status = arg['status']['state']
|
status = arg['status']['state']
|
||||||
|
|
||||||
if status == "play":
|
if status == "play":
|
||||||
|
backlight.rgb(0, 0, 255) # green
|
||||||
lcd.create_char(0, char_play)
|
lcd.create_char(0, char_play)
|
||||||
elif status == "pause":
|
elif status == "pause":
|
||||||
|
backlight.rgb(0, 255, 0) # blue
|
||||||
lcd.create_char(0, char_pause)
|
lcd.create_char(0, char_pause)
|
||||||
else:
|
else:
|
||||||
|
backlight.rgb(255, 0, 0)
|
||||||
lcd.create_char(0, char_stop)
|
lcd.create_char(0, char_stop)
|
||||||
|
|
||||||
if status not in {'play','pause'} or song_file != arg['song']['file']:
|
if status not in {'play','pause'} or song_file != arg['song']['file']:
|
||||||
|
@ -160,19 +180,22 @@ def button_right(pin):
|
||||||
def on_exit(sig, func=None):
|
def on_exit(sig, func=None):
|
||||||
run_event.clear()
|
run_event.clear()
|
||||||
t_display.join()
|
t_display.join()
|
||||||
|
t_vumeter.join()
|
||||||
backlight.rgb(0, 0, 0)
|
backlight.rgb(0, 0, 0)
|
||||||
backlight.rgb(0, 0, 0)
|
backlight.rgb(0, 0, 0)
|
||||||
print("Screen sound be blank and light off now.")
|
print("Screen sound be blank and light off now.")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
backlight.rgb(55, 55, 55)
|
lcd.set_contrast(50)
|
||||||
run_event = threading.Event()
|
run_event = threading.Event()
|
||||||
run_event.set()
|
run_event.set()
|
||||||
client = MPDClient()
|
client = MPDClient()
|
||||||
client.connect("localhost", 6600)
|
client.connect("localhost", 6600)
|
||||||
|
|
||||||
t_display = threading.Thread(name='display',target=display)
|
t_display = threading.Thread(name='display',target=display)
|
||||||
|
t_vumeter = threading.Thread(name='vumeter',target=vumeter)
|
||||||
t_display.start()
|
t_display.start()
|
||||||
|
t_vumeter.start()
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, on_exit)
|
signal.signal(signal.SIGTERM, on_exit)
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue