X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fbattery%2Fbattery.c;h=4db696e4d73ea977e723133024bb66394518c610;hb=afc4d060e002f51ed317818e875dae51fbccec12;hp=f0498b728e689e8aaa7b74295aacc6887a9598e9;hpb=1488f5525f69428d66b0cb2da6e610edae2ebf55;p=chaz%2Ftint2 diff --git a/src/battery/battery.c b/src/battery/battery.c index f0498b7..4db696e 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -37,12 +37,14 @@ PangoFontDescription *bat1_font_desc=0; PangoFontDescription *bat2_font_desc=0; struct batstate battery_state; int battery_enabled; +static const struct timeout* battery_timeout=0; static char buf_bat_percentage[10]; static char buf_bat_time[20]; int8_t battery_low_status; char *battery_low_cmd=0; +unsigned char battery_low_cmd_send=0; char *path_energy_now=0; char *path_energy_full=0; char *path_current_now=0; @@ -130,8 +132,8 @@ void init_battery() g_free(path1); g_free(battery_dir); - if (battery_enabled) - install_timer(0, 1000000, 3, 0, update_batterys); + if (battery_enabled && battery_timeout==0) + battery_timeout = add_timeout(10, 5000, update_batterys); } @@ -266,10 +268,15 @@ void update_battery() { if(energy_full > 0) new_percentage = (energy_now*100)/energy_full; - if(battery_low_status != 0 && battery_low_status == new_percentage && battery_state.percentage > new_percentage) { - //printf("battery low, executing: %s\n", battery_low_cmd); - if (battery_low_cmd) system(battery_low_cmd); + if(battery_low_status > new_percentage && battery_state.state == BATTERY_DISCHARGING && !battery_low_cmd_send) { + printf("battery low, executing: %s\n", battery_low_cmd); + if (battery_low_cmd) + system(battery_low_cmd); + battery_low_cmd_send = 1; } + if(battery_low_status < new_percentage && battery_state.state == BATTERY_CHARGING && battery_low_cmd_send) { + battery_low_cmd_send = 0; + } battery_state.percentage = new_percentage;