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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
$NetBSD: patch-aa,v 1.1.1.1 1999/11/02 21:54:47 hubertf Exp $
--- kapm/apm.cpp.orig Tue Nov 2 06:27:01 1999
+++ kapm/apm.cpp Tue Nov 2 06:27:49 1999
@@ -10,6 +10,13 @@
6) Its packaged as an object
*/
+#ifdef __NetBSD__
+# include <assert.h>
+# include <fcntl.h>
+# include <sys/ioctl.h>
+# include <machine/apmvar.h>
+# include <unistd.h>
+#endif /* __NetBSD__ */
#include <stdio.h>
#include <stdlib.h>
#include "apm.h"
@@ -29,6 +36,7 @@
int apm::check() {
#ifndef DEBUG
+#if defined(Linux)
FILE *str;
if (!(str = fopen( APM_PROC, "r" )))
@@ -43,6 +51,15 @@
if (!(i.apm_flags & APM_32_BIT_SUPPORT))
return 3;
+#elif defined(__NetBSD__)
+ int fd;
+
+ fd = open(APM_PROC, O_RDONLY);
+ if (fd == -1)
+ return 1;
+
+ return 0;
+#endif /* Linux/__NetBSD__ */
#else
// Do initial kernel support emulation setup
@@ -62,6 +79,7 @@
void apm::read()
{
#ifndef DEBUG
+#ifdef Linux
FILE *str;
char buffer[64];
@@ -71,21 +89,59 @@
sscanf( buffer, "%s %d.%d %x %x %x %x %d%% %d %s\n",
(char *)i.driver_version,
- &i.apm_version_major,
- &i.apm_version_minor,
- &i.apm_flags,
- &i.ac_line_status,
- (unsigned int*)(&i.battery_status),
- &i.battery_flags,
- (int*)(&i.battery_percentage),
- &i.battery_time,
- buffer ); // Scribble on our own buffer so save memories
- i.using_minutes = (buffer[0] == *"m");
+ &i.apm_version_major, /* HF: unused */
+ &i.apm_version_minor, /* HF: unused */
+ &i.apm_flags, /* HF: ? */
+ &i.ac_line_status, /* HF: ac_state */
+ (unsigned int*)(&i.battery_status), /* HF: battery_state */
+ &i.battery_flags, /* HF: ? */
+ (int*)(&i.battery_percentage), /* HF: battery_life */
+ &i.battery_time, /* HF: minutes_left? */
+ buffer ); // Scribble on our own buffer so save memories
+ i.using_minutes = (buffer[0] == *"m"); /* HF: 1 */
// Emulate a percentage if none is given
if ((i.battery_percentage == -1) && (i.battery_status != -1))
i.battery_percentage = (3 - i.battery_status) * 25;
-
+
+#elif defined(__NetBSD__)
+
+ int fd, rc;
+ struct apm_power_info apm_pi;
+
+ fd = open(APM_PROC, O_RDONLY);
+ assert(fd != -1);
+ rc = ioctl(fd, APM_IOC_GETPOWER, &apm_pi);
+ assert(rc != -1);
+ close(fd);
+
+ i.driver_version = "NetBSD\0\0\0"; /* can't they document what's
+ expected here ?!? */
+ i.apm_version_major = 1;
+ i.apm_version_minor = 1; /* May be 0 with APM_V10_ONLY
+ - how to find out ? */
+ i.apm_flags = 0; /* what's that? */
+ i.ac_line_status = apm_pi.ac_state; /* one of APM_AC_OFF, APM_AC_ON,
+ APM_AC_BACKUP, or
+ APM_AC_UNKNOWN */
+ i.battery_status = apm_pi.battery_state; /* one of APM_BATT_HIGH,
+ APM_BATT_LOW,
+ APM_BATT_CRITICAL,
+ APM_BATT_CHARGING, or
+ APM_BATT_UNKNOWN */
+ i.battery_flags = 0; /* what's that? */
+ i.battery_percentage = apm_pi.battery_life; /* percentage estimated
+ remaining normal
+ battery life (or 0 if
+ the BIOS cannot provide
+ an estimate) */
+ i.battery_time = apm_pi.minutes_left; /* estimated remaining lifetime
+ (or 0 if the BIOS cannot
+ provide an estimate) */
+ i.using_minutes = 1;
+
+#endif /* Linux, __NetBSD__ */
+
#else
static char percent = 0;
|