Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 May 2004 22:03:44 -0700 (PDT)
From:      Nate Lawson <nate@root.org>
To:        "Liam J. Foy" <liamfoy@sepulcrum.org>
Cc:        freebsd-acpi@freebsd.org
Subject:   Re: apm code
Message-ID:  <20040526215940.F87914@root.org>
In-Reply-To: <20040520205712.57abc39b.liamfoy@sepulcrum.org>
References:  <20040520205712.57abc39b.liamfoy@sepulcrum.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 20 May 2004, Liam J. Foy wrote:
> Hey,
>
> Just writing to the list to make sure am correct here. The issue concerns /usr/src/usr.sbin/apm/apm.c.
>
> --- /usr/src/usr.sbin/apm/apm.c	Thu May 20 20:30:57 2004
> +++ /hd2/apm.c	Thu May 20 20:44:36 2004
> @@ -174,7 +174,7 @@
>  	printf("Remaining battery life: ");
>  	if (aip->ai_batt_life == 255)
>  		printf("unknown\n");
> -	else if (aip->ai_batt_life <= 100)
> +	else if (aip->ai_batt_life >= 0 && aip->ai_batt_life <= 100)
>  		printf("%d%%\n", aip->ai_batt_life);
>  	else
>  		printf("invalid value (0x%x)\n", aip->ai_batt_life);
>
> The above patch will make apm print invalid value when ai_batt_life does not equal 0-100. The reason for this was the the current code was printing -1 as a so called valid value(normally when acline is connected). I dont think printing -1 is correct, and really it should be printing invalid value since that is what it is. Do you guys agree with me or does -1 symbolise something?
>
> Something else I am curious over is this snippet of code:
>
> if (aip->ai_infoversion >= 1) {
> 		printf("Number of batteries: ");
> 		if (aip->ai_batteries == (u_int) -1)
> 			printf("unknown\n");
> 		else {
>
> ai_batteries in machine/apm_bios.h is defined as u_int. Yet the above code is testing for -1. I _think_ this should be testing for 255(unknown). Anyone shead any light on this? I ask since I do not know apm very well. Would you guys agree my patch is correct also?

Are you using ACPI or APM for your power management?  Also, what values
are reported as "invalid" besides "Remaining battery life"?  The usermode
code is correct in comparing against 255 but it may be that the kernel
code is setting things to -1 (0xffffffff) which != 0xff.

-Nate



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040526215940.F87914>