fixed issue 84 with battery
git-svn-id: http://tint2.googlecode.com/svn/trunk@75 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
01b6e81b8c
commit
88661d034a
3 changed files with 32 additions and 5 deletions
|
@ -54,27 +54,27 @@ void update_battery(struct batstate *data) {
|
||||||
fgets(tmp, sizeof tmp, fp);
|
fgets(tmp, sizeof tmp, fp);
|
||||||
energy_now = atoi(tmp);
|
energy_now = atoi(tmp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else printf("ERROR: battery applet can't open energy_now\n");
|
}
|
||||||
|
|
||||||
fp = fopen("/sys/class/power_supply/BAT0/energy_full", "r");
|
fp = fopen("/sys/class/power_supply/BAT0/energy_full", "r");
|
||||||
if(fp != NULL) {
|
if(fp != NULL) {
|
||||||
fgets(tmp, sizeof tmp, fp);
|
fgets(tmp, sizeof tmp, fp);
|
||||||
energy_full = atoi(tmp);
|
energy_full = atoi(tmp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else printf("ERROR: battery applet can't open energy_full\n");
|
}
|
||||||
|
|
||||||
fp = fopen("/sys/class/power_supply/BAT0/current_now", "r");
|
fp = fopen("/sys/class/power_supply/BAT0/current_now", "r");
|
||||||
if(fp != NULL) {
|
if(fp != NULL) {
|
||||||
fgets(tmp, sizeof tmp, fp);
|
fgets(tmp, sizeof tmp, fp);
|
||||||
current_now = atoi(tmp);
|
current_now = atoi(tmp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else printf("ERROR: battery applet can't open current_now\n");
|
}
|
||||||
|
|
||||||
fp = fopen("/sys/class/power_supply/BAT0/status", "r");
|
fp = fopen("/sys/class/power_supply/BAT0/status", "r");
|
||||||
if(fp != NULL) {
|
if(fp != NULL) {
|
||||||
fgets(tmp, sizeof tmp, fp);
|
fgets(tmp, sizeof tmp, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else printf("ERROR: battery applet can't open status");
|
}
|
||||||
|
|
||||||
data->state = BATTERY_UNKNOWN;
|
data->state = BATTERY_UNKNOWN;
|
||||||
if(strcasecmp(tmp, "Charging\n")==0) data->state = BATTERY_CHARGING;
|
if(strcasecmp(tmp, "Charging\n")==0) data->state = BATTERY_CHARGING;
|
||||||
|
@ -110,8 +110,10 @@ void update_battery(struct batstate *data) {
|
||||||
data->percentage = new_percentage;
|
data->percentage = new_percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void init_battery()
|
void init_battery()
|
||||||
{
|
{
|
||||||
|
FILE *fp;
|
||||||
Panel *panel;
|
Panel *panel;
|
||||||
Battery *battery;
|
Battery *battery;
|
||||||
int i, bat_percentage_height, bat_percentage_height_ink, bat_time_height, bat_time_height_ink;
|
int i, bat_percentage_height, bat_percentage_height_ink, bat_time_height, bat_time_height_ink;
|
||||||
|
@ -126,6 +128,30 @@ void init_battery()
|
||||||
battery->area._resize = resize_battery;
|
battery->area._resize = resize_battery;
|
||||||
|
|
||||||
if (!battery->area.on_screen) continue;
|
if (!battery->area.on_screen) continue;
|
||||||
|
if((fp = fopen("/sys/class/power_supply/BAT0/energy_now", "r")) == NULL) {
|
||||||
|
fprintf(stderr, "ERROR: battery applet can't open energy_now\n");
|
||||||
|
panel->battery.area.on_screen = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
if((fp = fopen("/sys/class/power_supply/BAT0/energy_full", "r")) == NULL) {
|
||||||
|
fprintf(stderr, "ERROR: battery applet can't open energy_full\n");
|
||||||
|
panel->battery.area.on_screen = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
if((fp = fopen("/sys/class/power_supply/BAT0/current_now", "r")) == NULL) {
|
||||||
|
fprintf(stderr, "ERROR: battery applet can't open current_now\n");
|
||||||
|
panel->battery.area.on_screen = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
if((fp = fopen("/sys/class/power_supply/BAT0/status", "r")) == NULL) {
|
||||||
|
fprintf(stderr, "ERROR: battery applet can't open status");
|
||||||
|
panel->battery.area.on_screen = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
battery->area.posy = panel->area.pix.border.width + panel->area.paddingy;
|
battery->area.posy = panel->area.pix.border.width + panel->area.paddingy;
|
||||||
battery->area.height = panel->area.height - (2 * battery->area.posy);
|
battery->area.height = panel->area.height - (2 * battery->area.posy);
|
||||||
|
|
|
@ -468,7 +468,8 @@ void event_timer()
|
||||||
if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
|
if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
|
||||||
|
|
||||||
// update battery
|
// update battery
|
||||||
update_battery(&battery_state);
|
if (panel1[0].battery.area.on_screen)
|
||||||
|
update_battery(&battery_state);
|
||||||
|
|
||||||
// update clock
|
// update clock
|
||||||
time_clock.tv_sec = stv.tv_sec;
|
time_clock.tv_sec = stv.tv_sec;
|
||||||
|
|
BIN
src/tint2
BIN
src/tint2
Binary file not shown.
Loading…
Reference in a new issue