[sane-devel] SANE and switching off the scanner lamp.

Henning Meier-Geinitz henning@meier-geinitz.de
Tue, 11 May 2004 22:25:54 +0200


Hi,

On Mon, May 10, 2004 at 11:17:10AM +0100, Adrian Perez Jorge wrote:
>  Is there any proposal or standard way in SANE to check for scanner 
> inactivity to switch off the scanner lamp?  I have read some scanner 
> backends source code and some of them have an option to switch off the 
> scanner lamp after scanning; others have a little prog (look into SANE 
> `tools/' directory) that polls the scanner and switch off the lamp after 
> a period of inactivity.

Quite some scanners turn off the lamp after a fixed (or setable) time
automatically without backend intervention. Others are dumb and only
know "on" and "off".

>  I belive the interest to switch off the lamp is a matter of power 
> savings and lamp lifetime.  But switching off the lamp after each 
> scanning slows down the scanning process of a few bunch of pages, 

The backend could just switch off the lamp in sane_close. So if a
gaphical frontend like xsane is used, the lamp stays on during the
scans and will be shut off when leaving xsane.

With frontends like scanimage this doesn't work. In the gt68xx backend
I use an option to keep the lamp on for such cases.

> because there should be a warm up period in wich the backend should 
> wait.  (It's easier to program if the warm up period is supposed to be 
> constant, but a big constant will make that period longer than just the 
> necessary; but if not constant, is there a safe way to detect when the 
> lamp is ready to scan?  maybe during coarse calibration?)

Yes. Move the scan head to the calibration area, stop the motor. Scan
a line. calculate medium white level. Wait one second. Scan a new
line. Repeate until brightness doesn't increase any more.

>  It will be more adecuate to switch off the lamp after some period of 
> inactivity, so there is no pause between page scannings due to lamp 
> management.  Just inactivity period needs to be tuned for economy and 
> user slowness.

If you really want to do that, use sanei_thread to fork a sleeping
process in the backend that turns off the lamp after a timeout. Reset
the timeout with every scan.

>  A polling daemon could be a sollution but the SANE API should be aware 
> to detect a scanner in use

A scanner is in use when sane_open has been called on that scanner.
With most (but not all) backends you can't access the scanner while
it's opened. It's locked for a reason :-)

> and a standard way to switch off the lamp needs to exist.

Well, we could define a well-known option for that. I'm not sure if
it's really useful, however.

> A broadcaster/observer pattern could also be used here (somewhere
> :-)), so just backends instances that needs to manage the lamp are
> notified.

I think that doesn't fit in the SANE paradigm. There is only one
frontend which connects to a backend. You can't expect that a backend
accepts sane_open for the sam,e scanner twice.

>  Scanner button management also needs a similar solution (some posts 
> exists in the mailing list about that subject).  Is D-BUS 
> (http://www.freedesktop.org/Software/dbus) useful for all this?

Scanner button management can be done by the same frontend that does
the scan. Or by a daemon that starts a fontend. At least it's not
necessary to run two frontends at the same time as for lamp management.

Concerning the button discussion: I'm still waiting for patches to the
SANE 2 standard :-)

Bye,
  Henning