From 2d1bbf0d35f096803a96afbc8ae89a057e646d9f Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Tue, 13 Sep 2016 20:54:45 +0200 Subject: simplified battery_perc() a lot and removed useless options from config.def.h --- config.def.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'config.def.h') diff --git a/config.def.h b/config.def.h index b105869..8cf8e56 100644 --- a/config.def.h +++ b/config.def.h @@ -3,11 +3,6 @@ /* alsa sound */ #define ALSA_CHANNEL "Master" -/* battery */ -#define BATTERY_PATH "/sys/class/power_supply/" -#define BATTERY_NOW "energy_now" -#define BATTERY_FULL "energy_full_design" - /* how often to update the statusbar (min value == 1) */ #define UPDATE_INTERVAL 1 -- cgit v1.2.3-70-g09d2 From 87c1377b08a9001a16943942e9d67458d8d19c33 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Tue, 13 Sep 2016 21:08:44 +0200 Subject: simplified vol_perc() (and with that config.def.h is super clean) --- config.def.h | 3 --- slstatus.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'config.def.h') diff --git a/config.def.h b/config.def.h index 8cf8e56..a445aa7 100644 --- a/config.def.h +++ b/config.def.h @@ -1,8 +1,5 @@ /* See LICENSE file for copyright and license details. */ -/* alsa sound */ -#define ALSA_CHANNEL "Master" - /* how often to update the statusbar (min value == 1) */ #define UPDATE_INTERVAL 1 diff --git a/slstatus.c b/slstatus.c index f61e987..1b45f64 100644 --- a/slstatus.c +++ b/slstatus.c @@ -459,7 +459,7 @@ uid(void) static char * -vol_perc(const char *snd_card) +vol_perc(const char *soundcard) { /* FIX THIS SHIT! */ long int vol, max, min; snd_mixer_t *handle; @@ -471,7 +471,7 @@ vol_perc(const char *snd_card) snd_mixer_selem_register(handle, NULL, NULL); snd_mixer_load(handle); snd_mixer_selem_id_malloc(&s_elem); - snd_mixer_selem_id_set_name(s_elem, ALSA_CHANNEL); + snd_mixer_selem_id_set_name(s_elem, "Master"); elem = snd_mixer_find_selem(handle, s_elem); if (elem == NULL) { -- cgit v1.2.3-70-g09d2 From f13104156f20c0e394297c56550ff8a948ff1c1a Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Tue, 13 Sep 2016 22:03:36 +0200 Subject: battery_state() function added --- README.md | 2 +- config.def.h | 1 + slstatus.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'config.def.h') diff --git a/README.md b/README.md index 534eee0..686922c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Looking at the LOC (lines of code) of the [Conky project](https://github.com/brn The following information is included: -- Battery percentage +- Battery percentage/state - CPU usage (in percent) - Custom shell commands - Date and time diff --git a/config.def.h b/config.def.h index a445aa7..4f56eb0 100644 --- a/config.def.h +++ b/config.def.h @@ -8,6 +8,7 @@ /* statusbar - battery_perc (battery percentage) [argument: battery name] +- battery_state (battery charging state) [argument: battery name] - cpu_perc (cpu usage in percent) [argument: NULL] - datetime (date and time) [argument: format] - disk_free (disk usage in percent) [argument: mountpoint] diff --git a/slstatus.c b/slstatus.c index fa91cce..1d46674 100644 --- a/slstatus.c +++ b/slstatus.c @@ -40,6 +40,7 @@ struct arg { static char *smprintf(const char *, ...); static char *battery_perc(const char *); +static char *battery_state(const char *); static char *cpu_perc(void); static char *datetime(const char *); static char *disk_free(const char *); @@ -113,6 +114,37 @@ battery_perc(const char *battery) return smprintf("%d%%", perc); } +static char * +battery_state(const char *battery) +{ + char *state = malloc(sizeof(char)*12); + FILE *fp; + + if (!state) { + warn("Failed to get battery state."); + return smprintf(UNKNOWN_STR); + } + + + ccat(3, "/sys/class/power_supply/", battery, "/status"); + fp = fopen(concat, "r"); + if (fp == NULL) { + warn("Error opening battery file: %s", concat); + return smprintf(UNKNOWN_STR); + } + fscanf(fp, "%s", state); + fclose(fp); + + if (strcmp(state, "Charging") == 0) + return smprintf("+"); + else if (strcmp(state, "Discharging") == 0) + return smprintf("-"); + else if (strcmp(state, "Full") == 0) + return smprintf("="); + else + return smprintf("?"); +} + static char * cpu_perc(void) { -- cgit v1.2.3-70-g09d2