diff options
author | Marco S Hyman <marc@cvs.openbsd.org> | 1998-07-18 02:40:36 +0000 |
---|---|---|
committer | Marco S Hyman <marc@cvs.openbsd.org> | 1998-07-18 02:40:36 +0000 |
commit | f34a96fd754aa066dce4677f57e90fc20f2c5048 (patch) | |
tree | a09ab78767d24dc8fb2e0e82bae236c28a266ee6 /sys | |
parent | 8dd06895066a9e212477563f3144041f43d54f0d (diff) |
add ioctl to apm to set message display to one of three states:
1) default: print out all messages. I made this the default so there
would be no visable change to people who are used to what they have.
2) disable all messages. This mode is set by apmd when it starts up.
I think it is reasonable for apmd to disable the driver display
because it is collecting the data and syslogging it. Don't need
to see it three and 4 times.
3) print percentage changes. For those who have a _noisy_ machine
such as me but don't want to see lots and lots of messages I added
a mode where the messages will only be displayed if the estimated
battery percenge changes.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/i386/apm.c | 45 | ||||
-rw-r--r-- | sys/arch/i386/include/apmvar.h | 7 |
2 files changed, 49 insertions, 3 deletions
diff --git a/sys/arch/i386/i386/apm.c b/sys/arch/i386/i386/apm.c index b339cadea12..98597dbeb51 100644 --- a/sys/arch/i386/i386/apm.c +++ b/sys/arch/i386/i386/apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apm.c,v 1.20 1998/04/27 23:39:31 deraadt Exp $ */ +/* $OpenBSD: apm.c,v 1.21 1998/07/18 02:40:33 marc Exp $ */ /*- * Copyright (c) 1995 John T. Kohl. All rights reserved. @@ -83,6 +83,7 @@ struct apm_softc { struct selinfo sc_rsel; struct selinfo sc_xsel; int sc_flags; + int batt_life; int event_count; int event_ptr; struct apm_event_info event_list[APM_NEVENTS]; @@ -91,6 +92,19 @@ struct apm_softc { #define SCFLAG_OWRITE 0x0000002 #define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE) +/* + * Flags to control kernel display + * SCFLAG_NOPRINT: do not output APM power messages due to + * a power change event. + * + * SCFLAG_PCTPRINT: do not output APM power messages due to + * to a power change event unless the battery + * percentage changes. + */ +#define SCFLAG_NOPRINT 0x0008000 +#define SCFLAG_PCTPRINT 0x0004000 +#define SCFLAG_PRINT (SCFLAG_NOPRINT|SCFLAG_PCTPRINT) + #define APMUNIT(dev) (minor(dev)&0xf0) #define APMDEV(dev) (minor(dev)&0x0f) #define APMDEV_NORMAL 0 @@ -194,6 +208,7 @@ apm_power_print (sc, regs) struct apm_softc *sc; struct apmregs *regs; { + sc->batt_life = BATT_LIFE(regs); if (BATT_LIFE(regs) != APM_BATT_LIFE_UNKNOWN) { printf("%s: battery life expectancy %d%%\n", sc->sc_dev.dv_xname, @@ -378,7 +393,10 @@ apm_event_handle(sc, regs) case APM_POWER_CHANGE: DPRINTF(("power status change\n")); error = apm_get_powstat(nregs); - if (error == 0) + if (error == 0 && + (sc->sc_flags & SCFLAG_PRINT) != SCFLAG_NOPRINT && + ((sc->sc_flags & SCFLAG_PRINT) != SCFLAG_PCTPRINT || + sc->batt_life != BATT_LIFE(&nregs))) apm_power_print(sc, &nregs); apm_record_event(sc, regs->bx); break; @@ -830,6 +848,29 @@ apmioctl(dev, cmd, data, flag, p) return EBADF; apm_suspends++; return 0; + case APM_IOC_PRN_CTL: + if ((flag & FWRITE) == 0) + return EBADF; + { + int flag = *(int*)data; + DPRINTF(( "APM_IOC_PRN_CTL: %d\n", flag )); + switch (flag) { + case APM_PRINT_ON: /* enable printing */ + sc->sc_flags &= ~SCFLAG_PRINT; + return 0; + case APM_PRINT_OFF: /* disable printing */ + sc->sc_flags &= ~SCFLAG_PRINT; + sc->sc_flags |= SCFLAG_NOPRINT; + return 0; + case APM_PRINT_PCT: /* disable some printing */ + sc->sc_flags &= ~SCFLAG_PRINT; + sc->sc_flags |= SCFLAG_PCTPRINT; + return 0; + default: + break; + } + } + return EINVAL; case APM_IOC_DEV_CTL: actl = (struct apm_ctl *)data; if ((flag & FWRITE) == 0) diff --git a/sys/arch/i386/include/apmvar.h b/sys/arch/i386/include/apmvar.h index 30286cbeb07..bdbd44d12ff 100644 --- a/sys/arch/i386/include/apmvar.h +++ b/sys/arch/i386/include/apmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: apmvar.h,v 1.4 1997/09/29 03:42:28 mickey Exp $ */ +/* $OpenBSD: apmvar.h,v 1.5 1998/07/18 02:40:35 marc Exp $ */ /* * Copyright (c) 1995 John T. Kohl @@ -217,6 +217,11 @@ struct apm_ctl { #define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ #define APM_IOC_NEXTEVENT _IOR('A', 4, struct apm_event_info) /* fetch event */ #define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ #ifdef _KERNEL extern void apm_cpu_busy __P((void)); |