$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 +# include +# include +# include +# include +#endif /* __NetBSD__ */ #include #include #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;