Ubuntu 10.04 and Jupiter

I've been experimenting with Jupiter (currently version 0.0.51) on my Ubuntu 10.04 notebook to see if I could improve the battery life on this old System76 Serval (version 5). Though there is the applet built in Mono to that is accessible to the user to quickly adjust a few options, the real meat are the scripts it places under /usr/lib/jupiter that are run a notebook is placed on AC power or not.

Unfortunately, it looked like the scripts were not detecting whether the notebook was running on AC or battery power properly. While looking around those scripts, I think I found the problem in /usr/lib/jupiter/scripts/state. In the script on line 10, it looks for an AC device in /sys/class/power_supply that contains either a ADP or AC in the name, and on the next line it points to the online file in that device.

Unfortunately, on my Ubuntu 10.04 setup, there was no device with that name, only the battery was shown with the name BAT0. In this device, there is the file status available that seems to contain either "Discharging", "Charging", or "Full" (and possibly other states) depending on the current status of the battery.

With this knowledge, I updated the /usr/lib/jupiter/scripts/state script use this as a backup check in case the original method failed:

#!/bin/bash
# 
# Reports current CPU state
#

JUPITER_PATH="/usr/lib/jupiter/scripts"
JUPITER_KERNEL="/usr/lib/jupiter/kernel"
JUPITER_VAR="/var/jupiter"

AC_DEVICE=$(ls /sys/class/power_supply | grep "ADP\|AC")
BAT_DEVICE=$(ls /sys/class/power_supply | grep "BAT")
ACPI_AC_PROC=/sys/class/power_supply/$AC_DEVICE/online
BAT_PROC=/sys/class/power_supply/$BAT_DEVICE/status

function report_mode {
    if [ -e "$ACPI_AC_PROC" ]; then
      if [ "$(cat $ACPI_AC_PROC)" = "1" ]; then
        echo power
      else
        echo battery
      fi
    elif [ -e "$BAT_PROC" ]; then
      BAT_STATUS="$(cat $BAT_PROC)"
      if [ $BAT_STATUS == "Discharging" ]; then
        echo battery
      else
        echo power
      fi
    else
      echo UNKNOWN
    fi
}

case "$1" in
  *) report_mode
  ;;
esac

If this works, I'll have to submit this change to the Jupiter projects at some point.

Comments

it works!!!!