Add power consumption
This commit is contained in:
parent
13663512a4
commit
cd487dcf76
30
dwmstatus.c
30
dwmstatus.c
@ -100,7 +100,11 @@ readfile(char *base, char *file)
|
|||||||
|
|
||||||
memset(line, 0, sizeof(line));
|
memset(line, 0, sizeof(line));
|
||||||
|
|
||||||
|
if (file != NULL)
|
||||||
path = smprintf("%s/%s", base, file);
|
path = smprintf("%s/%s", base, file);
|
||||||
|
else {
|
||||||
|
path = smprintf("%s", base);
|
||||||
|
}
|
||||||
fd = fopen(path, "r");
|
fd = fopen(path, "r");
|
||||||
free(path);
|
free(path);
|
||||||
if (fd == NULL)
|
if (fd == NULL)
|
||||||
@ -194,6 +198,26 @@ getBrightness(char *base) {
|
|||||||
|
|
||||||
return smprintf("%s %d%% ", status, percentage);
|
return smprintf("%s %d%% ", status, percentage);
|
||||||
}
|
}
|
||||||
|
char *
|
||||||
|
getPowerConsumption(char *base) {
|
||||||
|
char *co;
|
||||||
|
long usageRead;
|
||||||
|
float usage;
|
||||||
|
|
||||||
|
co = readfile(base, NULL);
|
||||||
|
if (co == NULL)
|
||||||
|
return smprintf("");
|
||||||
|
|
||||||
|
sscanf(co, "%ld", &usageRead);
|
||||||
|
free(co);
|
||||||
|
|
||||||
|
if (usage == 0)
|
||||||
|
return smprintf("");
|
||||||
|
|
||||||
|
usage = usageRead/ 1e6;
|
||||||
|
|
||||||
|
return smprintf("%.2lf W ", usage);
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
gettemperature(char *base, char *sensor)
|
gettemperature(char *base, char *sensor)
|
||||||
@ -213,15 +237,17 @@ void update() {
|
|||||||
char *t0;
|
char *t0;
|
||||||
char *bat;
|
char *bat;
|
||||||
char *brightness;
|
char *brightness;
|
||||||
|
char *powerConsumption;
|
||||||
|
|
||||||
avgs = loadavg();
|
avgs = loadavg();
|
||||||
tmbln = mktimes("%H:%M %d.%m.%Y", tzwarsaw);
|
tmbln = mktimes("%H:%M %d.%m.%Y", tzwarsaw);
|
||||||
t0 = gettemperature("/sys/class//hwmon/hwmon1", "temp1_input");
|
t0 = gettemperature("/sys/class//hwmon/hwmon1", "temp1_input");
|
||||||
bat = getbattery("/sys/class/power_supply/BAT0");
|
bat = getbattery("/sys/class/power_supply/BAT0");
|
||||||
brightness = getBrightness("/sys/class/backlight/amdgpu_bl0");
|
brightness = getBrightness("/sys/class/backlight/amdgpu_bl0");
|
||||||
|
powerConsumption = getPowerConsumption("/sys/class/power_supply/BAT0/power_now");
|
||||||
|
|
||||||
status = smprintf("%s%s%s%s%s",
|
status = smprintf("%s%s%s%s%s%s",
|
||||||
bat, brightness, t0, avgs, tmbln);
|
powerConsumption, bat, brightness, t0, avgs, tmbln);
|
||||||
setstatus(status);
|
setstatus(status);
|
||||||
|
|
||||||
free(t0);
|
free(t0);
|
||||||
|
Loading…
Reference in New Issue
Block a user