OSDN Git Service

Make get_fans available in FreeBSD
authorwifiextender <router@archlinux.info>
Thu, 18 Aug 2016 19:12:07 +0000 (21:12 +0200)
committerwifiextender <router@archlinux.info>
Thu, 18 Aug 2016 19:12:07 +0000 (21:12 +0200)
README.md
img/pic5.png [new file with mode: 0644]
src/freebsd_functions.c
src/options.c
src/prototypes/functions.h

index 671ef29..fd0376f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -6,6 +6,10 @@ xmonad
 
 ![](img/pic2.png)
 
+FreeBSD
+
+![](img/pic5.png)
+
 Gather some system information and show it in this statusbar program, not tied to any Window Manager, terminal multiplexer, etc.
 
 Please note that the program won't detect fans connected via molex connetor(s) or external fan controller. Also I have not tested it with fan splitter(s) either.
@@ -14,7 +18,7 @@ The program is smart enough to detect whether some of your fan(s) blades are spi
 
 If you compile your kernel from source code make sure to include your cpu and motherboard sensors as **modules** and not inlined.
 
-Just an example if you use FreeBSD - acpi/aibs, coretemp/amdtemp.
+**Just an example if you use FreeBSD - acpi/aibs, coretemp/amdtemp.**
 
 ![](img/cpu-temp.png)
 ![](img/mobo-temp.png)
diff --git a/img/pic5.png b/img/pic5.png
new file mode 100644 (file)
index 0000000..5f5a6d9
Binary files /dev/null and b/img/pic5.png differ
index 05b1635..6933906 100644 (file)
@@ -161,3 +161,39 @@ get_mobo_temp(char *str1) {
       temp2 / 100 : temp2 / 10)); /* > 9C || < 9C */
   }
 }
+
+
+void
+get_fans(char *str1) {
+  u_int fan[3];
+  char tempstr[VLA], buffer[VLA];
+  char *all_fans = buffer;
+  uint_fast16_t x = 0, y = 0, z = 0, rpm[21];
+
+  memset(fan, 0, sizeof(fan));
+  memset(rpm, 0, sizeof(rpm));
+  size_t len = sizeof(fan);
+
+  for (x = 0; x < 20; x++) {
+    FILL_ARR(tempstr, "%s"UFINT, "dev.aibs.0.fan.", x);
+    memset(fan, 0, sizeof(fan));
+    if (0 != sysctlbyname(tempstr, &fan, &len, NULL, 0)) {
+      break;
+    }
+    rpm[x] = (uint_fast16_t)fan[0];
+  }
+
+  if (0 == rpm[0]) { /* no system fans at all */
+    FILL_STR_ARR(1, str1, NOT_FOUND);
+    return;
+  }
+
+  z = x;
+  for (x = 0; x < z; x++) {
+    if (0 < rpm[x])
+      GLUE2(all_fans, UFINT" ", rpm[x]);
+    else
+      ++y; /* non-spinning | removed | failed fan */
+  }
+  FILL_STR_ARR(1, str1, (y != x ? buffer : NOT_FOUND));
+}
index 751f920..b0c8a00 100644 (file)
@@ -159,6 +159,8 @@ parse_opt(int key, char *arg, struct argp_state *state) {
 
     NEW_LABEL('d', char mobo_temp[VLA], mobo_temp, FMT_TEMP);
 
+    NEW_LABEL('f', char fans[VLA], fans, FMT_FANS, FANS_STR);
+
     NEW_LABEL('t', char taim[VLA], taim, FMT_TIME" ", TIME_STR);
 
     NEW_NET_LABEL('b', char net[VLA], net, 1, FMT_NET, NET_STR);
@@ -181,8 +183,6 @@ parse_opt(int key, char *arg, struct argp_state *state) {
 
     NEW_ARG_LABEL('F', char ssd_model[VLA], ssd_model, FMT_KERN);
 
-    NEW_LABEL('f', char fans[VLA], fans, FMT_FANS, FANS_STR);
-
     NEW_NET_LABEL('h', char nic_drv[VLA], nic_drv, 8, FMT_KERN);
 
     NEW_NET_LABEL('H', char nic_ver[VLA], nic_ver, 9, FMT_KERN);
index cbcc4d7..6a17d1e 100644 (file)
@@ -26,10 +26,10 @@ void get_loadavg(char *);
 void get_voltage(char *);
 void get_mobo(char *);
 void get_mobo_temp(char *);
+void get_fans(char *);
 
 #if defined(__linux__)
 void get_ssd_model(char *, char *);
-void get_fans(char *);
 void get_statio(char *, char *);
 void get_battery(char *);
 #endif