--- a/status-bat/bat.c Fri Oct 24 14:13:46 2014 +0400
+++ b/status-bat/bat.c Fri Oct 24 17:07:07 2014 +0400
@@ -54,6 +54,7 @@
char *color_orange;
char *color_green;
char *color_none;
+static char *down_arrow = "↓";
char *color(int low,int mid,int rev,int value) {
if (value>mid) {
@@ -115,6 +116,10 @@
snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/energy_now",argv[1]);
struct stat st;
int energy = 0==stat(filename, &st);
+ int sleeptime = UPDATE_PERIOD;
+#ifdef DRAIN_THE_FUCK
+ int alertflash = 1;
+#endif
while (1) {
snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_now",argv[1], energy ? "energy" : "charge");
@@ -130,7 +135,6 @@
char *status = catfile(filename);
int remtime = 0;
- char remtimes[128];
char *arrow;
remtimes_color = color_none;
@@ -143,7 +147,7 @@
else if (!strcmp(status,"Discharging")) {
if (current_now != 0)
remtime = charge_now / (current_now/60);
- arrow = "↓";
+ arrow = down_arrow;
arrow_color = color_none;
remtimes_color = color(20,120,0,remtime);
} else {
@@ -151,20 +155,31 @@
arrow_color = color_green;
}
free(status);
- snprintf(remtimes,127,"%d:%02d",remtime/60,remtime%60);
- //printf("%d %d %d %s %d %s %s\n",charge_now,current_now,charge_full,
- // eights[charge_now*8/charge_full], charge_now*100/charge_full,status,remtimes);
-
int percent = charge_now/(charge_full/100);
eights_color = percent_color = color(15,40,0,percent);
printf("%s%s%s ",eights_color,eights[charge_now*8/charge_full],color_stop);
printf("%s%d%%%s ",percent_color,percent,color_stop);
printf("%s%s%s ",arrow_color,arrow,color_stop);
- printf("%s%s%s\n",remtimes_color,remtimes,color_stop);
+#ifdef DRAIN_THE_FUCK
+ if ((remtime < 20)&&(arrow == down_arrow)) {
+ sleeptime = 1;
+ alertflash = !alertflash;
+ } else {
+ sleeptime = UPDATE_PERIOD;
+ alertflash = 1;
+ }
+ if (alertflash) {
+#endif
+ printf("%s%d:%02d%s\n",remtimes_color, remtime/60, remtime%60, color_stop);
+#ifdef DRAIN_THE_FUCK
+ } else {
+ printf("%s·:··%s\n",remtimes_color, color_stop);
+ }
+#endif
fflush(stdout);
#ifdef USE_UDEV
- int poll_status = poll(fds,1, UPDATE_PERIOD*1000);
+ int poll_status = poll(fds,1, sleeptime*1000);
if (poll_status < 0) {
if (poll_status != EINTR) {
perror("poll");
@@ -181,7 +196,7 @@
}
}
#else
- sleep(UPDATE_PERIOD);
+ sleep(sleeptime);
#endif
}
}