Subject: Re: voltage & current program
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 12 Apr 2007 21:54:44 -0500
Newsgroups: comp.lang.lisp
Message-ID: <u8CdncBkLMNpbYPbnZ2dnUVZ_jydnZ2d@speakeasy.net>
sandeep patil <san.gujar@gmail.com> wrote:
+---------------
| On Apr 11, 12:23 pm, r...@rpw3.org (Rob Warnock) wrote:
| > Well, how would you measure it *without* Lisp?!?
| > First tell us that, and then we might have a chance
| > of telling you how Lisp could do the same thing.
| >
| > [Note: Performing physical measurements on the internals
| > of one's system is typically a *very* platform-specific
| > issue having very little to do with programming languages
| > per se and much more to do with what drivers (I2C, ACPI, etc.)
| > your platform provides...]
| >
| > -Rob
| >
| > -----
| > Rob Warnock                     <r...@rpw3.org>
| > 627 26th Avenue                 <URL:http://rpw3.org/>
| > San Mateo, CA 94403             (650)572-2607
| 
| Dear sir
| 
| i want to access voltage & current value in my Lisp Program.
| if you have any idea about it then tell me.
| to access value perform operaton on it.
| i have plan to ight program for laptop battery.
+---------------

You *STILL* haven't answered my question!!! How would you do
it in *any* other programming language of your choice on the
particular operating system and platform you're running on???!?
(...which you haven't told us.) The answer depends *COMPLETELY*
on your operating system and platform!!

For example, once upon a time, I ran CMUCL on a laptop that was
running FreeBSD 2.2.6, and *that* laptop had only APM, not ACPI,
so on *that particular* laptop with *that particular* operating
system, one opened "/dev/apm" and did an "APMIO_GETINFO" ioctl(),
which one could do from within CMUCL as follows [roughly, not tested]:

    (use-package :alien)
    (use-package :c-call)

    (def-alien-type nil
      (struct apm_info
	(ai_infoversion  unsigned-int)
	(ai_major        unsigned-int)
	(ai_minor        unsigned-int)
	(ai_acline       unsigned-int)
	(ai_batt_stat    unsigned-int)
	(ai_batt_life    unsigned-int)
	(ai_batt_time    int)
	(ai_status       unsigned-int)
	(ai_batteries    unsigned-int)
	(ai_capabilities unsigned-int)
	(ai_spare0       unsigned-int)
	(ai_spare1       unsigned-int)
	(ai_spare2       unsigned-int)
	(ai_spare3       unsigned-int)
	(ai_spare4       unsigned-int)
	(ai_spare5       unsigned-int)))

    (defvar *ai* (make-alien '(struct apm_info)))

    (defconstant +APMIO_GETINFO+ #x4040500b)

    (let ((fd (unix:unix-open "/dev/apm" 0 0)))
      (unless fd
	(error ...some useful error message...))
      (multiple-value-bind (result err)
	  (unix:unix-ioctl fd +APMIO_GETINFO+ (alien-sap *ai*))
        (when err
	  (error ...some useful error message...))
        (list (slot *ai* 'ai_acline)
	      (slot *ai* 'ai_batt_life))))

    ==> (0 73)	; If you're running on the battery & it's 73% charged.

But *none* of that would work on the laptop I use today, since
it supports *only* ACPI and not APM at all.

As I said before [twice], how you do this is *VERY* operating
system and platform dependent [and Lisp-implementation-dependent].
Without those details, no-one can help you!!


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607