# HG changeset patch # User Stiletto # Date 1414072513 -14400 # Node ID 70b4e0b27e2c82ba15835a6e76c8c8adbb7e2eff # Parent dae770da64168009d5ed052f64bb2ec0dcef274e status-wifi diff -r dae770da6416 -r 70b4e0b27e2c config.mk --- a/config.mk Mon Oct 20 23:24:03 2014 +0400 +++ b/config.mk Thu Oct 23 17:55:13 2014 +0400 @@ -16,6 +16,6 @@ STATUS_CFLAGS = -std=c99 -pedantic -Wall -Os ${STATUS_INCS} ${STATUS_CPPFLAGS} STATUS_LDFLAGS = ${STATUS_LIBS} -static -STATUS = status-time status-mem status-loadavg +STATUS = status-time status-mem status-loadavg status-wifi # compiler and linker CC = cc diff -r dae770da6416 -r 70b4e0b27e2c status-wifi/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/status-wifi/Makefile Thu Oct 23 17:55:13 2014 +0400 @@ -0,0 +1,12 @@ +# dwm - dynamic window manager +# See LICENSE file for copyright and license details. + +include ../config.mk +include config.mk + +OUT = status-wifi +SRC = wifi.c +OBJ = ${SRC:.c=.o} +CONFIG = config.h + +include ../Makefile.status.inc diff -r dae770da6416 -r 70b4e0b27e2c status-wifi/config.def.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/status-wifi/config.def.h Thu Oct 23 17:55:13 2014 +0400 @@ -0,0 +1,2 @@ +#define UPDATE_PERIOD 15 +//#define PANGO_MARKUP // use second argument instead diff -r dae770da6416 -r 70b4e0b27e2c status-wifi/config.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/status-wifi/config.mk Thu Oct 23 17:55:13 2014 +0400 @@ -0,0 +1,5 @@ +STATUS_LIBS = -L/usr/lib -liw +STATUS_INCS = -std=gnu99 +STATUS_LDFLAGS = ${STATUS_LIBS} + + diff -r dae770da6416 -r 70b4e0b27e2c status-wifi/wifi.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/status-wifi/wifi.c Thu Oct 23 17:55:13 2014 +0400 @@ -0,0 +1,109 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +char *eights[] = { "ø", "▁", "▂", "▃", "▄", "▅", "▆","▇", "█" }; + +char *color_stop; +char *color_red; +char *color_orange; +char *color_green; +char *color_none; + +char *color(int low,int mid,int rev,int value) { + if (value>mid) { + return rev ? color_red : color_green; + } else if (value>low) { + return color_orange; + } + return rev ? color_green : color_red; +} + +int main(int argc, char *argv[]) { + assert(argc>1); + + int skfd; + if((skfd = iw_sockets_open()) < 0) { + perror("socket"); + exit(-1); + } + + while (1) { + if (argc>2 && !strcmp(argv[2],"term")) { + color_stop = "\x1b[0m"; + color_red = "\x1b[1;31m"; + color_green = "\x1b[1;32m"; + color_orange = "\x1b[1;33m"; + color_none = color_stop; + } else if (argc>2 && !strcmp(argv[2],"pango")) { + color_stop = ""; + color_red = ""; + color_green = ""; + color_orange = ""; + color_none = ""; + } else { + color_stop = color_red = color_green = color_orange = color_none = ""; + } + + iwstats stats; + iwrange range; + int down = 0; + wireless_config info; + + + if (iw_get_basic_config(skfd,argv[1],&info) < 0) { + perror("iw_get_basic_config"); + exit(-2); + } + + if (iw_get_range_info(skfd,argv[1],&range) < 0) { + perror("iw_get_range_info"); + exit(-2); + } + if (iw_get_stats(skfd,argv[1],&stats,&range,1) < 0) { + if (argc>2) + down = 1; + else { + perror("iw_get_stats"); + exit(-2); + } + } + if (down) { + if (!strcmp(info.essid,"")) { + printf("%sDOWN%s\n",color_orange,color_stop); + } else { + printf("%s [%sXX/XX%s] XX\n",info.essid,color_red,color_stop); + } + } else { + int ql = 100 * stats.qual.qual / range.max_qual.qual; + char *qual_color = color(20,40,0,ql); + if (stats.qual.qual-35) + perc=100; + else if(dbm<=-95) + perc = 1; + else + perc = (dbm+95)*100/60; + + printf("%s [%s%02d/%02d%s] ",info.essid,qual_color,stats.qual.qual,range.max_qual.qual,color_stop); + printf("%s%hhd%s ",color(-83,-77,0,dbm),dbm,color_stop); + printf("%s%d%%%s\n",color(20,40,0,perc),perc,color_stop); + } + fflush(stdout); + sleep(UPDATE_PERIOD); + } + close(skfd); +}