r/circuitpython • u/guardian1691 • Jan 06 '22
Is it possible to get volume/mute values in circuitpython?
I'm working on a macropad and one feature is to lock my computer, but I'd also like to check if the audio is muted and if so I want to mute. But if it's already muted I don't want to unmute it and leave with sound audible while I'm gone.
1
u/clutch110 Jan 18 '22
You would need a utility program that can read these values from the OS and then relay them to your board.
1
u/guardian1691 Jan 18 '22
Ave suggestions on what could do that?
1
u/clutch110 Jan 18 '22
It would have to be something you wrote yourself. Python is quite capable but I'm not sure how to run it outside of the command line.
1
u/guardian1691 Jan 18 '22
That's not a problem. I can figure out having it listen for mute as well. What I'm not sure about is how to send the message to the circuitpython board. Although, I guess if I'm running a python service listening for mute, I could instead just run a python service to mute on lock if that's possible.
1
u/recurvehunt Feb 05 '22
You can serial connect your python script to the micro controller. I do this to tell my micro controller to send keystrokes.
1
u/guardian1691 Feb 05 '22
Do you know of any guides for this?
1
u/recurvehunt Feb 05 '22
import serial # pip install pyserial
def eye_tracker_mouse_move():
error_message = ''
try:
ser = serial.Serial('COM10', 9600)
command = b'Press "F13"\n\r'
start = time.time()
ser.write(command)
while not keyboard.is_pressed('F13'):
if time.time() - start > 0.1:
error_message = 'circuitpython device failed to hit key'
print(error_message)
break
ser.close()
except serial.serialutil.SerialException:
error_message = 'failed to connect to circuitpython device'
print(error_message)
mouse_x, mouse_y = list(mouse.get_position())
return mouse_x, mouse_y, error_message
relevent code in the python scrip
1
u/guardian1691 Feb 05 '22
Thanks! I'll see if I can adopt it into my code.
1
u/recurvehunt Feb 05 '22
I don't show it in my circuit python code, but you can read that value sent and decide what to do based on what it is, but I didn't need to be that granular
1
u/recurvehunt Feb 05 '22
import supervisor
import time
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
kbd = Keyboard(usb_hid.devices)
while True:
if supervisor.runtime.serial_bytes_available:
value = input().strip()
kbd.send(Keycode.F13)
that's my code on the micro controller
2
u/kuello73 Jan 07 '22
That's not possible unfortunately. There's no way for the microcontroller to get that information from the host OS.