[N900/rx-51] switch between speakers/headphone with jack detection
This depends on #131 (closed).
For my N900 music player project, I need to switch the output from speakers to headphones. It would be nice if we could do this automatically when plugging in the headphones into the audio jack of the devices.
Inserting headphones triggers an acpi event as I can see in logread
:
Jan 1 01:59:59 nokia-n900 daemon.err acpid[1070]: HEADPHONE_INSERT
Removing the headphones does not generate a log message, but I'm pretty sure we could catch that as well. On this page I found a config (for a different acpi daemon) that makes it seem like the HEADPHONE_INSERT
event gets fired twice (with 0 and 1), so with the current code it's probably only printed when the value is 1. Usually such events are generated by buttons, that would mean we get log entries when buttons are released, not when they get pressed. If busybox' acpid isn't able to do this, there's also triggerhappy for example, which is used by charging-sdl already.
The N900 would be the reference device for implementing this (at least if I do it), but it should work the same way for other devices as well.
The plan:
-
write a nokia-n900-audio-output
script with one argument that is "speakers" or "headphones" (s|h). It should run alsa commands to switch the output between the two (extract the alsa commands from diffing these configs). -
add that to device-nokia-n900
and install it to/usr/bin
-
capture the acpi event for headphone insert, and trigger ${devicename}-audio-output "headphones"
(if the script exists) -
do the same for headphone removal -> trigger the script with the speakers argument
(When this is done, we can also implement that it pauses and continues mpd/mpris/... playback on headphones removal/insert.)