diff options
author | ZoRo <dos21h@gmail.com> | 2020-04-05 16:31:20 +0100 |
---|---|---|
committer | ZoRo <dos21h@gmail.com> | 2020-04-05 16:31:20 +0100 |
commit | de58c2e89c6d38ae21e12b83902defa171b0b635 (patch) | |
tree | 632d661b8f3eb686bfd1788e7148044ef1fe8431 /status | |
download | dwmstatus-pixel-de58c2e89c6d38ae21e12b83902defa171b0b635.tar.gz dwmstatus-pixel-de58c2e89c6d38ae21e12b83902defa171b0b635.zip |
Diffstat (limited to 'status')
-rw-r--r-- | status/Kconfig | 31 | ||||
-rw-r--r-- | status/batt.c | 144 | ||||
-rw-r--r-- | status/cpu.c | 77 | ||||
-rw-r--r-- | status/date.c | 39 | ||||
-rw-r--r-- | status/make.mk | 5 | ||||
-rw-r--r-- | status/temp.c | 74 | ||||
-rw-r--r-- | status/time.c | 59 |
7 files changed, 429 insertions, 0 deletions
diff --git a/status/Kconfig b/status/Kconfig new file mode 100644 index 0000000..4b1dbda --- /dev/null +++ b/status/Kconfig @@ -0,0 +1,31 @@ +menuconfig STATUS + bool "Choose statuses" + option status + +if STATUS +config STATUS_TIME + bool "Show current time" + default n + +config STATUS_DATE + bool "Show current date" + default n + +config STATUS_LOAD_AVERAGE + bool "Average system load" + default n + +config STATUS_BATTERY + bool "Battery or AC?" + default n + +config STATUS_TEMP + bool "Show temperature" + default n + +config STATUS_CPU + bool "Show current CPU usage" + default n + +endif + diff --git a/status/batt.c b/status/batt.c new file mode 100644 index 0000000..f6e36b1 --- /dev/null +++ b/status/batt.c @@ -0,0 +1,144 @@ +#include "kconfig.h" +#include "dwmstatus.h" +#include "debug/debug.h" + + +#define BAT_PATH "/sys/class/power_supply/BAT0" +#define AC_PATH "/sys/class/power_supply/AC" + +/* +char utf8_batt_charging[] = { 0xef, 0x88, 0x91 }; +char utf8_batt_charged_0[] = { 0xef, 0x88, 0x92 }; +char utf8_batt_charged_20[] = { 0xef, 0x88, 0x95 }; +char utf8_batt_charged_70[] = { 0xef, 0x88, 0x94 }; +char utf8_batt_charged_100[] = { 0xef, 0x88, 0x93 }; +*/ + +char utf8_batt_charging[] = { 0xef, 0x96, 0x83 }; //ef 96 83 + +char utf8_batt_charged_0[] = { 0xef, 0x89, 0x84 }; //ef 89 84 +char utf8_batt_charged_20[] = { 0xef, 0x89, 0x83 }; //ef 89 83 +char utf8_batt_charged_70[] = { 0xef, 0x89, 0x8e }; //ef 89 8e +char utf8_batt_charged_100[] = { 0xef, 0x95, 0xba }; //ef 95 ba + + +int print_batt( bbuf *buf ) +{ + ASSERT( buf != NULL ); + + if ( buf->size < 1 ) + { + buf->size = 1024; + buf->str = malloc( buf->size ); + } + + int c1_s=0; //CALC OFFSET INSIDE STATUS_UTF8 + + int ac_state=-1; + FILE *fac = fopen( AC_PATH "/online", "r" ); + + ASSERT(fac != NULL ); + if ( fac != NULL ) + { + //printf("1\n"); + fscanf( fac, "%d", &ac_state ); + //printf("1\n"); + fclose( fac ); + } else + { + printf("%s\n",strerror(errno)); + } + + //printf("1\n"); + //printf("%d\n",ac_state); + + int bat_cap=-1; + FILE *fbat = fopen( BAT_PATH "/capacity", "r" ); + ASSERT( fbat != NULL ); + + if ( fbat != NULL ) + { + fscanf( fbat, "%d", &bat_cap ); + fclose( fbat ); + } else + { + printf("%s\n", strerror(errno)); + } + + //we expect that everything is nice + ASSERT(bat_cap >= 0); + ASSERT(bat_cap <= 100); + ASSERT(ac_state <= 1); + ASSERT(ac_state >= 0); + +#ifdef CONFIG_STATUS_UTF8 + if ( ac_state ) + { + c1_s = sizeof( utf8_batt_charging ); + memcpy( buf->str, utf8_batt_charging, c1_s ); + snprintf( buf->str+c1_s, buf->size-1-c1_s, " %02d ", bat_cap ); + } else + { + if ( bat_cap < 20) + { + c1_s = sizeof( utf8_batt_charged_0 ); + memcpy( buf->str, utf8_batt_charged_0, c1_s ); + } else if ( bat_cap < 70 ) + { + c1_s = sizeof( utf8_batt_charged_20 ); + memcpy( buf->str, utf8_batt_charged_20, c1_s ); + } else if ( bat_cap < 98 ) + { + c1_s = sizeof( utf8_batt_charged_70 ); + memcpy( buf->str, utf8_batt_charged_70, c1_s ); + } + else + { + c1_s = sizeof( utf8_batt_charged_100 ); + memcpy( buf->str, utf8_batt_charged_100, c1_s ); + } + + } +#else + +#endif + +//PUT COLORING INTO WORK +#ifdef CONFIG_STATUS_FMT_PANGO + //seperate by colors + // RED - few secs left - <10% + // ORANGE - better to prepare - 10-30% + // GREEN - looks ok - >30% + if ( bat_cap < 10 && bat_cap >= 0 ) + { + #ifdef CONFIG_STATUS_UTF8 + snprintf(buf->str+c1_s, buf->size-1-c1_s, " <span color=\"#ff6633\">%02d</span> ", bat_cap ); + #else + snprintf( buf->str, buf->size-1, "AC:%d BAT:<span color=\"#ff6633\">%02d</span> ", ac_state, bat_cap ); + #endif + } else if ( bat_cap < 30 ) + { + #ifdef CONFIG_STATUS_UTF8 + snprintf(buf->str+c1_s, buf->size-1-c1_s, " <span color=\"#ffcc33\">%02d</span> ", bat_cap ); + #else + snprintf( buf->str, buf->size-1, "AC:%d BAT:<span color=\"#ffcc33\">%02d</span> ", ac_state, bat_cap ); + #endif + } else if ( bat_cap < 100 ) + { + #ifdef CONFIG_STATUS_UTF8 + snprintf(buf->str+c1_s, buf->size-1-c1_s, " <span color=\"#33ff66\">%02d</span> ", bat_cap ); + #else + snprintf( buf->str, buf->size-1, "AC:%d BAT:<span color=\"#33ff66\">%02d</span> ", ac_state, bat_cap ); + #endif + } +#else + #ifdef CONFIG_STATUS_UTF8 + snprintf(buf->str+c1_s, buf->size-1-c1_s, " !%02d ", bat_cap ); + #else + snprintf( buf->str, buf->size-1, "AC:%d BAT:%02d ", ac_state, bat_cap ); + #endif +#endif + + return 0; +} + diff --git a/status/cpu.c b/status/cpu.c new file mode 100644 index 0000000..5f203ee --- /dev/null +++ b/status/cpu.c @@ -0,0 +1,77 @@ +#include "kconfig.h" +#include "dwmstatus.h" + +static int prev_total = 0; +static int prev_idle = 0; + +int print_cpu( bbuf *buf ) +{ + ASSERT( buf != NULL ); + + + int str_size=0; + int curr_user = 0, curr_nice = 0, curr_system = 0, curr_idle = 0, curr_total; + int diff_idle, diff_total, diff_usage; + + if ( buf->size < 1 ) + { + buf->size = 1024; + buf->str = malloc( buf->size ); + } + + FILE *f = fopen( "/proc/stat", "r" ); + ASSERT(f != NULL ); + + fscanf( f, "cpu %d %d %d %d", &curr_user, &curr_nice, &curr_system, &curr_idle ); + fclose( f ); + + ASSERT( curr_user > 0 ); + ASSERT( curr_nice > 0 ); + ASSERT( curr_system > 0 ); + ASSERT( curr_idle > 0 ); + + //printf("%d %d %d %d\n", curr_user, curr_nice, curr_system, curr_idle ); + + curr_total = curr_user + curr_nice + curr_system + curr_idle; + diff_idle = curr_idle - prev_idle; + diff_total = curr_total - prev_total; + diff_usage = (diff_total ? (1000 * (diff_total - diff_idle)/diff_total + 5)/10 : 0); + prev_total = curr_total; + prev_idle = curr_idle; + +#ifdef CONFIG_STATUS_UTF8 + //chip f64f, //ef ac 99 + buf->str[0] = 0xef; + buf->str[1] = 0xac; + buf->str[2] = 0x99; + str_size = 3; + printf("asd1 [%s]\n", buf->str); +#endif + +#ifdef CONFIG_STATUS_FMT_PANGO + //seperate by colors + // COLD - BLUE - < 20% + // WARM - GREEN 20-80% + // HOT - RED >80% + if ( diff_usage < 20 ) + { + snprintf( buf->str, buf->size-1, "CPU:<span color=\"#3366ff\">%02d%%</span> ", diff_usage ); + } else if( diff_usage > 80 ) + { + snprintf( buf->str, buf->size-1, "CPU:<span color=\"#ff6633\">%02d%%</span> ", diff_usage ); + } else + { + snprintf( buf->str, buf->size-1, "CPU:<span color=\"#33ff66\">%02d%%</span> ", diff_usage ); + } +#else + #ifdef CONFIG_STATUS_UTF8 + snprintf( &buf->str[str_size], buf->size-1-str_size, "%02d%% ", diff_usage ); + #else + snprintf( &buf->str[str_size], buf->size-1-str_size, "CPU:%02d%% ", diff_usage ); + #endif + +#endif + + return 0; +} + diff --git a/status/date.c b/status/date.c new file mode 100644 index 0000000..f06c61d --- /dev/null +++ b/status/date.c @@ -0,0 +1,39 @@ +#include "kconfig.h" +#include "dwmstatus.h" + +int print_date( bbuf *buf ) +{ + ASSERT( buf != NULL ); + + int str_size=0; + if ( buf->size < 1 ) + { + buf->size = 1024; + buf->str = malloc( buf->size ); + ASSERT( buf->str != NULL ); + } + + time_t tim; + struct tm *timtm; + + memset(buf->str, 0, buf->size); + time( &tim ); + timtm = localtime( &tim ); + if (timtm == NULL) + { + perror("localtime"); + } + +#ifdef CONFIG_STATUS_UTF8 + buf->str[0] = 0xef; + buf->str[1] = 0x81; + buf->str[2] = 0xb3; + str_size = 3; +#endif + + + strftime(&buf->str[str_size], buf->size-1-str_size," %d%b%Y", timtm); + + return 0; +} + diff --git a/status/make.mk b/status/make.mk new file mode 100644 index 0000000..ca2a0ac --- /dev/null +++ b/status/make.mk @@ -0,0 +1,5 @@ + +CUR_DIR=status +NEW_SRC=date.c time.c +SRC+=$(CUR_DIR)/time.c $(CUR_DIR)/date.c +OBJ+=$(CUR_DIR)/time.o $(CUR_DIR)/date.o diff --git a/status/temp.c b/status/temp.c new file mode 100644 index 0000000..d35f6b3 --- /dev/null +++ b/status/temp.c @@ -0,0 +1,74 @@ +#include "kconfig.h" +#include "dwmstatus.h" + +#define TEMP_PATH "/sys/class/thermal/thermal_zone0/temp" + +int print_temp( bbuf *buf) +{ + ASSERT( buf != NULL ); + + int str_size=0; + if ( buf->size < 1 ) + { + buf->size = 1024; + buf->str = malloc( buf->size ); + } + + uint32_t temp=0; + FILE *f = fopen(TEMP_PATH,"r"); + + ASSERT( f != NULL ); + + fscanf( f, "%u\n", &temp ); + temp /= 1000; + //printf("%u\n",temp); + + fclose( f ); + + ASSERT( temp < 110 ); + +#ifdef CONFIG_STATUS_UTF8 + buf->str[0] = 0xef; + buf->str[1] = 0xa3; + buf->str[2] = 0x87; + str_size = 3; +#endif + +#ifdef CONFIG_STATUS_FMT_PANGO + //seperate by color temp + // RED - very hot - >80 + // GREEN - normal temp - 50-80 + // BLUE - cold - <50 + if ( temp < 50 ) + { + #ifdef CONFIG_STATUS_UTF8 + snprintf( &buf->str[str_size], buf->size-1-str_size, "<span color=\"#3366ff\">%u</span>C ", temp ); + #else + snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:<span color=\"#3366ff\">%u</span>C ", temp ); + #endif + } else if ( temp < 80 ) + { + #ifdef CONFIG_STATUS_UTF8 + snprintf( &buf->str[str_size], buf->size-1-str_size, "<span color=\"#33ff66\">%u</span>C ", temp ); + #else + snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:<span color=\"#33ff66\">%u</span>C ", temp ); + #endif + } else + { + #ifdef CONFIG_STATUS_UTF8 + snprintf( &buf->str[str_size], buf->size-1-str_size, "<span color=\"#ff6633\">%u</span>C ", temp ); + #else + snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:<span color=\"#ff6633\">%u</span>C ", temp ); + #endif + } +#else + #ifdef CONFIG_STATUS_UTF8 + snprintf( &buf->str[str_size], buf->size-1-str_size, "%uC ", temp ); + #else + snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:%uC ", temp ); + #endif + //snprintf( buf->str, buf->size-1, "\xc2\xae%uC ", temp/1000 ); +#endif + + return 0; +} diff --git a/status/time.c b/status/time.c new file mode 100644 index 0000000..f02e2bf --- /dev/null +++ b/status/time.c @@ -0,0 +1,59 @@ + +#include "kconfig.h" +#include "dwmstatus.h" + +int print_time( bbuf *buf ) +{ + ASSERT( buf != NULL ); + + int str_size=0; + + if ( buf->size < 1 ) + { + buf->size = 1024; + buf->str = malloc( buf->size ); + } + + time_t tim; + struct tm *timtm; + + memset(buf->str, 0, buf->size); + //settz(tzname); + time( &tim ); + timtm = localtime( &tim ); + if (timtm == NULL) + { + perror("localtime"); + //exit(1); + } +#ifdef CONFIG_STATUS_UTF8 + /* + buf->str[0] = 0x20; + buf->str[1] = 0xef; + buf->str[2] = 0x8d; + buf->str[3] = 0xae; + str_size = 2; + */ + //nerd f64f, //ef 99 8f + buf->str[0] = 0xef; + buf->str[1] = 0x99; + buf->str[2] = 0x8f; + str_size = 3; + printf("asd1 [%s]\n", buf->str); +#endif + + //printf("%s",asctime(timtm)); + strftime(&buf->str[str_size], buf->size-1-str_size,"%H:%M ", timtm); + //if (!strftime(buf->str, buf->size-1, "%H:%M", timtm)) + //{ + // fprintf(stderr, "strftime == 0\n"); + //exit(1); + //} + + + printf("asd1 [%s]\n", buf->str); + //wprintf(L"asd2 [%ls]\n", buf->str); + return 0; +} + + |