135 lines
3.5 KiB
Python
135 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import queue
|
|
import threading
|
|
import dot3k.lcd as lcd
|
|
from mpd import MPDClient
|
|
|
|
rotate_pause = 10 # delay in rotation steps
|
|
|
|
char_play = [
|
|
0b10000,
|
|
0b11000,
|
|
0b11100,
|
|
0b11110,
|
|
0b11110,
|
|
0b11100,
|
|
0b11000,
|
|
0b10000,
|
|
]
|
|
|
|
char_pause = [
|
|
0b00000,
|
|
0b11011,
|
|
0b11011,
|
|
0b11011,
|
|
0b11011,
|
|
0b11011,
|
|
0b11011,
|
|
0b00000,
|
|
]
|
|
|
|
char_stop = [
|
|
0b00000,
|
|
0b11111,
|
|
0b11111,
|
|
0b11111,
|
|
0b11111,
|
|
0b11111,
|
|
0b11111,
|
|
0b00000,
|
|
]
|
|
|
|
|
|
q = queue.Queue()
|
|
|
|
def stringrotate(text, width, step):
|
|
if len(text) > width:
|
|
fulltext = text + " - "
|
|
fulltext = fulltext[step:] + fulltext[:step]
|
|
return fulltext[:width]
|
|
else:
|
|
return text
|
|
|
|
def display():
|
|
title = ''
|
|
artist = ''
|
|
album = ''
|
|
song_file = '' # Useful to determine if current song actually changed
|
|
step_title = step_artist = step_album = 0
|
|
while True:
|
|
try:
|
|
arg = q.get(timeout=0.2)
|
|
status = arg['status']['state']
|
|
|
|
if status == "play":
|
|
lcd.create_char(0, char_play)
|
|
elif status == "pause":
|
|
lcd.create_char(0, char_pause)
|
|
else:
|
|
lcd.create_char(0, char_stop)
|
|
|
|
if song_file != arg['song']['file']:
|
|
song_file = arg['song']['file']
|
|
title = arg['song']['title']
|
|
artist = arg['song']['artist']
|
|
album = arg['song']['album']
|
|
|
|
step_title = step_artist = step_album = 0
|
|
delay_title = delay_artist = delay_album = rotate_pause
|
|
lcd.clear()
|
|
|
|
lcd.set_cursor_position(0, 0)
|
|
lcd.write(chr(0))
|
|
|
|
if len(title) <= 15:
|
|
lcd.set_cursor_position(1, 0)
|
|
lcd.write(title)
|
|
if len(artist) <= 16:
|
|
lcd.set_cursor_position(0, 1)
|
|
lcd.write(artist)
|
|
if len(album) <= 16:
|
|
lcd.set_cursor_position(0, 2)
|
|
lcd.write(album)
|
|
|
|
except queue.Empty:
|
|
if step_title == 0 and delay_title > 0:
|
|
delay_title -= 1
|
|
else:
|
|
step_title = (step_title + 1) % (len(title) + 3)
|
|
if delay_title == 0:
|
|
delay_title = rotate_pause
|
|
if step_artist == 0 and delay_artist > 0:
|
|
delay_artist -= 1
|
|
else:
|
|
step_artist = (step_artist + 1) % (len(artist) + 3)
|
|
if delay_title == 0:
|
|
delay_artist = rotate_pause
|
|
if step_album == 0 and delay_album > 0:
|
|
delay_album -= 1
|
|
else:
|
|
step_album = (step_album + 1) % (len(album) + 3)
|
|
if delay_title == 0:
|
|
delay_album = rotate_pause
|
|
|
|
if len(title) > 15:
|
|
lcd.set_cursor_position(1, 0)
|
|
lcd.write(stringrotate(title, 15, step_title))
|
|
if len(artist) > 16:
|
|
lcd.set_cursor_position(0, 1)
|
|
lcd.write(stringrotate(artist, 16, step_artist))
|
|
if len(album) > 16:
|
|
lcd.set_cursor_position(0, 2)
|
|
lcd.write(stringrotate(album, 16, step_album))
|
|
|
|
|
|
client = MPDClient()
|
|
client.connect("localhost", 6600)
|
|
|
|
t_display = threading.Thread(name='display',target=display)
|
|
t_display.start()
|
|
|
|
while True:
|
|
q.put({'song': client.currentsong(), 'status' : client.status()})
|
|
client.idle('player')
|