Changing volume and program is working

This commit is contained in:
Arne van Iterson 2020-05-21 23:15:54 +02:00
parent d25ca36444
commit ed1bc1fdb4
2 changed files with 64 additions and 9 deletions

View File

@ -159,7 +159,6 @@ void drawBar() {
} }
// Draw program name in the middle of the display or scroll it // Draw program name in the middle of the display or scroll it
// TODO: Fix char lenght
void drawName() { void drawName() {
int width = 0; int width = 0;
for (size_t i = 0; i < sizeof(programName); i++) for (size_t i = 0; i < sizeof(programName); i++)
@ -195,6 +194,8 @@ void processData() {
{ {
connected = true; connected = true;
Serial.println("<OK>"); Serial.println("<OK>");
Serial.println("<COUNT>");
Serial.println("<SWITCH," + (String)currentProgram + ">");
} }
else if (strcmp("COUNT", command) == 0) else if (strcmp("COUNT", command) == 0)
{ {
@ -272,7 +273,7 @@ void checkInput(unsigned long time) {
} else { } else {
currentProgram--; currentProgram--;
} }
Serial.println("<NAME," + (String)currentProgram + ">"); Serial.println("<SWITCH," + (String)currentProgram + ">");
} else { } else {
if (volume != 0) if (volume != 0)
{ {
@ -291,7 +292,7 @@ void checkInput(unsigned long time) {
} else { } else {
currentProgram++; currentProgram++;
} }
Serial.println("<NAME," + (String)currentProgram + ">"); Serial.println("<SWITCH," + (String)currentProgram + ">");
} else { } else {
if (volume != 100) if (volume != 100)
{ {
@ -348,7 +349,7 @@ void loop() {
checkSerial(); checkSerial();
// Check if serial connection is established // Check if serial connection is established
if (connected) if (connected && dataReady)
{ {
// Draw menu every second or every 0.1 second when editing // Draw menu every second or every 0.1 second when editing
if (menuUpdate || (editing && time % 100 == 0)) { if (menuUpdate || (editing && time % 100 == 0)) {

View File

@ -11,8 +11,7 @@ def main():
sessions = AudioUtilities.GetAllSessions() sessions = AudioUtilities.GetAllSessions()
print (str(len(sessions)) + " audio sessions found:") print (str(len(sessions)) + " audio sessions found:")
for session in sessions: for session in sessions:
volume = session.SimpleAudioVolume print (" " + str(session))
print (" " + str(session.Process))
# Init serial connection # Init serial connection
ports = serial.tools.list_ports.comports() ports = serial.tools.list_ports.comports()
@ -32,10 +31,65 @@ def main():
print ("Waiting for arduino...") print ("Waiting for arduino...")
time.sleep(5) time.sleep(5)
board.write("<HELLO>".encode("utf-8")) board.write("<HELLO>".encode("utf-8"))
board.write("<COUNT,3>".encode("utf-8"))
board.write("<GETVOL,50>".encode("utf-8")) currentProgram = 0
board.write("<NAME,Test>".encode("utf-8"))
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(("<COUNT," + str(len(sessions)) + ">").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(("<NAME," + name + ">").encode())
board.write(("<GETVOL," + str(round(volume * 100)) + ">").encode())
elif command == "SETVOL":
audio = sessions[currentProgram].SimpleAudioVolume
audio.SetMasterVolume(float(data) / 100, None)
volume = audio.GetMasterVolume()
board.write(("<GETVOL," + str(round(volume * 100)) + ">").encode())
line = []
newData = False
if __name__ == "__main__": if __name__ == "__main__":
main() main()