Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 23 Sep 2014, 20:29
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
pup_event_frontend_d supporting BATTERY CHECK
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Fri 01 Jun 2012, 20:42    Post subject:  pup_event_frontend_d supporting BATTERY CHECK
Subject description: for laptops
 

Code:
--- /initrd/pup_ro2/sbin/pup_event_frontend_d   2012-02-15 15:14:53.000000000 +0100
+++ /sbin/pup_event_frontend_d   2012-06-01 21:40:35.778876979 +0100

Code:
@@ -102,6 +142,26 @@ RETVALm=1
 PREVSIZETMPM=0
 PREVSIZEFREEM=0
 
+proc_acpi_func(){
+BAT_0_info_file=/proc/acpi/battery/BAT0/info
+BAT_0_state_file=/proc/acpi/battery/BAT0/state
+BAT_0='0'
+if [ -f "$BAT_0_info_file" -a -f "$BAT_0_info_file" ];then
+BAT_0_DESIGN_CAPACITY=`grep 'design capacity:' "$BAT_0_info_file"`
+BAT_0_DESIGN_CAPACITY="${BAT_0_DESIGN_CAPACITY//[^[:digit:]]/}"
+BAT_0_WARN=$((BAT_0_DESIGN_CAPACITY/15))
+BAT_0_CURRENT=`grep 'remaining capacity:' "$BAT_0_state_file"`
+BAT_0_CURRENT="${BAT_0_CURRENT//[^[:digit:]]/}"
+[ "$BAT_0_DESIGN_CAPACITY" -a "$BAT_0_CURRENT" ] && BAT_0='1'
+fi
+}
+proc_acpi_func
+echo "BAT_0_DESIGN_CAPACITY='$BAT_0_DESIGN_CAPACITY'
+BAT_0_CURRENT='$BAT_0_CURRENT'
+BAT_0_WARN='$BAT_0_WARN'
+BAT_0='$BAT_0'
+"
+
 #v424 experiment, automatic unmounting...
 auto_unmount_func() {
  for ONEMNTPT in `mount | grep '^/dev/' | grep -vE '^/dev/loop|^/dev/ram' | cut -f 3 -d ' ' | grep -v '^/initrd/' | grep -v '^/$' | tr '\n' ' '`

Code:
@@ -764,17 +824,30 @@ do
   touch /tmp/snapmergepuppyrequest #request to savepuppy_func.
   SAVECNT=0
  fi
- if [ $POWERTIMEOUT -ne 0 ];then #w007 power-off computer after inactivity.
+ MINUTECNT=$((MINUTECNT+4))
+ if [ $MINUTECNT -gt 59 ];then #come in here every minute...
+ MINUTECNT=0;echo "Next Minute"
+  if [ "$BAT_0" = '1' ];then echo "BAT_0 detected"
+  BAT_0_CURRENT=`grep 'remaining capacity:' "$BAT_0_state_file"`
+  BAT_0_CURRENT="${BAT_0_CURRENT//[^[:digit:]]/}"
+  echo "BAT_0_CURRENT='$BAT_0_CURRENT'"
+   if [ $BAT_0_CURRENT -lt $BAT_0_WARN ];then
+    aplay /usr/share/audio/2barks.au;aplay /usr/share/audio/2barks.au
+    pupmessage -bg red -timeout 30 "Battery State is: $BAT_0_CURRENT
+better to plug in ac adapter or poweroff the laptop "
+   fi #warn
+  fi #bat
+  if [ $POWERTIMEOUT -ne 0 ];then #w007 power-off computer after inactivity.
   MOUSECNT=`expr $MOUSECNT + 4`
-  MINUTECNT=`expr $MINUTECNT + 4`
-  if [ $MINUTECNT -gt 59 ];then #come in here every minute...
-   MINUTECNT=0
-   CURPOS2="`getcurpos`"
-   echo "MOUSECNT=$MOUSECNT CURPOS2=$CURPOS2" >> /tmp/pup_event_frontend_d_curpos.log
-   [ "$CURPOS1" = "" ] && CURPOS1="$CURPOS2"
-   [ "$CURPOS1" != "$CURPOS2" ] && MOUSECNT=0
-   CURPOS1="$CURPOS2"
-   [ $MOUSECNT -gt $POWERTIMEOUT ] && wmpoweroff &
+  #MINUTECNT=`expr $MINUTECNT + 4`
+   #if [ $MINUTECNT -gt 59 ];then #come in here every minute...
+    #MINUTECNT=0
+    CURPOS2="`getcurpos`"
+    #echo "MOUSECNT=$MOUSECNT CURPOS2=$CURPOS2" >> /tmp/pup_event_frontend_d_curpos.log
+    [ "$CURPOS1" = "" ] && CURPOS1="$CURPOS2"
+    [ "$CURPOS1" != "$CURPOS2" ] && MOUSECNT=0
+    CURPOS1="$CURPOS2"
+    [ $MOUSECNT -gt $POWERTIMEOUT ] && wmpoweroff &
   fi
  fi
  #some apps should not be disturbed by this background stuff...

NOTE 1:
I have only one netbook, the path to /proc/acpi/battery/BAT0/state might vary. Probably worth a tab in the eventmanager GUI.
NOTE 2:
Tested on two frugal installs and worked ok.
NOTE 3:
Might have too much debugging echo output.
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0531s ][ Queries: 11 (0.0096s) ][ GZIP on ]