Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
moetunes committed Nov 22, 2011
1 parent 30ae4f7 commit a5de3bd
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions power_mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define SYS_FILE "/sys/class/power_supply/BAT0/uevent"

static char *text = "";
static char text1[80] = "";
static char text1[30] = "";


int window_loop(){
Expand All @@ -17,21 +17,19 @@ int window_loop(){
Window win;
XEvent ev;
Display *dis;

char *fontname;
XFontStruct *font;
int text_width, text_width1;
int texty;
int text_width, text_width1, texty;

/* First connect to the display server, as specified in the DISPLAY environment variable. */
dis = XOpenDisplay(NULL);
if (!dis) {fprintf(stderr, "\033[0;31mUnable to connect to display\033[0m");return 7;}
if (!dis) {fprintf(stderr, "\033[0;31mUnable to connect to display\033[0m");return 1;}

screen_num = DefaultScreen(dis);
background = BlackPixel(dis, screen_num);
border = WhitePixel(dis, screen_num);
width = (XDisplayWidth(dis, screen_num)/4);
height = (XDisplayHeight(dis, screen_num)/5);
width = (XDisplayWidth(dis, screen_num)/5);
height = (XDisplayHeight(dis, screen_num)/6);
fontname = "-*-freesans-*-*-*";
font = XLoadQueryFont(dis, fontname);
if (!font) {
Expand All @@ -41,7 +39,7 @@ int window_loop(){
GC pen;
XGCValues values;

win = XCreateSimpleWindow(dis, DefaultRootWindow(dis),width*3-20,height*4-20,width,height,2,border,background);
win = XCreateSimpleWindow(dis, DefaultRootWindow(dis),width*4-20,height*5-20,width,height,2,border,background);

/* create the pen to draw lines with */
values.foreground = WhitePixel(dis, screen_num);
Expand Down Expand Up @@ -82,20 +80,20 @@ int window_loop(){
}
}

int main(void) {
FILE *Batt ;
int main(void) {
FILE *Batt;
char buffer[80];
char *battstatus, *chargenow, *lastfull;
int battdo, dummy ;
int battdo, dummy;
long nowcharge, fullcharge;

Batt = fopen( SYS_FILE, "r" ) ;
if ( Batt == NULL ) {
fprintf(stderr, "Couldn't find %s \n", SYS_FILE);
return(0) ;
} else {
Batt = fopen( SYS_FILE, "r" ) ;
if ( Batt == NULL ) {
fprintf(stderr, "\t\033[0;31mCouldn't find %s\033[0m \n", SYS_FILE);
return(0) ;
} else {
while(fgets(buffer,sizeof buffer,Batt) != NULL) {
/* Now look for info */
/* Now look for info */
if(strstr(buffer,"POWER_SUPPLY_STATUS") != NULL) {
battstatus = strstr(buffer, "=");
//printf("%s\n", battstatus);
Expand Down Expand Up @@ -124,16 +122,16 @@ int main(void) {
fclose(Batt);

dummy = ((float)nowcharge/fullcharge)*100;
if(dummy <= 37 && battdo == 2 || battdo >= 3) {
if((dummy <= 37 && battdo == 2) || battdo >= 3) {
if(battdo == 1) text = "Power Supply Charging";
if(battdo == 2) text = "Power Supply Discharging";
if(battdo == 3) text = "Power Supply Charged";
if(battdo == 4) text = "Power Supply Full";
if(battdo == 5) text = "Power Supply Unknown !!";
snprintf(text1, 79, "Remaining Charge %d %%", dummy);
snprintf(text1, 29, "Remaining Charge %d %%", dummy);
window_loop();
}

return 0;
return 0;
}
}

0 comments on commit a5de3bd

Please sign in to comment.