In Ubuntu, we can select the output device of audio in sound preferences. But now I want to write a shell script, so I need to select the output device from the commandline.
You can first view your current default audio device by typing:
pactl stat
And with
pactl list
you can view all your devices.
And with this command
echo "set-default-sink alsa_output.Headset" | pacmd
you can set the default device.
But I found a much better source for this problem and a included little shell script for this problem here http://ubuntuforums.org/archive/index.php/t-1370383.html
Related
I am building some kind of kiosk system and I bought this USB DIY keyboard for it: https://www.amazon.com/gp/product/B07QPXQQ7L
This allows me to have a lot of buttons and they behave like keyboard keys.
I'm writing a program (Perl) that will take the input from that keyboard and do things based on that.
The problem is that I need to have the rest of the system (both X and the TTYs) ignore that keyboard so that it won't type random things in the terminal or in the window manager. In other words, the system should disregard it but the device itself must still be available in /dev/input/...
I don't need a real keyboard to control the machine because I connect via VNC and SSH.
Bonus points if you know how to read from a /dev/input/... keyboard and end up with letters typed just like with STDIN in a terminal.
Thanks!
I found the solution here where someone wanted the exact same thing in the case of a barcode reader:
https://serverfault.com/questions/385260/bind-usb-keyboard-exclusively-to-specific-application/976557#976557
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", RUN+="/bin/sh -c 'echo remove > /sys$env{DEVPATH}/uevent'"
ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", SYMLINK+="diykeyboard"
And then replace xxxx and yyyy by the Vendor and Product ID as found in lsusb. So in my case 1c4f and 0002:
Bus 001 Device 003: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
The udevadm control --reload thing didn't do it for me, I had to reboot.
Then in theory the data typed on the keyboard should be available at /dev/diykeyboard (the SYMLINK variable).
Now in my case unfortunately there are multiple events that match this vendor+product, and to match the right one I needed to add DEVPATH=="*:1.0/*", KERNEL=="event*" in the second line where it creates the SYMLINK. And then surprise it did not create the link in /dev so I had to do something dirty, create a link myself with ln:
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="1c4f", ATTRS{idProduct}=="0002", RUN+="/bin/sh -c 'echo remove > /sys$env{DEVPATH}/uevent'"
SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="1c4f", ATTRS{idProduct}=="0002", DEVPATH=="*:1.0/*", KERNEL=="event*", RUN+="/bin/sh -c 'ln -sf /dev/input/$kernel /diykeyboard'"
(don't create the link in /tmp since udev happens before the mounting of /tmp at boot)
From there I can read from /diykeyboard (which usually points to /dev/input/event0) either with evtest which shows the keys typed, or directly with my program and then decoding the scancodes.
I'm an arch linux user and I had a dream. Make a keyboard shortcut that will play a rimshot (Ba Dum Tsssss) when pressed.
After some researches it appears that pacmd is the best option to do so, but I have no idea how it works and the man page is empty, and the help lacks clear information... sinks, modules and sources... well, that's all obscure.
Can anybody help me to achieve my goal ?
From the man page:
pacmd set-sink-mute <index> <1|0>
controls the mute-ness of a given sink (sound interface) where <index> is the sink index (listed with pacmd list-sinks) and 1 or 0 indicates muted or not muted, respectively.
You'll likely want to create a short Bash script that would unmute the sink, play your sound, and then remute it; you can then bind this to a key.
I am connected on my embedded device with the serial port and would like to start my custom binaries on boot and be able to see the output generated.
My /etc/inittab file contains:
console::respawn:/sbin/getty -L 115200 ttyAPP3 vt100
console::respawn:/usr/bin/mybinary
With this configuration, I can see the output of mybinary in the serial console but It is difficult/impossible to connect (insert login and password) to getty because of the interference of the output generated.
I tried to switch the output in inittab to another not used tty (tty10) like this:
console::respawn:/sbin/getty -L 115200 ttyAPP3 vt100
tty10::respawn:/usr/bin/mybinary
And now I can connect but how can I see the output generated to /dev/tty10 ?
I tried cat /dev/tty10 but nothing is shown.
I know the question is old, but it has no answers at all for crying out loud.
Remember that a TTY is both an output device and also an input device -- by cat'ing from it you're reading input from the terminal which means the keyboard, NOT the screen.
I don't know if there's a parallel in other *nixes, but Linux systems have /dev/vcsX and /dev/vcsaX character devices (nodes c,7,0+X and c,7,128+X respectively) for each /dev/ttyX device - these are mirrors of the data currently on the output of the TTY device (ie. the screen part of the TTY, not the keyboard part). These will give you what you're looking for. The vcsaX devices will give you a displaybyte+attributebyte pair (i.e. the foreground/background text colour -- see other references for more information on text attribute bytes) for each character on the screen, while the vcsX devices give only the displaybyte for each character. Of course it's a raw stream/dump so if the row and/or column count of your terminal doesn't match that of the the TTY you're dumping then you'll need to parse the data and reformat it to match.
tl;dr: use "cat /dev/vcs10"
Hope that helps.
I need to write a script that controls and checks the gpio states.
I have been trying for a while to find a way to do it, but I didn't succeed.
Here is for the details :
I use an at91sam9260 board with a Linux kernel 2.6.27 embedded in it.
I see the /dev/gpio device
I tried some commands like cat /dev/gpio OR echo 1> /dev/gpio but it did not give me any result ( except an error message for the first command)
I also tried to create /dev/gpio0 .. to /dev/gpio31 (with the makedev command before recompiling the CRAMFS filesystem, but I did not get more results.
Does someone know how to check these gpio states and set/clear some of them ?
More generally, Is there an easy way to find out the proper shell commands for a particular device just by looking at the driver source files ?
If your kernel has sysfs support you can access and control the gpio pins through the interface in /sys/class/gpio. See the sysfs section of the kernel document in Documentation/gpio.txt.
I have used at91sam9260. You can set/unset the gpio pins using sysfs interface.
for ex. go to: cd /sys/class/gpio and then "echo 2 > export" and then set the directions of gpio pins to input(in)/output(out) by "echo in > direction" and then you can read the value from "value" file by "cat value"
Check /sys/kernel/debug/pinctrl/ directory for verbose GPIO info.
I'm trying to use a bunch of sundcards (8 usb + 4 hdmi + 1 mobo) to control different zones separately & combine them in cool ways.
I'm having trouble getting pulse to recognize all of my soundcards' existence.
"aplay -l" recognizes all 13 cards, as does "pacmd list-cards", but pulse only recognizes 10 of them (0-9). It seems to find them in the "pacmd dump", but not in "list-sinks."
my "pacmd info" file loads all the modules correctly, but I can't figure out why "list-sinks" doesn't list them.
If ALSA recognizes your sound cards then you can try to add them to PulseAudio manually with pacmd load-module module-alsa-sink device=hw:x,y where x and y is the device, subevice pair of aplay -l.
If it works correctly then you can append these commands to the default configuration of PulseAudio (/etc/pulse/default.pa). (I know that it's only a hack, but it works for me :)