summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--statuses/cpuusage.c36
-rw-r--r--statuses/memusage.c22
-rw-r--r--statuses/volume_alsa.c26
-rw-r--r--sysstatus.c5
4 files changed, 44 insertions, 45 deletions
diff --git a/statuses/cpuusage.c b/statuses/cpuusage.c
index fa92829..dd9f1c5 100644
--- a/statuses/cpuusage.c
+++ b/statuses/cpuusage.c
@@ -23,11 +23,11 @@ float cpu_history[CPU_HISTORY_SIZE]; // don't care about init values
void status_cpuusage()
{
double loadavg[3] = { -13.37, -13.37, -13.37 } ;
-
+
char *stline = NULL;
size_t stlen;
FILE *stfile;
-
+
unsigned long cpu_user;
unsigned long cpu_nice;
unsigned long cpu_sys;
@@ -35,51 +35,51 @@ void status_cpuusage()
unsigned long cpu_idle;
unsigned long cpu_total;
int i;
-
-
+
+
fputs("^fg(yellow)", stdout); // Error signaling color
-
+
stfile = fopen("/proc/stat", "r");
if (stfile != NULL)
{
for(i = CPU_HISTORY_SIZE - 1; i > 0; i--)
cpu_history[i] = cpu_history[i - 1];
-
+
stlen = getline(&stline, &stlen, stfile);
fclose(stfile);
-
- if ( 4 == sscanf(stline, "%*s %ld %ld %ld %ld", &cpu_user, &cpu_nice, &cpu_sys, &cpu_idle) );
+
+ if ( 4 == sscanf(stline, "%*s %ld %ld %ld %ld", &cpu_user, &cpu_nice, &cpu_sys, &cpu_idle) )
{
cpu_used = cpu_user + cpu_nice + cpu_sys;
cpu_total = cpu_used + cpu_idle;
-
+
// Now do the percentage
cpu_history[0] = (float)(cpu_used - last_cpu_used) /
(float)(cpu_total - last_cpu_total);
-
+
last_cpu_used = cpu_used;
last_cpu_total = cpu_total;
-
-
+
+
if (cpu_history[0] < 0.4)
fputs("^fg(#0077FF)", stdout); // CPU idling OK
else
fputs("^fg(#FF00FF)", stdout); // CPU busy
-
+
//printf(" CPU: %.0f%% ", cpu_history[0] * 100);
}
-
+
free(stline);
}
-
-
- if (getloadavg(loadavg, 3) > 0);
+
+
+ if (getloadavg(loadavg, 3) > 0)
printf(" %s%.0f,%.0f,%.0f,%.0f ",
cpu_history[0] < 0.1000 ? " " : "",
cpu_history[0] * 100,
loadavg[0] * (100 / 1),
loadavg[1] * (100 / 1), // (100 / NUM_CPUS)
loadavg[2] * (100 / 1));
-
+
//fputs(" CPU usage ", stdout);
}
diff --git a/statuses/memusage.c b/statuses/memusage.c
index 10d3732..37ba563 100644
--- a/statuses/memusage.c
+++ b/statuses/memusage.c
@@ -8,41 +8,41 @@ void status_memusage()
char *stline = NULL;
size_t stlen;
FILE *stfile;
-
+
int memtotal = 0;
int memfree = 0;
int memused;
int membuffers = 0;
int memcached = 0;
-
-
+
+
stfile = fopen("/proc/meminfo", "r");
if (stfile != NULL)
{
stlen = getline(&stline, &stlen, stfile);
memtotal = atoi(&stline[17]);
-
+
stlen = getline(&stline, &stlen, stfile);
memfree = atoi(&stline[17]);
-
+
stlen = getline(&stline, &stlen, stfile);
membuffers = atoi(&stline[17]);
-
+
stlen = getline(&stline, &stlen, stfile);
memcached = atoi(&stline[17]);
free(stline);
-
+
fclose(stfile);
-
+
memused = memtotal - memfree - memcached - membuffers;
-
+
memused /= 1024; // Just show MBs used
-
+
if ((float)memused / (float)memtotal < 0.85)
fputs("^fg(green)", stdout); // < 85% mem used
else
fputs("^fg(red)", stdout); // >= 85% mem used
-
+
printf(" Mem: %d M ", memused);
}
}
diff --git a/statuses/volume_alsa.c b/statuses/volume_alsa.c
index 0b1546a..527cafe 100644
--- a/statuses/volume_alsa.c
+++ b/statuses/volume_alsa.c
@@ -6,32 +6,32 @@ int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_
snd_mixer_t *handle = NULL;
snd_mixer_elem_t *elem;
snd_mixer_selem_id_t *sid;
-
+
long min = 0, max = 0;
long volume;
int on_off;
-
-
+
+
snd_mixer_selem_id_alloca(&sid);
if (snd_mixer_open(&handle, 0) < 0)
return -1;
-
+
if (snd_mixer_attach(handle, cardname) < 0)
goto ERROR;
-
+
snd_mixer_selem_id_set_name(sid, mixername);
-
+
if (snd_mixer_selem_register(handle, NULL, NULL) < 0)
goto ERROR;
-
+
if (snd_mixer_load(handle) < 0)
goto ERROR;
-
+
elem = snd_mixer_find_selem(handle, sid);
if (!elem)
goto ERROR;
-
+
if (snd_mixer_selem_has_playback_volume(elem) && snd_mixer_selem_has_playback_channel(elem, channel))
{
snd_mixer_selem_get_playback_switch(elem, channel, &on_off);
@@ -39,9 +39,9 @@ int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_
fputs("^fg(#22FF22)", stdout);
else
fputs("^fg(red)", stdout);
-
+
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
-
+
snd_mixer_selem_get_playback_volume(elem, channel, &volume);
fputs("^ca(1, amixer sset Master toggle)", stdout);
fputs("^ca(4, amixer sset Master 2+ unmute)", stdout);
@@ -55,9 +55,9 @@ int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_
snd_mixer_close(handle);
return 0;
-
+
ERROR:
-
+
snd_mixer_close(handle);
return -1;
}
diff --git a/sysstatus.c b/sysstatus.c
index f5e980c..cac8333 100644
--- a/sysstatus.c
+++ b/sysstatus.c
@@ -1,7 +1,6 @@
#include <stdio.h>
-#include <fcntl.h>
#include <stdlib.h>
-#include <unistd.h>
+#include "config.h"
#include "statuses/battery.h"
#include "statuses/cpuusage.h"
#include "statuses/datetime.h"
@@ -10,7 +9,7 @@
#include "statuses/volume_alsa.h"
#include "statuses/temp.h"
#include "statuses/uptime.h"
-#include "config.h"
+
void updatestatus()
{