Battery.c 659 Bytes
Newer Older
1
2
3
4
5
6
7
8
/*
htop - freebsd/Battery.c
(C) 2015 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

#include "BatteryMeter.h"
Greg V's avatar
Greg V committed
9
#include <sys/sysctl.h>
10
11

void Battery_getData(double* level, ACPresence* isOnAC) {
Greg V's avatar
Greg V committed
12
13
14
15
16
17
   int life;
   size_t life_len = sizeof(life);
   if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
      *level = -1;
   else
      *level = life;
18

Greg V's avatar
Greg V committed
19
20
21
22
23
24
25
   int acline;
   size_t acline_len = sizeof(acline);
   if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1)
      *isOnAC = AC_ERROR;
   else
      *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT;
}