Auto-detecting a USB Headset

July 3rd, 2009

After a lot of trial and error today, I’ve still only gotten part of the way to my objective: making my new Plantronics USB headset get auto-detected in Gentoo, and make it my “primary” ALSA device. That is, when it’s plugged in, all audio goes to it, and when it’s not, all audio goes to the speakers. Much, much easier said than done.

The first hurdle was coming to the realization that ALSA in fact sees this headset as its own sound card. Once I got that far (it took me a while, with some help on IRC), all I needed in the end was 4 additional lines in my /etc/modprobe.d/alsa file:

alias snd-card-0 snd-hda-intel
alias sound-slot-0 snd-hda-intel
options snd-hda-intel index=1

alias snd-card-1 snd-usb-audio
alias sound-slot-1 snd-usb-audio
options snd-usb-audio index=0

The first 2 lines were already there, and then I added the two lines about snd-card-1 and sound-slot-1. Easy enough. The other two lines (not counting the whitespace) are to tell the system what order they go in. 0 is primary, 1 is second, etc. So by having index=0 for snd-usb-audio, that device is my first card, and the on-board is my second. Easy enough. I kept getting fouled up in testing my various configs by not actually removing the modules; I was just restarting ALSA. Not good. Once I got that config working, I wrote a couple of bash scripts to flip those variables, update the configs, etc. Here's my "on" script:

#!/bin/bash
# Script to swtich around audio devices when headset plugged in
if ( grep -q "options snd-usb-audio index=0" /etc/modprobe.d/alsa )
then
echo "Exiting..."
exit 1
fi

sed -i '/options snd-hda-intel/ s/0/1/' /etc/modprobe.d/alsa
sed -i '/options snd-usb-audio/ s/1/0/' /etc/modprobe.d/alsa
update-modules -f
/etc/init.d/alsasound stop
sleep 0.5
modprobe -r snd-usb-audio
modprobe -r snd-hda-intel
/etc/init.d/alsasound start
sleep 0.5
/etc/init.d/mpd start

It's simple enough, in retrospect, and it works. The "off" script is identical except it does the reverse flip at the beginning. I could have made it one script, but whatever.

The next step was to make this all happen automatically. That's where I'm stuck. I've been tinkering with udev for hours now, and I can't seem to write the rules right. My current rules look like this:

ATTRS{id}=="U0x47f0xc001", ACTION=="add", RUN+="/home/dfego/bin/udev-headset-on.sh", ENV{IS_PLANTRON}="yes"
ENV{IS_PLANTRON}=="yes", ACTION=="remove", RUN+="/home/dfego/bin/udev-headset-off.sh"

I don't even remember now if this particular "add" works, but some of the ones I wrote today did. However, not one, not a single one of my "remove" lines worked. All day. None of them. It's almost depressing. For some God-forsaken reason, I can't make anything trigger on a remove event. So I tried using a single script and having it go on all events, but that fell on its face because udev insists on running it lots and lots of times every time an event happens, even when I built protections into the script that it couldn't run more than once simultaneously. So I don't know what to do. For now, I'm just going to be happy with what I've done and use the script. It's not like I plug my headset in and out all that often (except, of course, today). But I feel sad and defeated, and very much like I wasted a ton of time doing something that doesn't work for some reason beyond my comprehension. It should work... it just doesn't.

Maybe I'll try again one of these days. Maybe not.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Technorati

Uncategorized

Software Suspend on GNOME Desktop

June 14th, 2009

I just wrote a short article on the above topic, and then, not long before hitting “Publish,” I find this article that has the answer in short, simple terms. So if you’re having any issues having the “Suspend” dialog work on your GNOME desktop, give the above link a try. I figure I should spare everyone from my often verbose ramblings when someone’s already got the answer. :)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Technorati

linux , ,

Chat Logs and “The Cloud”

June 13th, 2009

At the end of 2007, Google did a wonderful thing and added AIM to their built-in chat in Gmail. This was an awesome convenience, since I could now chat with both my used protocols right from my email window. Not to mention I got a nice consolidation of my chat logs accessible from anywhere to boot. Of course, I was leaving all the conveniences of my desktop client behind, such as not being dependent on my browser window to chat. But it seemed all worthwhile, since I usually had a browser window open anyway, and I didn’t have a ton of spare resources (RAM, screen real estate) on my laptop, my sole machine.

Now I’m in the situation where I want to go back to the desktop client. I’ve got a nice new computer with lots of RAM and lots of screen real estate. But I’m now slightly dismayed, because my wonderfully accessible chat logs are now no longer going to be “all” with my mail. I say “all” because before a certain point they weren’t, but from that point on, I was golden. Now, if I switch back, I’ll have all my logs to a certain point on my computer, then a bunch in “the cloud,” and then most of them on my desktop, and some in my browser, for when I’m away from my computer. Not ideal.

What I really want it some “neutral” location for my logs that both the Gmail client and my desktop application (currently Pidgin) will respect and send their logs to. I’ve got web space out there, so I’ve got a location, but how to make it work? One way I could think of is to run something like a Greasemonkey script which keeps track of what it’s sent over time (so when I come back to the computer it’s installed on, it sends the new conversations) and sends new conversations off periodically. So that could be done with Greasemonkey, or with a Firefox Plugin. A modification to Pidgin sounds relatively trivial to me at this point, at least compared to writing a Firefox plugin. In any case, I’m going to ponder this… Any thoughts on the matter, technical or otherwise, are welcome.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Technorati

Uncategorized