113 #endif |
114 #endif |
114 char filename[PATH_MAX+1]; |
115 char filename[PATH_MAX+1]; |
115 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/energy_now",argv[1]); |
116 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/energy_now",argv[1]); |
116 struct stat st; |
117 struct stat st; |
117 int energy = 0==stat(filename, &st); |
118 int energy = 0==stat(filename, &st); |
|
119 int sleeptime = UPDATE_PERIOD; |
|
120 #ifdef DRAIN_THE_FUCK |
|
121 int alertflash = 1; |
|
122 #endif |
118 while (1) { |
123 while (1) { |
119 |
124 |
120 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_now",argv[1], energy ? "energy" : "charge"); |
125 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_now",argv[1], energy ? "energy" : "charge"); |
121 int charge_now = catint(filename); |
126 int charge_now = catint(filename); |
122 |
127 |
128 |
133 |
129 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/status",argv[1]); |
134 snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/status",argv[1]); |
130 char *status = catfile(filename); |
135 char *status = catfile(filename); |
131 |
136 |
132 int remtime = 0; |
137 int remtime = 0; |
133 char remtimes[128]; |
|
134 char *arrow; |
138 char *arrow; |
135 |
139 |
136 remtimes_color = color_none; |
140 remtimes_color = color_none; |
137 if (!strcmp(status,"Charging")) { |
141 if (!strcmp(status,"Charging")) { |
138 if (current_now != 0) |
142 if (current_now != 0) |
141 arrow_color = color_orange; |
145 arrow_color = color_orange; |
142 } |
146 } |
143 else if (!strcmp(status,"Discharging")) { |
147 else if (!strcmp(status,"Discharging")) { |
144 if (current_now != 0) |
148 if (current_now != 0) |
145 remtime = charge_now / (current_now/60); |
149 remtime = charge_now / (current_now/60); |
146 arrow = "↓"; |
150 arrow = down_arrow; |
147 arrow_color = color_none; |
151 arrow_color = color_none; |
148 remtimes_color = color(20,120,0,remtime); |
152 remtimes_color = color(20,120,0,remtime); |
149 } else { |
153 } else { |
150 arrow = "—"; |
154 arrow = "—"; |
151 arrow_color = color_green; |
155 arrow_color = color_green; |
152 } |
156 } |
153 free(status); |
157 free(status); |
154 snprintf(remtimes,127,"%d:%02d",remtime/60,remtime%60); |
|
155 //printf("%d %d %d %s %d %s %s\n",charge_now,current_now,charge_full, |
|
156 // eights[charge_now*8/charge_full], charge_now*100/charge_full,status,remtimes); |
|
157 |
|
158 |
158 |
159 int percent = charge_now/(charge_full/100); |
159 int percent = charge_now/(charge_full/100); |
160 eights_color = percent_color = color(15,40,0,percent); |
160 eights_color = percent_color = color(15,40,0,percent); |
161 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); |
162 printf("%s%d%%%s ",percent_color,percent,color_stop); |
162 printf("%s%d%%%s ",percent_color,percent,color_stop); |
163 printf("%s%s%s ",arrow_color,arrow,color_stop); |
163 printf("%s%s%s ",arrow_color,arrow,color_stop); |
164 printf("%s%s%s\n",remtimes_color,remtimes,color_stop); |
164 #ifdef DRAIN_THE_FUCK |
|
165 if ((remtime < 20)&&(arrow == down_arrow)) { |
|
166 sleeptime = 1; |
|
167 alertflash = !alertflash; |
|
168 } else { |
|
169 sleeptime = UPDATE_PERIOD; |
|
170 alertflash = 1; |
|
171 } |
|
172 if (alertflash) { |
|
173 #endif |
|
174 printf("%s%d:%02d%s\n",remtimes_color, remtime/60, remtime%60, color_stop); |
|
175 #ifdef DRAIN_THE_FUCK |
|
176 } else { |
|
177 printf("%s·:··%s\n",remtimes_color, color_stop); |
|
178 } |
|
179 #endif |
165 fflush(stdout); |
180 fflush(stdout); |
166 #ifdef USE_UDEV |
181 #ifdef USE_UDEV |
167 int poll_status = poll(fds,1, UPDATE_PERIOD*1000); |
182 int poll_status = poll(fds,1, sleeptime*1000); |
168 if (poll_status < 0) { |
183 if (poll_status < 0) { |
169 if (poll_status != EINTR) { |
184 if (poll_status != EINTR) { |
170 perror("poll"); |
185 perror("poll"); |
171 exit(12); |
186 exit(12); |
172 } |
187 } |