-rw-r--r-- | libopie/odevice.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 58bd663..44fe35f 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -85,2 +85,5 @@ public: virtual bool setLedState ( OLed led, OLedState st ); + + virtual bool hasLightSensor ( ) const; + virtual int readLightSensor ( ); @@ -358,2 +361,11 @@ bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) +bool ODevice::hasLightSensor ( ) const +{ + return false; +} + +int ODevice::readLightSensor ( ) +{ + return -1; +} @@ -668,2 +680,32 @@ int iPAQ::displayBrightnessResolution ( ) const +bool iPAQ::hasLightSensor ( ) const +{ + return true; +} + +int iPAQ::readLightSensor ( ) +{ + int fd; + int val = -1; + + if (( fd = ::open ( "/proc/hal/lightsensor", O_RDONLY )) >= 0 ) { + char buffer [5]; + + if ( ::read ( fd, buffer, 4 ) == 4 ) { + char *endptr; + + buffer [4] = 0; + val = ::strtol ( buffer + 2, &endptr, 16 ); + + if ( *endptr != 0 ) + val = -1; + } + + ::close ( fd ); + } + + return val; +} + + /************************************************** |