109 mon_fd = udev_monitor_get_fd(mon); |
109 mon_fd = udev_monitor_get_fd(mon); |
110 static struct pollfd fds[1]; |
110 static struct pollfd fds[1]; |
111 fds[0].fd = mon_fd; |
111 fds[0].fd = mon_fd; |
112 fds[0].events = POLLIN; |
112 fds[0].events = POLLIN; |
113 #endif |
113 #endif |
|
114 char filename[PATH_MAX+1]; |
|
115 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/energy_now",argv[1]); |
|
116 struct stat st; |
|
117 int energy = 0==stat(filename, &st); |
114 while (1) { |
118 while (1) { |
115 char filename[PATH_MAX+1]; |
|
116 |
119 |
117 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/charge_now",argv[1]); |
120 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_now",argv[1], energy ? "energy" : "charge"); |
118 int charge_now = catint(filename); |
121 int charge_now = catint(filename); |
119 |
122 |
120 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/current_now",argv[1]); |
123 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_now",argv[1], energy ? "power" : "current"); |
121 int current_now = catint(filename); |
124 int current_now = catint(filename); |
122 |
125 |
123 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/charge_full",argv[1]); |
126 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_full",argv[1], energy ? "energy" : "charge"); |
124 int charge_full = catint(filename); |
127 int charge_full = catint(filename); |
125 |
128 |
126 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/status",argv[1]); |
129 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/status",argv[1]); |
127 char *status = catfile(filename); |
130 char *status = catfile(filename); |
128 |
131 |
131 char *arrow; |
134 char *arrow; |
132 |
135 |
133 remtimes_color = color_none; |
136 remtimes_color = color_none; |
134 if (!strcmp(status,"Charging")) { |
137 if (!strcmp(status,"Charging")) { |
135 if (current_now != 0) |
138 if (current_now != 0) |
136 remtime = ((charge_full-charge_now) * 60) / current_now; |
139 remtime = (charge_full-charge_now) / (current_now/60); |
137 arrow = "↑"; |
140 arrow = "↑"; |
138 arrow_color = color_orange; |
141 arrow_color = color_orange; |
139 } |
142 } |
140 else if (!strcmp(status,"Discharging")) { |
143 else if (!strcmp(status,"Discharging")) { |
141 if (current_now != 0) |
144 if (current_now != 0) |
142 remtime = (charge_now * 60) / current_now; |
145 remtime = charge_now / (current_now/60); |
143 arrow = "↓"; |
146 arrow = "↓"; |
144 arrow_color = color_none; |
147 arrow_color = color_none; |
145 remtimes_color = color(20,120,0,remtime); |
148 remtimes_color = color(20,120,0,remtime); |
146 } else { |
149 } else { |
147 arrow = "—"; |
150 arrow = "—"; |
151 snprintf(remtimes,127,"%d:%02d",remtime/60,remtime%60); |
154 snprintf(remtimes,127,"%d:%02d",remtime/60,remtime%60); |
152 //printf("%d %d %d %s %d %s %s\n",charge_now,current_now,charge_full, |
155 //printf("%d %d %d %s %d %s %s\n",charge_now,current_now,charge_full, |
153 // eights[charge_now*8/charge_full], charge_now*100/charge_full,status,remtimes); |
156 // eights[charge_now*8/charge_full], charge_now*100/charge_full,status,remtimes); |
154 |
157 |
155 |
158 |
156 int percent = charge_now*100/charge_full; |
159 int percent = charge_now/(charge_full/100); |
157 eights_color = percent_color = color(15,40,0,percent); |
160 eights_color = percent_color = color(15,40,0,percent); |
158 printf("%s%s%s ",eights_color,eights[charge_now*8/charge_full],color_stop); |
161 printf("%s%s%s ",eights_color,eights[charge_now*8/charge_full],color_stop); |
159 printf("%s%d%%%s ",percent_color,percent,color_stop); |
162 printf("%s%d%%%s ",percent_color,percent,color_stop); |
160 printf("%s%s%s ",arrow_color,arrow,color_stop); |
163 printf("%s%s%s ",arrow_color,arrow,color_stop); |
161 printf("%s%s%s\n",remtimes_color,remtimes,color_stop); |
164 printf("%s%s%s\n",remtimes_color,remtimes,color_stop); |