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 Sat 25 Oct 2014, 03:23
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 Posts_count_1  
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
Sub_title: 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_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count_1  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0492s ][ Queries: 12 (0.0058s) ][ GZIP on ]