summaryrefslogtreecommitdiffstats
path: root/openbsd
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2020-11-17 18:12:38 +1100
committerNathan Scott <nathans@redhat.com>2020-11-18 10:17:33 +1100
commitea9622b8c9444d92007f24fc54597f83c498f11d (patch)
tree13cb45909d2c873b7b09ec59580d6a8db4676b0b /openbsd
parente3af8d0d0851dd6ce25446a7f9a99e2127795a78 (diff)
Merge individual Battery.[ch] files into Platform.[ch]
Consistent with everything else involving platform-specific calls from core htop code.
Diffstat (limited to 'openbsd')
-rw-r--r--openbsd/Battery.c74
-rw-r--r--openbsd/Battery.h15
-rw-r--r--openbsd/Platform.c59
3 files changed, 59 insertions, 89 deletions
diff --git a/openbsd/Battery.c b/openbsd/Battery.c
deleted file mode 100644
index b72253e0..00000000
--- a/openbsd/Battery.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
-htop - openbsd/Battery.c
-(C) 2015 Hisham H. Muhammad
-(C) 2015 Michael McConville
-Released under the GNU GPLv2, see the COPYING file
-in the source distribution for its full text.
-*/
-
-#include "Battery.h"
-
-#include <sys/sysctl.h>
-#include <sys/sensors.h>
-#include <errno.h>
-#include <math.h>
-#include <string.h>
-
-static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) {
- for (int devn = 0;; devn++) {
- mib[2] = devn;
- if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) {
- if (errno == ENXIO)
- continue;
- if (errno == ENOENT)
- return false;
- }
- if (strcmp(name, snsrdev->xname) == 0) {
- return true;
- }
- }
-}
-
-void Battery_getData(double* level, ACPresence* isOnAC) {
- static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
- struct sensor s;
- size_t slen = sizeof(struct sensor);
- struct sensordev snsrdev;
- size_t sdlen = sizeof(struct sensordev);
-
- bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
-
- *level = NAN;
- if (found) {
- /* last full capacity */
- mib[3] = 7;
- mib[4] = 0;
- double last_full_capacity = 0;
- if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
- last_full_capacity = s.value;
- }
- if (last_full_capacity > 0) {
- /* remaining capacity */
- mib[3] = 7;
- mib[4] = 3;
- if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
- double charge = s.value;
- *level = 100 * (charge / last_full_capacity);
- if (charge >= last_full_capacity) {
- *level = 100;
- }
- }
- }
- }
-
- found = findDevice("acpiac0", mib, &snsrdev, &sdlen);
-
- *isOnAC = AC_ERROR;
- if (found) {
- mib[3] = 9;
- mib[4] = 0;
- if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
- *isOnAC = s.value;
- }
- }
-}
diff --git a/openbsd/Battery.h b/openbsd/Battery.h
deleted file mode 100644
index 60b632d2..00000000
--- a/openbsd/Battery.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef HEADER_Battery
-#define HEADER_Battery
-/*
-htop - openbsd/Battery.h
-(C) 2015 Hisham H. Muhammad
-(C) 2015 Michael McConville
-Released under the GNU GPLv2, see the COPYING file
-in the source distribution for its full text.
-*/
-
-#include "BatteryMeter.h"
-
-void Battery_getData(double* level, ACPresence* isOnAC);
-
-#endif
diff --git a/openbsd/Platform.c b/openbsd/Platform.c
index 5601048d..bf045396 100644
--- a/openbsd/Platform.c
+++ b/openbsd/Platform.c
@@ -25,6 +25,7 @@ in the source distribution for its full text.
#include <sys/param.h>
#include <sys/sysctl.h>
+#include <sys/sensors.h>
#include <sys/swap.h>
#include <unistd.h>
@@ -38,6 +39,7 @@ in the source distribution for its full text.
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
+#include <errno.h>
#include <math.h>
@@ -322,3 +324,60 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
*packetsTransmitted = 0;
return false;
}
+
+static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) {
+ for (int devn = 0;; devn++) {
+ mib[2] = devn;
+ if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) {
+ if (errno == ENXIO)
+ continue;
+ if (errno == ENOENT)
+ return false;
+ }
+ if (strcmp(name, snsrdev->xname) == 0) {
+ return true;
+ }
+ }
+}
+
+void Platform_getBattery(double* level, ACPresence* isOnAC) {
+ static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
+ struct sensor s;
+ size_t slen = sizeof(struct sensor);
+ struct sensordev snsrdev;
+ size_t sdlen = sizeof(struct sensordev);
+
+ bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
+
+ *level = NAN;
+ if (found) {
+ /* last full capacity */
+ mib[3] = 7;
+ mib[4] = 0;
+ double last_full_capacity = 0;
+ if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1)
+ last_full_capacity = s.value;
+ if (last_full_capacity > 0) {
+ /* remaining capacity */
+ mib[3] = 7;
+ mib[4] = 3;
+ if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
+ double charge = s.value;
+ *level = 100 * (charge / last_full_capacity);
+ if (charge >= last_full_capacity) {
+ *level = 100;
+ }
+ }
+ }
+ }
+
+ found = findDevice("acpiac0", mib, &snsrdev, &sdlen);
+
+ *isOnAC = AC_ERROR;
+ if (found) {
+ mib[3] = 9;
+ mib[4] = 0;
+ if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1)
+ *isOnAC = s.value;
+ }
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy