From aebb254b8201b6b173cca317ac1d6b8c446efb77 Mon Sep 17 00:00:00 2001 From: raspbeguy Date: Sun, 12 Mar 2017 17:04:43 +0100 Subject: [PATCH] mpd: only info text --- mpd_dot3k.py | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 mpd_dot3k.py diff --git a/mpd_dot3k.py b/mpd_dot3k.py new file mode 100644 index 0000000..9b48a4d --- /dev/null +++ b/mpd_dot3k.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 + +import queue +import threading +import dot3k.lcd as lcd +from mpd import MPDClient + +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.5) + 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 + 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: + step_title = (step_title + 1) % (len(title) + 3) + step_artist = (step_artist + 1) % (len(artist) + 3) + step_album = (step_album + 1) % (len(album) + 3) + + 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')