spoon

set dwm status
git clone git://git.2f30.org/spoon.git
Log | Files | Refs | LICENSE

commit e5f8bc81916adcaf337d83a4e89f2fd89c7238f5
parent 315c36f57ada6030ca250fb103df80d8fffadb51
Author: sin <sin@2f30.org>
Date:   Thu Oct 13 16:03:11 +0100

Implement temperature plugin for Linux

Diffstat:
Makefile | 3++-
temp.c | 14+++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile @@ -12,7 +12,8 @@ include config.mk CPPFLAGS_OpenBSD = -I/usr/X11R6/include -I/usr/local/include LDFLAGS_OpenBSD = -L/usr/X11R6/lib -L/usr/local/lib CPPFLAGS_Linux = -DPATH_BAT_CAP=\"/sys/class/power_supply/BAT0/capacity\"\ - -DPATH_AC_ONLINE=\"/sys/class/power_supply/AC/online\" + -DPATH_AC_ONLINE=\"/sys/class/power_supply/AC/online\"\ + -DPATH_TEMP=\"/sys/class/hwmon/hwmon0/temp1_input\" CPPFLAGS = $(CPPFLAGS_$(UNAME)) LDFLAGS = $(LDFLAGS_$(UNAME)) LDLIBS = -lxkbfile -lX11 -lmpdclient diff --git a/temp.c b/temp.c @@ -1,3 +1,4 @@ +#include <err.h> #include <stddef.h> #include <stdio.h> @@ -27,6 +28,17 @@ tempread(char *buf, size_t len) int tempread(char *buf, size_t len) { - return -1; + FILE *fp; + int temp; + + fp = fopen(PATH_TEMP, "r"); + if (fp == NULL) { + warn("fopen %s", PATH_TEMP); + return -1; + } + fscanf(fp, "%d", &temp); + fclose(fp); + snprintf(buf, len, "%ddegC", temp / 1000); + return 0; } #endif