blob: 67f333bdb0baccbf4ef45f45b3dbc904164b39f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
$NetBSD: patch-ag,v 1.2 1999/07/15 18:09:26 chopps Exp $
--- applets/battery/read-battery.c.orig Thu Jul 15 13:59:20 1999
+++ applets/battery/read-battery.c Thu Jul 15 14:41:09 1999
@@ -185,7 +185,44 @@
close(fd);
return TRUE;
-#else /* ! ( __linux__ || __FreeBSD__) */
+#elif defined(__NetBSD__)
+
+ struct apm_power_info aip;
+ int fd;
+
+ fd = open(APMDEV, O_RDONLY);
+ if (fd == -1)
+ {
+ g_error (_("Cannot open /dev/apm; can't get data."));
+ return FALSE;
+ }
+
+ if (ioctl(fd, APM_IOC_GETPOWER, &aip) == -1) {
+ g_error(_("ioctl failed on /dev/apm."));
+ return FALSE;
+ }
+
+ *hours_remaining = aip.minutes_left / 60;
+ aip.minutes_left %= 60;
+ *minutes_remaining = aip.minutes_left;
+
+ /* if APM is not turned on */
+ if (aip.battery_state == APM_BATT_UNKNOWN)
+ {
+ g_error(_("APM battery state unknown! Cannot read battery charge information."));
+ }
+ if (aip.ac_state == APM_AC_UNKNOWN)
+ {
+ g_error(_("APM ac state is unknown! Cannot read battery charge information."));
+ }
+
+ *ac_online = aip.ac_state == APM_AC_ON;
+ *percentage = aip.battery_life;
+
+ close(fd);
+ return TRUE;
+
+#else /* ! ( __linux__ || __FreeBSD__ || __NetBSD__ ) */
/* Assume always connected to power. */
*ac_online = 1;
|