commit 6e085bb0829b1f701633d571ab6ac3868d7ab681
parent 1a3626eb68f65133ab7257a07bfccc7f57def1da
Author: sin <sin@2f30.org>
Date: Tue, 17 May 2016 14:57:34 +0100
Add cpu freq reading
Untested.
Diffstat:
M | spoon.c | | | 24 | ++++++++++++++++++++++++ |
1 file changed, 24 insertions(+), 0 deletions(-)
diff --git a/spoon.c b/spoon.c
@@ -16,6 +16,7 @@
int dummyread(char *buf, size_t len);
int mpdread(char *buf, size_t len);
+int cpuread(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);
@@ -28,6 +29,7 @@ struct ent {
/* reorder this if you want */
{ .fmt = "[%s] ", .read = mpdread },
{ .fmt = "[%s] ", .read = xkblayoutread },
+ { .fmt = "[%sMHz] ", .read = cpuread },
{ .fmt = "%s ", .read = battread },
{ .fmt = "%s ", .read = wifiread },
{ .fmt = "%s", .read = dateread },
@@ -77,6 +79,7 @@ out:
#ifdef __OpenBSD__
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/sysctl.h>
#include <sys/ioctl.h>
#include <net/if.h>
@@ -91,6 +94,21 @@ out:
#include <machine/apmvar.h>
int
+cpuread(char *buf, size_t len)
+{
+ int mib[2], cpuspeed;
+ size_t len;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_CPUSPEED;
+ len = sizeof(cpuspeed);
+ if (sysctl(mib, 2, &cpuspeed, &len, NULL, 0) < 0)
+ return -1;
+ snprintf(buf, len, "%d", cpuspeed);
+ return 0;
+}
+
+int
battread(char *buf, size_t len)
{
struct apm_power_info info;
@@ -214,6 +232,12 @@ wifiread(char *buf, size_t len)
}
#else
int
+cpuread(char *buf, size_t len)
+{
+ return -1;
+}
+
+int
battread(char *buf, size_t len)
{
return -1;