116 lines
2.7 KiB
Python
Executable file
116 lines
2.7 KiB
Python
Executable file
#!/usr/bin/env python
|
|
tty = '/dev/ttyACM1'
|
|
baud = 9600
|
|
|
|
import serial
|
|
import time
|
|
|
|
|
|
|
|
class SerialMPCduino(object):
|
|
volume = None
|
|
title = None
|
|
artist = None
|
|
album = None
|
|
repeat = None
|
|
shuffle = None
|
|
can_receive = True
|
|
|
|
def __init__(self, tty, baud):
|
|
self.serial = serial.Serial(tty, baud)
|
|
|
|
# Setup
|
|
print("Setup")
|
|
print(self.serial)
|
|
print("------")
|
|
|
|
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
|
|
print(self.serial.readline().decode('ascii'))
|
|
# Make sure buffer is empty
|
|
self.check_serial()
|
|
|
|
def write_serial(self, string):
|
|
self.serial.write("S"+string+"\n")
|
|
if not self.serial.read(1):
|
|
print("Error")
|
|
self.check_serial()
|
|
|
|
def read_serial(self, string):
|
|
self.serial.write("E"+string+"\n")
|
|
return self.serial.readline()
|
|
|
|
|
|
|
|
def setVolume(self, volume):
|
|
if self.volume != volume:
|
|
self.volume = volume
|
|
self.write_serial("V" + str(volume))
|
|
|
|
def setTitle(self, title):
|
|
if self.title != title:
|
|
self.title = title
|
|
self.write_serial("T" + str(title))
|
|
|
|
def setArtist(self, artist):
|
|
if self.artist != artist:
|
|
self.artist = artist
|
|
self.write_serial("A" + str(artist))
|
|
|
|
def setAlbum(self, album):
|
|
if self.album != album:
|
|
self.album = album
|
|
self.write_serial("a" + str(album))
|
|
|
|
def setRepeat(self, repeat):
|
|
if self.repeat != repeat:
|
|
self.repeat = repeat
|
|
self.write_serial("r" + str(repeat))
|
|
|
|
def setShuffle(self, shuffle):
|
|
if self.shuffle != shuffle:
|
|
self.shuffle = shuffle
|
|
self.write_serial("z" + str(shuffle))
|
|
|
|
def readVolume(self):
|
|
return self.read_serial("V")
|
|
|
|
def readTitle(self):
|
|
return self.read_serial("T")
|
|
|
|
def readArtist(self):
|
|
return self.read_serial("A")
|
|
|
|
def readAlbum(self):
|
|
return self.read_serial("a")
|
|
|
|
def readRepeat(self):
|
|
return self.read_serial("r")
|
|
|
|
def readShuffle(self):
|
|
return self.read_serial("z")
|
|
|
|
|
|
|
|
volume = 0
|
|
title = "Blub"
|
|
artist = "ee"
|
|
album = "dd"
|
|
repeat = True
|
|
shuffle = True
|
|
|
|
ser = SerialMPCduino(tty, baud)
|
|
print("loop")
|
|
|
|
while True:
|
|
print(volume)
|
|
volume = (volume + 1)
|
|
ser.setVolume(volume)
|
|
ser.setTitle(title)
|
|
ser.setArtist(artist)
|
|
ser.setAlbum(album)
|
|
ser.setRepeat(repeat)
|
|
ser.setShuffle(shuffle)
|
|
ser.readArtist()
|