From 8aebd0b0a97a366d37db9cad2dd8fab0885633e0 Mon Sep 17 00:00:00 2001 From: fanta Date: Wed, 17 Aug 2022 18:09:02 +0200 Subject: [PATCH] codigo python inicial --- potenciometroVLC.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 potenciometroVLC.py diff --git a/potenciometroVLC.py b/potenciometroVLC.py new file mode 100755 index 0000000..9ffe7bf --- /dev/null +++ b/potenciometroVLC.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +import time +import serial +import os +import subprocess + +ser = serial.Serial(port='/dev/ttyUSB0',baudrate = 9600,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS,timeout=1) +last = "0" +cmd1="pactl list sink-inputs | grep -B 18 -i 'VLC media player (LibVLC 3.0.16)' | grep -i 'Entrada de destino' | awk '{print $4}'" +vlcID = subprocess.Popen(cmd1,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True); vlcOut,vlcErr=vlcID.communicate(); rc=vlcID.wait() +vlcOut = vlcOut[1:] +vlcOut = vlcOut.replace('\n', '') + +print("ID del VLC para usar con pactl: " + vlcOut) + +while 1: + x = ser.readline() + x = x.decode() + x = x.replace('\n', '') + x = x.replace('\r', '') + + if ( x != last ): + vlcID = subprocess.Popen(cmd1,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True); vlcOut,vlcErr=vlcID.communicate(); rc=vlcID.wait() + vlcOut = vlcOut[1:] + vlcOut = vlcOut.replace('\n', '') + #cmd2 = "amixer set Master " + str(x) + "%" + #cmd2 = "amixer set Headphone " + str(x) + "%" + cmd2 = "pactl set-sink-input-volume " + vlcOut + " " + str(x) + "%" + print(cmd2) + os.system(cmd2) + last = x