Enlightenment CVS committal

Author  : xstasi
Project : e17
Module  : apps/e

Dir     : e17/apps/e/src/modules/battery


Modified Files:
        e_mod_main.c 


Log Message:
fixed bug on ibooks that would display -0% battery - now it displays all info 
correctly
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/e/src/modules/battery/e_mod_main.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -3 -r1.68 -r1.69
--- e_mod_main.c        20 Feb 2006 19:09:50 -0000      1.68
+++ e_mod_main.c        4 Mar 2006 12:36:42 -0000       1.69
@@ -1007,6 +1007,7 @@
    int voltage;
    int charge;
    int max_charge;
+   double tmp;
    Status *stat;
 
    stat = E_NEW(Status, 1);
@@ -1043,22 +1044,22 @@
 
                  while (fgets (buf,sizeof (buf), f))
                    {
-                      if ((token = strtok (buf, ":\n")))
+                      if ((token = strtok (buf, ":")))
                         {
                            if (!strncmp ("flags", token, 5))
-                             flags = axtoi (strtok (0, ":\n"));
-                           else if (!strncmp ("charge", token, 6))
-                             charge = atoi(strtok(0, ":\n"));
+                             flags = axtoi (strtok (0, ": "));
+                           else if (!strncmp ("charge", token, 6)) 
+                             charge = atoi(strtok(0, ": "));
                            else if (!strncmp ("max_charge", token, 9))
-                             max_charge += atoi (strtok(0,":\n"));
+                             max_charge = atoi (strtok(0,": "));
                            else if (!strncmp ("current", token, 7))
-                             current = atoi (strtok(0, ":\n"));
+                             current = atoi (strtok(0, ": "));
+                           else if (!strncmp ("time rem", token, 8))
+                             time = atoi (strtok(0, ": "));
                            else if (!strncmp ("voltage", token, 7))
-                             voltage = atoi (strtok(0,":\n"));
-                           else if (!strncmp ("time rem.", token, 8))
-                             time = atoi (strtok(0, ":\n"));
+                             voltage = atoi (strtok(0,": "));
                            else
-                             strtok (0,":\n");
+                             strtok (0,": ");
                         }
                    }
                  /* Skip flag;
@@ -1078,7 +1079,7 @@
                   */
                  fclose(f);
 
-                 battery++;
+                 battery = 1;
                  if (!current)
                    {
                       /* Neither charging nor discharging */
@@ -1086,21 +1087,21 @@
                  else if (!ac)
                    {
                       /* When on dc, we are discharging */
-                      discharging++;
+                      discharging = 1;
                       seconds += time;
                    }
                  else
                    {
                       /* Charging */
-                      charging++;
+                      charging = 1;
                       /* Charging works in paralell */
                       seconds = MAX(time, seconds);
                    }
+
               }
          }
        ecore_list_destroy(bats);
      }
-
    hours = seconds / (60 * 60);
    seconds -= hours * (60 * 60);
    minutes = seconds / 60;
@@ -1109,6 +1110,7 @@
    if (hours < 0) hours = 0;
    if (minutes < 0) minutes = 0;
 
+   
    if (!battery)
      {
        stat->has_battery = 0;
@@ -1136,7 +1138,11 @@
          }
        stat->level = (double)charge / (double)max_charge;
        if (stat->level > 1.0) stat->level = 1.0;
-       snprintf(buf, sizeof(buf), "%.0f%%", stat->level * 100.0);
+       tmp = (double)max_charge / 100;
+       tmp = (double)charge / tmp;
+       stat->level = (double)tmp / 100;
+
+       snprintf(buf, sizeof(buf), "%.0f%%", tmp);
        stat->reading = strdup(buf);
        snprintf(buf, sizeof(buf), "%i:%02i", hours, minutes);
        stat->time = strdup(buf);




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to