forked from enlightenment/enlightenment
fixed bug on ibooks that would display -0% battery - now it displays all info correctly
SVN revision: 21002
This commit is contained in:
parent
4b607a4cfb
commit
ed715bb41a
|
@ -1007,6 +1007,7 @@ _battery_linux_powerbook_check(Battery *ef)
|
||||||
int voltage;
|
int voltage;
|
||||||
int charge;
|
int charge;
|
||||||
int max_charge;
|
int max_charge;
|
||||||
|
double tmp;
|
||||||
Status *stat;
|
Status *stat;
|
||||||
|
|
||||||
stat = E_NEW(Status, 1);
|
stat = E_NEW(Status, 1);
|
||||||
|
@ -1043,22 +1044,22 @@ _battery_linux_powerbook_check(Battery *ef)
|
||||||
|
|
||||||
while (fgets (buf,sizeof (buf), f))
|
while (fgets (buf,sizeof (buf), f))
|
||||||
{
|
{
|
||||||
if ((token = strtok (buf, ":\n")))
|
if ((token = strtok (buf, ":")))
|
||||||
{
|
{
|
||||||
if (!strncmp ("flags", token, 5))
|
if (!strncmp ("flags", token, 5))
|
||||||
flags = axtoi (strtok (0, ":\n"));
|
flags = axtoi (strtok (0, ": "));
|
||||||
else if (!strncmp ("charge", token, 6))
|
else if (!strncmp ("charge", token, 6))
|
||||||
charge = atoi(strtok(0, ":\n"));
|
charge = atoi(strtok(0, ": "));
|
||||||
else if (!strncmp ("max_charge", token, 9))
|
else if (!strncmp ("max_charge", token, 9))
|
||||||
max_charge += atoi (strtok(0,":\n"));
|
max_charge = atoi (strtok(0,": "));
|
||||||
else if (!strncmp ("current", token, 7))
|
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))
|
else if (!strncmp ("voltage", token, 7))
|
||||||
voltage = atoi (strtok(0,":\n"));
|
voltage = atoi (strtok(0,": "));
|
||||||
else if (!strncmp ("time rem.", token, 8))
|
|
||||||
time = atoi (strtok(0, ":\n"));
|
|
||||||
else
|
else
|
||||||
strtok (0,":\n");
|
strtok (0,": ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Skip flag;
|
/* Skip flag;
|
||||||
|
@ -1078,7 +1079,7 @@ _battery_linux_powerbook_check(Battery *ef)
|
||||||
*/
|
*/
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
battery++;
|
battery = 1;
|
||||||
if (!current)
|
if (!current)
|
||||||
{
|
{
|
||||||
/* Neither charging nor discharging */
|
/* Neither charging nor discharging */
|
||||||
|
@ -1086,21 +1087,21 @@ _battery_linux_powerbook_check(Battery *ef)
|
||||||
else if (!ac)
|
else if (!ac)
|
||||||
{
|
{
|
||||||
/* When on dc, we are discharging */
|
/* When on dc, we are discharging */
|
||||||
discharging++;
|
discharging = 1;
|
||||||
seconds += time;
|
seconds += time;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Charging */
|
/* Charging */
|
||||||
charging++;
|
charging = 1;
|
||||||
/* Charging works in paralell */
|
/* Charging works in paralell */
|
||||||
seconds = MAX(time, seconds);
|
seconds = MAX(time, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ecore_list_destroy(bats);
|
ecore_list_destroy(bats);
|
||||||
}
|
}
|
||||||
|
|
||||||
hours = seconds / (60 * 60);
|
hours = seconds / (60 * 60);
|
||||||
seconds -= hours * (60 * 60);
|
seconds -= hours * (60 * 60);
|
||||||
minutes = seconds / 60;
|
minutes = seconds / 60;
|
||||||
|
@ -1109,6 +1110,7 @@ _battery_linux_powerbook_check(Battery *ef)
|
||||||
if (hours < 0) hours = 0;
|
if (hours < 0) hours = 0;
|
||||||
if (minutes < 0) minutes = 0;
|
if (minutes < 0) minutes = 0;
|
||||||
|
|
||||||
|
|
||||||
if (!battery)
|
if (!battery)
|
||||||
{
|
{
|
||||||
stat->has_battery = 0;
|
stat->has_battery = 0;
|
||||||
|
@ -1136,7 +1138,11 @@ _battery_linux_powerbook_check(Battery *ef)
|
||||||
}
|
}
|
||||||
stat->level = (double)charge / (double)max_charge;
|
stat->level = (double)charge / (double)max_charge;
|
||||||
if (stat->level > 1.0) stat->level = 1.0;
|
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);
|
stat->reading = strdup(buf);
|
||||||
snprintf(buf, sizeof(buf), "%i:%02i", hours, minutes);
|
snprintf(buf, sizeof(buf), "%i:%02i", hours, minutes);
|
||||||
stat->time = strdup(buf);
|
stat->time = strdup(buf);
|
||||||
|
|
Loading…
Reference in New Issue