Quite content with it (Playing is not always working)
This commit is contained in:
parent
c0ad31810f
commit
ec91729896
5 changed files with 42 additions and 41 deletions
|
@ -14,9 +14,10 @@ void layout(unsigned int tick) {
|
|||
if ( playing || tick % 3 ) {
|
||||
display.setCursor(0, 0);
|
||||
// First line (20)
|
||||
display.print(F(" "));
|
||||
if (volume < 100 ) display.print(' ');
|
||||
display.print(volume);
|
||||
display.print(F("% || "));
|
||||
display.print(F("% |||| "));
|
||||
if (repeat_bool) display.print('r');
|
||||
else display.print(' ');
|
||||
if (random_bool) display.print('x');
|
||||
|
@ -29,9 +30,7 @@ void layout(unsigned int tick) {
|
|||
else display.print(' ');
|
||||
if (updating_bool) display.print('u');
|
||||
else display.print(' ');
|
||||
display.print(" || ");
|
||||
display.print(progress);
|
||||
display.print("% ");
|
||||
display.print(" ");
|
||||
}
|
||||
|
||||
//line 2
|
||||
|
@ -60,7 +59,7 @@ String textscroll(String text, unsigned int tick) {
|
|||
|
||||
text = text + " - ";
|
||||
for ( int i = 0; i < chars; i++ )
|
||||
newstring += text.charAt((tick + i) % (len+3));
|
||||
newstring += text.charAt((2*tick + i) % (len+3));
|
||||
|
||||
return newstring;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ boolean single_bool = true;
|
|||
boolean playing = false;
|
||||
|
||||
int volume = 100;
|
||||
int progress = 51;
|
||||
String title = " << << Title >> >> ";
|
||||
String artist = " << << Artist >> >> ";
|
||||
String album = " << << Album >> >> ";
|
||||
|
@ -75,6 +74,7 @@ void setup() {
|
|||
layout(tick);
|
||||
calcMaxTicks();
|
||||
|
||||
|
||||
while(!Serial);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ void setFromSerial (String inputString) {
|
|||
case 'c': string = consume_bool; break;
|
||||
case 'u': string = updating_bool; break;
|
||||
case 's': string = single_bool; break;
|
||||
case 'p': string = progress; break;
|
||||
case 'P': string = playing; break;
|
||||
default: string = "!"; break;
|
||||
}
|
||||
|
@ -53,7 +52,6 @@ void setFromSerial (String inputString) {
|
|||
case 'T': title = string; break;
|
||||
case 'A': artist = string; break;
|
||||
case 'a': album = string; break;
|
||||
case 'p': progress = string.toInt(); break;
|
||||
case 'P': playing = (string != 0); break;
|
||||
case 'r': repeat_bool = (string != 0); break;
|
||||
case 'z': shuffle_bool = (string != 0); break;
|
||||
|
|
|
@ -16,9 +16,10 @@ class SerialMPCduino(object):
|
|||
__single = None
|
||||
__consume = None
|
||||
|
||||
def __init__(self, tty, baud):
|
||||
def __init__(self, tty, baud, verbose):
|
||||
self.tty = tty
|
||||
self.baud = baud
|
||||
self.verbose = verbose
|
||||
self.serial = serial.Serial(tty, baud)
|
||||
|
||||
|
||||
|
@ -27,27 +28,28 @@ class SerialMPCduino(object):
|
|||
print(self.serial)
|
||||
print("------")
|
||||
|
||||
def check_serial(self):
|
||||
while not self.serial.inWaiting():
|
||||
pass
|
||||
def vprint(self, string):
|
||||
if self.verbose > 1:
|
||||
print(string)
|
||||
|
||||
def check_serial(self):
|
||||
if ( self.serial.inWaiting() > 0 ):
|
||||
#if incoming bytes are waiting to be read from the serial input buffer
|
||||
#read the bytes and convert from binary array to ASCII
|
||||
string = self.serial.readline().decode('ascii')
|
||||
print(string)
|
||||
return string
|
||||
|
||||
def write_serial(self, string):
|
||||
print("S"+string)
|
||||
self.vprint("S"+string)
|
||||
wait_time = 0.3 + 10 * len(string) / float(self.baud)
|
||||
self.serial.write("S"+string+"\n")
|
||||
time.sleep(wait_time)
|
||||
|
||||
string = self.serial.readline().decode('ascii')
|
||||
time.sleep(0.2)
|
||||
print(string)
|
||||
print("Ready")
|
||||
self.vprint(string)
|
||||
self.vprint(self.check_serial())
|
||||
self.vprint("Ready")
|
||||
|
||||
def read_serial(self, string):
|
||||
self.serial.write("E"+string+"\n")
|
||||
|
@ -62,14 +64,14 @@ class SerialMPCduino(object):
|
|||
|
||||
|
||||
# Percentages
|
||||
@property
|
||||
def progress(self):
|
||||
return self.read_serial("p")
|
||||
@progress.setter
|
||||
def progress(self, new):
|
||||
if self.Checker(self.__progress, new, "p"+str(new)):
|
||||
print("Progress: {}".format(new))
|
||||
self.__progress = new
|
||||
#@property
|
||||
#def progress(self):
|
||||
# return self.read_serial("p")
|
||||
#@progress.setter
|
||||
#def progress(self, new):
|
||||
# if self.Checker(self.__progress, new, "p"+str(new)):
|
||||
# print("Progress: {}".format(new))
|
||||
# self.__progress = new
|
||||
|
||||
@property
|
||||
def volume(self):
|
||||
|
@ -114,7 +116,7 @@ class SerialMPCduino(object):
|
|||
return self.write_serial("r")
|
||||
@repeat.setter
|
||||
def repeat(self, new):
|
||||
if self.Checker(self.__repeat, new, "r"+str(new)):
|
||||
if self.Checker(self.__repeat, new, "r"+str(new*1)):
|
||||
print("Repeat: {}".format(new))
|
||||
self.__repeat = new
|
||||
|
||||
|
@ -123,7 +125,7 @@ class SerialMPCduino(object):
|
|||
return self.write_serial("z")
|
||||
@shuffle.setter
|
||||
def shuffle(self, new):
|
||||
if self.Checker(self.__shuffle, new, "z"+str(new)):
|
||||
if self.Checker(self.__shuffle, new, "z"+str(new*1)):
|
||||
print("Shuffle: {}".format(new))
|
||||
self.__shuffle = new
|
||||
|
||||
|
@ -132,7 +134,7 @@ class SerialMPCduino(object):
|
|||
return self.read_serial("s")
|
||||
@single.setter
|
||||
def single(self, single):
|
||||
if self.Checker(self.__single, new, "s"+str(new)):
|
||||
if self.Checker(self.__single, new, "s"+str(new*1)):
|
||||
print("Single: {}".format(new))
|
||||
self.__single = new
|
||||
|
||||
|
@ -141,7 +143,7 @@ class SerialMPCduino(object):
|
|||
return self.read_serial("x")
|
||||
@random.setter
|
||||
def random(self, new):
|
||||
if self.Checker(self.__random, new, "x"+str(new)):
|
||||
if self.Checker(self.__random, new, "x"+str(new*1)):
|
||||
print("Random: {}".format(new))
|
||||
self.__random = new
|
||||
|
||||
|
@ -150,24 +152,24 @@ class SerialMPCduino(object):
|
|||
return self.read_serial("x")
|
||||
@consume.setter
|
||||
def consume(self, new):
|
||||
if self.Checker(self.__consume, new, "c"+str(new)):
|
||||
if self.Checker(self.__consume, new, "c"+str(new*1)):
|
||||
print("Consume: {}".format(new))
|
||||
self.__consume = new
|
||||
|
||||
@property
|
||||
def update(self):
|
||||
return self.read_serial("u")
|
||||
@update.setter
|
||||
def update(self, new):
|
||||
if self.Checker(self.__update, new, "u"+str(new)):
|
||||
print("Update: {}".format(new))
|
||||
self.__update = new
|
||||
#@property
|
||||
#def update(self):
|
||||
# return self.read_serial("u")
|
||||
#@update.setter
|
||||
#def update(self, new):
|
||||
# if self.Checker(self.__update, new, "u"+str(new*1)):
|
||||
# print("Update: {}".format(new))
|
||||
# self.__update = new
|
||||
|
||||
@property
|
||||
def playing(self):
|
||||
return self.read_serial("P")
|
||||
@playing.setter
|
||||
def playing(self, new):
|
||||
if self.Checker(self.__playing, new, "P"+str(new)):
|
||||
if self.Checker(self.__playing, new, "P"+str(new*1)):
|
||||
print("Playing: {}".format(new))
|
||||
self.__playing = new
|
||||
|
|
|
@ -5,6 +5,7 @@ import time
|
|||
|
||||
tty = '/dev/ttyACM0'
|
||||
baud = 9600
|
||||
verbose = 1
|
||||
mpdhost = 'fatserf.thuis'
|
||||
mpcformat = "+%title%\t%artist%\t%album%"
|
||||
|
||||
|
@ -22,10 +23,9 @@ consume = True
|
|||
playing = True
|
||||
|
||||
|
||||
#mpctext = subprocess.check_output(['mpc', 'current', '--wait', '-h', mpdhost, '-f', mpcformat])
|
||||
|
||||
if True:
|
||||
ser = SerialMPCduino(tty, baud)
|
||||
ser = SerialMPCduino(tty, baud, verbose)
|
||||
time.sleep(0.5)
|
||||
while True:
|
||||
mpctext = subprocess.check_output(['mpc', '-h', mpdhost, '-f', mpcformat])
|
||||
|
@ -85,4 +85,6 @@ if True:
|
|||
ser.album = album
|
||||
ser.repeat =repeat
|
||||
ser.shuffle = shuffle
|
||||
time.sleep(0.8)
|
||||
|
||||
time.sleep(0.4)
|
||||
subprocess.call(['mpc', '-h', mpdhost, 'idle'])# Waits for changes
|
||||
|
|
Loading…
Reference in a new issue