commit 5dd39d54cc2786fbb8f6d559943357dc59541567
parent 0b575aa3989ee877769a104c83203dbce2ff2e55
Author: lostd <lostd@2f30.org>
Date: Fri, 20 May 2016 23:23:19 +0100
Support printing hw.sensors.cpu0.temp0 in Celsius
Diffstat:
M | spoon.c | | | 28 | ++++++++++++++++++++++++++++ |
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/spoon.c b/spoon.c
@@ -17,6 +17,7 @@
int dummyread(char *buf, size_t len);
int mpdread(char *buf, size_t len);
int cpuread(char *buf, size_t len);
+int tempread(char *buf, size_t len);
int battread(char *buf, size_t len);
int wifiread(char *buf, size_t len);
int dateread(char *buf, size_t len);
@@ -30,6 +31,7 @@ struct ent {
{ .fmt = "[%s] ", .read = mpdread },
{ .fmt = "[%s] ", .read = xkblayoutread },
{ .fmt = "[%sMHz] ", .read = cpuread },
+ { .fmt = "[%s] ", .read = tempread },
{ .fmt = "%s ", .read = battread },
{ .fmt = "%s ", .read = wifiread },
{ .fmt = "%s", .read = dateread },
@@ -79,6 +81,7 @@ out:
#ifdef __OpenBSD__
#include <sys/socket.h>
#include <sys/sysctl.h>
+#include <sys/sensors.h>
#include <sys/ioctl.h>
#include <net/if.h>
@@ -108,6 +111,25 @@ cpuread(char *buf, size_t len)
}
int
+tempread(char *buf, size_t len)
+{
+ int mib[5];
+ struct sensor temp;
+ size_t sz;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_SENSORS;
+ mib[2] = 0; /* cpu0 */
+ mib[3] = SENSOR_TEMP;
+ mib[4] = 0; /* temp0 */
+ sz = sizeof(temp);
+ if (sysctl(mib, 5, &temp, &sz, NULL, 0) == -1)
+ return -1;
+ snprintf(buf, len, "%ddegC", (temp.value - 273150000) / 1000000);
+ return 0;
+}
+
+int
battread(char *buf, size_t len)
{
struct apm_power_info info;
@@ -237,6 +259,12 @@ cpuread(char *buf, size_t len)
}
int
+tempread(char *buf, size_t len)
+{
+ return -1;
+}
+
+int
battread(char *buf, size_t len)
{
return -1;