Changing volume and program is working
This commit is contained in:
parent
d25ca36444
commit
ed1bc1fdb4
@ -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("<OK>");
|
||||
Serial.println("<COUNT>");
|
||||
Serial.println("<SWITCH," + (String)currentProgram + ">");
|
||||
}
|
||||
else if (strcmp("COUNT", command) == 0)
|
||||
{
|
||||
@ -272,7 +273,7 @@ void checkInput(unsigned long time) {
|
||||
} else {
|
||||
currentProgram--;
|
||||
}
|
||||
Serial.println("<NAME," + (String)currentProgram + ">");
|
||||
Serial.println("<SWITCH," + (String)currentProgram + ">");
|
||||
} else {
|
||||
if (volume != 0)
|
||||
{
|
||||
@ -291,7 +292,7 @@ void checkInput(unsigned long time) {
|
||||
} else {
|
||||
currentProgram++;
|
||||
}
|
||||
Serial.println("<NAME," + (String)currentProgram + ">");
|
||||
Serial.println("<SWITCH," + (String)currentProgram + ">");
|
||||
} 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)) {
|
||||
|
@ -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("<HELLO>".encode("utf-8"))
|
||||
board.write("<COUNT,3>".encode("utf-8"))
|
||||
board.write("<GETVOL,50>".encode("utf-8"))
|
||||
board.write("<NAME,Test>".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(("<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__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user