author | erik <erik> | 2007-02-08 01:15:31 (UTC) |
---|---|---|
committer | erik <erik> | 2007-02-08 01:15:31 (UTC) |
commit | c36a2e25a8875a31957968482ba8a0831a8b0aba (patch) (side-by-side diff) | |
tree | 73c5f9231d3fe7157d814d8a948f27e31eb87c81 | |
parent | c4aaefcbe64cecb35f1f1bfa10337e95d8ae439c (diff) | |
download | opie-c36a2e25a8875a31957968482ba8a0831a8b0aba.zip opie-c36a2e25a8875a31957968482ba8a0831a8b0aba.tar.gz opie-c36a2e25a8875a31957968482ba8a0831a8b0aba.tar.bz2 |
This commit provides support for any iPAQ handheld that runs a 2.6 kernel
and follows the backlight class in sysfs. This patch was originally done
by an unknown poster and maintained by Paul S. Thanks all who contributed.
-rw-r--r-- | libopie2/opiecore/device/odevice_ipaq.cpp | 101 |
1 files changed, 44 insertions, 57 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 16ecc27..02b685a 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp @@ -352,191 +352,178 @@ bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, b QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); } newkeycode = Key_unknown; break; } } if ( newkeycode != keycode ) { if ( newkeycode != Key_unknown ) QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); return true; } else return false; } void iPAQ::timerEvent ( QTimerEvent * ) { killTimer ( m_power_timer ); m_power_timer = 0; QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); } void iPAQ::playAlarmSound() { #ifndef QT_NO_SOUND static Sound snd ( "alarm" ); if(!snd.isFinished()) return; changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); snd. play(); #endif } bool iPAQ::setDisplayBrightness ( int bright ) { bool res = false; int fd; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; - QString cmdline; - - switch ( model()) { - case Model_iPAQ_H191x: - case Model_iPAQ_H4xxx: - { - QDir sysClass( "/sys/class/backlight/pxafb/" ); - sysClass.setFilter(QDir::Dirs); - int fd; - if ( sysClass.exists() ) { - QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" ); - fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); - if ( fd ) { - char buf[10]; - buf[0] = bright ? 0 : 4; - buf[1] = '\0'; - res = ( ::write( fd, &buf[0], 2 ) == 0 ); - ::close( fd ); - } - sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" ); - fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); - if ( fd ) { - char buf[100]; - int len = ::snprintf( &buf[0], sizeof buf, "%d", bright ); - res = ( ::write( fd, &buf[0], len ) == 0 ); - ::close( fd ); - } - } - } - break; - - case Model_iPAQ_HX4700: - cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright ); - // No Global::shellQuote as we gurantee it to be sane - res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); - break; - - - default: + QDir sysClass( "/sys/class/backlight/" ); + sysClass.setFilter(QDir::Dirs); + if ( sysClass.exists() && sysClass.count() > 2 ) { + QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); + int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); + if ( fd ) { + char buf[100]; + int val = bright * displayBrightnessResolution() / 255; + int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); + res = ( ::write( fd, &buf[0], len ) == 0 ); + ::close( fd ); + } + } else { if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { FLITE_IN bl; bl. mode = 1; bl. pwr = bright ? 1 : 0; bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); ::close ( fd ); } } + return res; } int iPAQ::displayBrightnessResolution() const { + int res = 16; + + QDir sysClass( "/sys/class/backlight/" ); + sysClass.setFilter(QDir::Dirs); + if ( sysClass.exists() && sysClass.count() > 2 ) { + QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" ); + int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK ); + if ( fd ) { + char buf[100]; + if ( ::read( fd, &buf[0], sizeof buf ) ) + ::sscanf( &buf[0], "%d", &res ); + ::close( fd ); + } + return res; + } + switch ( model()) { case Model_iPAQ_H31xx: case Model_iPAQ_H36xx: case Model_iPAQ_H37xx: return 128; // really 256, but >128 could damage the LCD case Model_iPAQ_H38xx: case Model_iPAQ_H39xx: return 64; case Model_iPAQ_H5xxx: case Model_iPAQ_HX4700: case Model_iPAQ_H4xxx: return 255; case Model_iPAQ_H191x: return 7; case Model_iPAQ_H1940: return 44; default: return 2; } } bool iPAQ::setDisplayStatus ( bool on ) { bool res = false; QString cmdline; - if ( model() == Model_iPAQ_H191x ) { - QDir sysClass( "/sys/class/lcd/pxafb/" ); - sysClass.setFilter(QDir::Dirs); - if ( sysClass.exists() ) { - QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" ); - int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); - if ( fd ) { - char buf[10]; - buf[0] = on ? 0 : 4; - buf[1] = '\0'; - res = ( ::write( fd, &buf[0], 2 ) == 0 ); - ::close( fd ); - } - } - return res; + QDir sysClass( "/sys/class/lcd/" ); + sysClass.setFilter(QDir::Dirs); + if ( sysClass.exists() && sysClass.count() > 2 ) { + QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); + int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); + if ( fd ) { + char buf[10]; + buf[0] = on ? 0 : 4; + buf[1] = '\0'; + res = ( ::write( fd, &buf[0], 2 ) == 0 ); + ::close( fd ); + } } else { - return OAbstractMobileDevice::setDisplayStatus(on); + res = OAbstractMobileDevice::setDisplayStatus(on); } - res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); - return res; } bool iPAQ::hasLightSensor() const { switch (model()) { case Model_iPAQ_H191x: + case Model_iPAQ_H22xx: case Model_iPAQ_H4xxx: return false; default: return true; } } int iPAQ::readLightSensor() { int fd; int val = -1; if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { char buffer [8]; if ( ::read ( fd, buffer, 5 ) == 5 ) { char *endptr; buffer [4] = 0; val = ::strtol ( buffer + 2, &endptr, 16 ); if ( *endptr != 0 ) val = -1; } ::close ( fd ); } return val; } int iPAQ::lightSensorResolution() const { return 256; } |