Site Tools


headphones_insertion_handling

Automatically switch off speakers when headphones plugged in

Install input-event-daemon

wget http://flie.no-ip.org:7080/ac100/deb/input-event-daemon_0.1.3-1_armhf.deb
sudo dpkg -i input-event-daemon_0.1.3-1_armhf.deb

/etc/input-event-daemon.conf:

[Global]
listen = /dev/input/by-path/platform-tegra-alc5632.0-event
listen = /dev/input/event2
listen = /dev/input/event3
listen = /dev/input/event4
 
[Keys]
POWER = systemctl suspend
#POWER = systemctl poweroff
#MUTE         = amixer -q set Master mute
#CTRL+ALT+ESC = beep
 
[Switches]
HEADPHONE_INSERT:0 = amixer set 'Int Spk' on
HEADPHONE_INSERT:1 = amixer set 'Int Spk' off
LID:1 = /usr/bin/brightness off
LID:0 = /usr/bin/brightness on
#LID:0 = DISPLAY=:0 XAUTHORITY=/home/user/.Xauthority xset dpms force on
#LID:1 = DISPLAY=:0 XAUTHORITY=/home/user/.Xauthority xset dpms force off

/usr/bin/brightness:

#!/bin/bash

[ x"$1" == x ] && exit 1
bfile=/sys/devices/platform/pwm-backlight/backlight/pwm-backlight/brightness
curbr=$(cat $bfile)
brsave=/etc/brightness
minbr=5

case $1 in
  on)
    br=$(cat $brsave)
    if (($br >= $minbr))
    then
      echo -n $br > $bfile
    else
      echo -n $minbr > $bfile
    fi
    exit 0
  ;;
  off)
    echo $curbr > $brsave
    echo 0 > $bfile
    exit 0
  ;;
esac
let "newbr=curbr $1"
if (( 5 < $newbr && $newbr < 255 ))
then
  echo -n $newbr > $bfile
fi

Done! Now you can put in you earphones and speakers will be switched off. And you screen backlight should switch off when lid closed and restore when its open.

headphones_insertion_handling.txt · Last modified: 2012/11/17 00:44 by fly-away