diff --git a/arduino-mixer.ino b/arduino-mixer.ino index 6c8abfa..f817a62 100644 --- a/arduino-mixer.ino +++ b/arduino-mixer.ino @@ -159,7 +159,6 @@ void drawBar() { } // Draw program name in the middle of the display or scroll it -// TODO: Fix char lenght void drawName() { int width = 0; for (size_t i = 0; i < sizeof(programName); i++) @@ -195,6 +194,8 @@ void processData() { { connected = true; Serial.println(""); + Serial.println(""); + Serial.println(""); } else if (strcmp("COUNT", command) == 0) { @@ -272,7 +273,7 @@ void checkInput(unsigned long time) { } else { currentProgram--; } - Serial.println(""); + Serial.println(""); } else { if (volume != 0) { @@ -291,7 +292,7 @@ void checkInput(unsigned long time) { } else { currentProgram++; } - Serial.println(""); + Serial.println(""); } else { if (volume != 100) { @@ -348,7 +349,7 @@ void loop() { checkSerial(); // Check if serial connection is established - if (connected) + if (connected && dataReady) { // Draw menu every second or every 0.1 second when editing if (menuUpdate || (editing && time % 100 == 0)) { diff --git a/python/start.py b/python/start.py index da1eaab..7dd7c04 100644 --- a/python/start.py +++ b/python/start.py @@ -11,8 +11,7 @@ def main(): sessions = AudioUtilities.GetAllSessions() print (str(len(sessions)) + " audio sessions found:") for session in sessions: - volume = session.SimpleAudioVolume - print (" " + str(session.Process)) + print (" " + str(session)) # Init serial connection ports = serial.tools.list_ports.comports() @@ -32,10 +31,65 @@ def main(): print ("Waiting for arduino...") time.sleep(5) board.write("".encode("utf-8")) - board.write("".encode("utf-8")) - board.write("".encode("utf-8")) - board.write("".encode("utf-8")) + + currentProgram = 0 + + line = [] + newData = False + recvInProgress = False + startMarker = '60' # < + endMarker = '62' # > + + while True: + for c in board.read(): + if c == 62: + recvInProgress = False + newData = True + if recvInProgress == True: + line.append(chr(c)) + if c == 60: + recvInProgress = True + break + + if newData == True: + dataArray = ''.join(line).split(',') + command = dataArray[0] + if len(dataArray) > 1: + data = dataArray[1] + + # Process data + # TODO: Listen for programs being added, then send this again + if command == "COUNT": + board.write(("").encode()) + elif command == "SWITCH": + currentProgram = int(data) + program = sessions[currentProgram] + + volume = program.SimpleAudioVolume.GetMasterVolume() + + if program.DisplayName == "@%SystemRoot%\System32\AudioSrv.Dll,-202": + name = "Systeem" + # TODO: This line is being overwritten somehow + elif session.Process and session.Process.name() == "firefox.exe": + name = "Firefox" + elif program.DisplayName != "": + name = str(program.DisplayName) + else: + name = str(session.Process and session.Process.name()) + + board.write(("").encode()) + board.write(("").encode()) + elif command == "SETVOL": + audio = sessions[currentProgram].SimpleAudioVolume + + audio.SetMasterVolume(float(data) / 100, None) + + volume = audio.GetMasterVolume() + board.write(("").encode()) + + line = [] + newData = False if __name__ == "__main__": main() \ No newline at end of file