[hackers] [slstatus] Return actual percentage for wifi_perc() || parazyd

From: <git_AT_suckless.org>
Date: Tue, 24 Oct 2017 11:17:37 +0200 (CEST)

commit d2988c72e3e77e188fda0176ce4969322e69fae9
Author: parazyd <parazyd_AT_dyne.org>
AuthorDate: Tue Oct 24 11:03:17 2017 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Tue Oct 24 11:16:54 2017 +0200

    Return actual percentage for wifi_perc()
    
    Implement basic percentage calculation for wifi_perc. With this
    commit, the function returns correct percentage, since the max
    of what /proc/net/wireless returns is 70.

diff --git a/components/wifi.c b/components/wifi.c
index 30b57ab..9ecb8e1 100644
--- a/components/wifi.c
+++ b/components/wifi.c
_AT_@ -14,7 +14,9 @@
 const char *
 wifi_perc(const char *iface)
 {
- int i, perc;
+ int i, cur;
+ float perc;
+ int total = 70; /* the max of /proc/net/wireless */
         char *p, *datastart;
         char path[PATH_MAX];
         char status[5];
_AT_@ -50,9 +52,11 @@ wifi_perc(const char *iface)
                 return NULL;
 
         datastart = (datastart+(strlen(iface)+1));
- sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc);
+ sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &cur);
 
- return bprintf("%d", perc);
+ perc = (float)cur / total * 100.0;
+
+ return bprintf("%.0f", perc);
 }
 
 const char *
Received on Tue Oct 24 2017 - 11:17:37 CEST

This archive was generated by hypermail 2.3.0 : Tue Oct 24 2017 - 11:24:20 CEST