[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to send a function when the laptop Lid is closed ?(acpi)



This probably should have gone to debian-laptop, rather than
debian-user.  However...

On Dec 9, 2007 6:36 AM, Jabka Atu <mashrom.head@gmail.com> wrote:
> i tried creating the next file in /etc/acpi/event :
> /etc/acpi/events# cat ./lid
> event=button[/]lid
> action=touch /tmp/lidfilename

I have the following as /etc/acpi/sleep_button:
event=button/sleep
action=/etc/acpi/sleep.sh

The sleep.sh script is then:
---[ begin sleep.sh ]---
#!/bin/sh

# if launched through a lid event and lid is open, do nothing
echo "$1" | grep "button/lid" && grep -q open
/proc/acpi/button/lid/LID/state && exit 0

# remove USB 1.1 driver
rmmod uhci_hcd

# sync filesystem and clock
sync
/sbin/hwclock --systohc

# switch to console
FGCONSOLE=`fgconsole`
chvt 6
#/usr/sbin/radeontool light off

# go to sleep
sleep 5 && echo -n "mem" > /sys/power/state

# readjust the clock (it might be off a bit after suspend)
/sbin/hwclock --adjust
/sbin/hwclock --hctosys

# reload USB 1.1 driver
modprobe uhci_hcd

# turn on the backlight and switch back to X
#radeontool light on
chvt $FGCONSOLE

# get alsa to actually play sound again -- very hackish
/usr/bin/amixer set Master toggle; /usr/bin/amixer set Master toggle
/usr/bin/amixer set PCM toggle; /usr/bin/amixer set PCM toggle
---[ end sleep.sh ]---

I cribbed this from somewhere (I can't recall where), with the amixer
tweaks at the end because my sound appears to always be disabled when
the laptop wakes up.  It's not toggled to the "off" setting, though,
which is why I toggle Master and PCM twice each.

-- 
Michael A. Marsh
http://www.umiacs.umd.edu/~mmarsh
http://mamarsh.blogspot.com
http://36pints.blogspot.com



Reply to: