Showing posts with label sleep. Show all posts
Showing posts with label sleep. Show all posts

Thursday, February 20, 2014

Suspend when Idle

E's power management features work well for the most part, but if you want your Chromebook to sleep when idle while working in the console (not running X), you're out of luck. One solution is powernap, which makes use of various "monitors" to determine whether the system is idle or not.

It doesn't work out of the box, but only a few simple edits are required.

After installing the package, first go edit /etc/default/powernap. You'll see these lines:

# start powernap at boot [yes|no]
START=no

Just change no to yes and save the file.

Next, head on over /etc/powernap. You'll see a file here called config. Open that up, and head over to the line that reads this:

[ConsoleMonitor] 
ptmx = y

For whatever reason, /dev/ptmx doesn't work for monitoring console activity in Chrubuntu, so change this to /dev/pts, so it reads:

[ConsoleMonitor]
pts = yes

[ UPDATE: You actually need to edit the powernap python script itself to get this to work. Head on over to /usr/share/pyshared/powernap/monitors/ConsoleMonitor.py and open it up in your favorite text editor. Skip down to line 38 and change the words "keyboard" and "mouse" to "cros_ec_keyb" and "cyapa" respectively. Then sudo service powernap restart. Note that these device names may vary depending on your version of the kernel / Ubuntu, you can see the full device list in /proc/interrupts. It may not be obvious which device is which.)

You'll probably also want ACTION_SECONDS from the default 30 to something more reasonable like 300 (5 minutes) once you're sure everything is working.

Powernap supports a sort of escalation, but if you just simply want your Chromebook to sleep when idle, you can change ACTION_METHOD from 0 (powersave) to 1 (suspend), and it will sleep immediately after ACTION_SECONDS expires.

The processor load monitor works fine when set to the default, but there's plenty of other monitors you can configure (disk activity, network activity, etc.) that ship inactive if you want more advanced idle detection.

Reboot to be safe, or you can try restarting the powernap service using sudo service powernap restart.

Using this method, sleep/wake works perfectly fine from within X (with Enlightenment's auto blanking turned off) or the console alike. I might use the same technique for auto dimming, because I've found E's built-in auto dimming feature to be somewhat flakey.

Lid sleep on the Chromebook

This is a pretty easy one. Make sure you have acpid installed and add a file called lid to the /etc/acpi/events folder that contains the following:

event=button/lid
action=/etc/acpi/lid.sh

Then, add a script in your /etc/acpi folder that contains this:

#!/bin/bash
if [ -f /var/lock/lidsleep ]; then
rm /var/lock/lidsleep
else
touch /var/lock/lidsleep
/usr/sbin/pm-suspend
fi

You can also add lid-specific sleep commands here if you desire, but I'd use /etc/pm/sleep.d for global sleep commands. Be sure to see the prior post on disabling the trackpad during sleep, or your Chromebook is going to wake up if you even look at it wrong.

Reboot or restart acpid and lid sleep should be working.

Wednesday, February 19, 2014

Disable the trackpad during sleep without X

One of the biggest gripes Chromebook users have reported is that the Chromebook wakes up too easily because of the trackpad. There are multiple solutions for this if you're running CrOS or X11, but if you're often using just the console, tricks like xinput and Chrosh's tpcontrol don't work.

But all is not.. naught! You can use the same technique described here for USB devices. First you need the identifier for the trackpad, though, which doesn't show up using lsusb.

You'll find your trackpad's identifier under /sys/bus/i2c/drivers/cyapa -- there should be a directory there called something like 1-0067. That's the identifier:

root@calculon:/sys/bus/i2c/drivers/cyapa$ ls
1-0067 bind  uevent  unbind

Next, using the trick from the above post, create a new script in /etc/pm/sleep.d. The file should contain:

#!/bin/bash
case $1 in
    hibernate|suspend)
        echo '1-0067' | tee /sys/bus/i2c/drivers/cyapa/unbind
    ;;
    thaw|resume)
        echo '1-0067' | tee /sys/bus/i2c/drivers/cyapa/bind
        ;;
    *)
        echo "Somebody is calling me totally wrong."
    ;;
esac

Moar battery life for all!