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

Re: setup apm for 'battery low' warning on textconsole



Liked it, adapted acpi_percent so it will work with
two (or more presumably) batteries.  Also detects bay w/o
battery.  Also removed BAT0 dependency since mine are
numbered 1 and 2.

function acpi_percent()
{
 for BATDIR in /proc/acpi/battery/BAT*
 do
   BATTERY=$(basename $BATDIR)
   CAPACITY=$(cat $BATDIR/info |grep "design capacity:"|cut -d' ' -f11)
   if [ -n "$CAPACITY" ]
   then
     LEVEL=$(cat $BATDIR/state | grep remaining|cut -d' ' -f8)
     ACPI_PERCENT=`echo $(( $LEVEL * 100 / $CAPACITY ))`
     if [ "$LEVEL" = "$CAPACITY" ]; then
       echo "$BATTERY: full"
     else
       echo "$BATTERY: $ACPI_PERCENT%"
     fi
   else
     echo "$BATTERY: no data"
   fi
 done
}

Of course, now I broke the color stuff.  I'm not sure what
color you would want if one battery is dead but the other is
fine.  Perhaps base the color on the average?  Or do you
want to know the one is dead by color so you can swap it
out.  I'll leave such deep questions to those who can afford
more than two ;)

On Sun, Mar 02, 2003 at 11:25:06AM +0100, Fabio Sirna wrote:
> Alle feb 13 at 11:36, Jason Kraftcheck scrisse:
> 
> >Here's some junk from my .bashrc to color the shell prompt according to 
> >the battery life:
> 
> I change your script for the ACPI :) It's great :)
> 
> if [ `cat /proc/acpi/battery/BAT0/state | grep present: |cut -d\  -f18` = "yes" ]; then
> 
> function acpi_percent()
> {
>  CAPACITY=`cat /proc/acpi/battery/BAT0/info |grep "design capacity:"|cut -d\  -f11`
>  LEVEL=`cat /proc/acpi/battery/BAT0/state | grep remaining|cut -d\  -f8`
>  ACPI_PERCENT=`echo $(( $LEVEL * 100 / $CAPACITY ))`
>  if [ "$LEVEL" = "$CAPACITY" ]; then 
>   echo full
>  else
>   echo $ACPI_PERCENT%
>  fi
> }
> 
> function acpi_charge()
> {
>  ACPI_CHARGE=`cat /proc/acpi/ac_adapter/AC/state | cut -d\  -f20`
>  case $ACPI_CHARGE in
>        *on-line*)
>          ACPI_CHARGE="+" ;;
>        *off-line*)
>          ACPI_CHARGE="-" ;;
>      esac
>      echo $ACPI_CHARGE
> }
> 
> function acpi_color()
>    {
>      if  [  "$(acpi_charge)"  =  "+"  ];  then
>        echo  "1;32"
>      else
>        case  $(acpi_percent)  in
>           10?%)  echo  "0;32"  ;;
>            9?%)  echo  "0;32"  ;;
>            8?%)  echo  "0;32"  ;;
>            7?%)  echo  "0;32"  ;;
>            6?%)  echo  "0;32"  ;;
>            5?%)  echo  "0;32"  ;;
>            4?%)  echo  "0;33"  ;;
>            3?%)  echo  "0;33"  ;;
>            2?%)  echo  "0;33"  ;;
>            1?%)  echo  "0;31"  ;;
>             ?%)  echo  "0;31;5"  ;;
>              *)  echo  "0;35"  ;;
>        esac
>      fi
>    }
> 
> function  acpi_color_prompt
>    {
>      PS1='\[\e[$(acpi_color)m\][$(acpi_charge)$(acpi_percent)][\t] \u:\w\$>\[\e[0;37m\] '
>      #PS1="\[\e[$(acpi_color)m\]\h\$\[\e[0m\]  "
>    }
> 
>    #  linux  console
>    if  [  "$TERM"  =  "linux"  ];  then
>      PROMPT_COMMAND=acpi_color_prompt
>    fi
> 
>    function  echo_acpi
>    {
>      echo -n "($(acpi_charge)$(acpi_percent)) "
>    }
> 
>    #  alternately echo apm state before prompt
>    #  PROMPT_COMMAND = echo_apm
> 
> else PS1='\[\e[0;31m\][no battery][\t] \u:\w\$>\[\e[0;37m\] '
> 
> fi
> 
> -- 
> Fabio
> _____________________________________________________________________
> Envie de discuter en "live" avec vos amis ? T?l?charger MSN Messenger
> http://www.ifrance.com/_reloc/m la 1?re messagerie instantan?e de France
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-laptop-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> 



Reply to: