From b06b849f271079b0dd5d3419ad1162232ff4a9f5 Mon Sep 17 00:00:00 2001 From: aquadran Date: Fri, 09 Jun 2006 08:27:01 +0000 Subject: changed access method for lcd sys params of ipaq h191x and mypal a716 based on Slavek Banko patch --- (limited to 'libopie2') diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index e6e3145..63b60a7 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp @@ -31,6 +31,7 @@ /* QT */ #include +#include #include #include #include @@ -379,12 +380,30 @@ bool iPAQ::setDisplayBrightness ( int bright ) switch ( model()) { case Model_iPAQ_H191x: - if ( !bright ) - cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power"); - else - cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright ); - // No Global::shellQuote as we gurantee it to be sane - res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); + { + 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: @@ -437,7 +456,20 @@ bool iPAQ::setDisplayStatus ( bool on ) QString cmdline; if ( model() == Model_iPAQ_H191x ) { - cmdline = QString::fromLatin1( "echo %1 > /sys/class/lcd/pxafb/power; echo %2 > /sys/class/backlight/pxafb/power").arg( on ? "0" : "4" ).arg( on ? "0" : "4" ); + 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; } else { return OAbstractMobileDevice::setDisplayStatus(on); } @@ -449,7 +481,12 @@ bool iPAQ::setDisplayStatus ( bool on ) bool iPAQ::hasLightSensor() const { - return true; + switch (model()) { + case Model_iPAQ_H191x: + return false; + default: + return true; + } } int iPAQ::readLightSensor() diff --git a/libopie2/opiecore/device/odevice_mypal.cpp b/libopie2/opiecore/device/odevice_mypal.cpp index 7e1245a..7eb8d1d 100644 --- a/libopie2/opiecore/device/odevice_mypal.cpp +++ b/libopie2/opiecore/device/odevice_mypal.cpp @@ -31,6 +31,7 @@ /* QT */ #include +#include #include #include #include @@ -206,19 +207,27 @@ bool MyPal::setDisplayBrightness ( int bright ) if ( bright < 0 ) bright = 0; - QString cmdline; - - switch ( model()) { - case Model_MyPal_716: - if ( !bright ) - cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power"); - else - cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright ); - // No Global::shellQuote as we gurantee it to be sane - res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); - break; - default: - res = OAbstractMobileDevice::setDisplayBrightness(bright); + 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 ); + } } return res; @@ -238,15 +247,19 @@ bool MyPal::setDisplayStatus ( bool on ) { bool res = false; - QString cmdline; - - if ( model() == Model_MyPal_716 ) { - cmdline = QString::fromLatin1( "echo %1 > /sys/class/lcd/pxafb/power; echo %2 > /sys/class/backlight/pxafb/power").arg( on ? "0" : "4" ).arg( on ? "0" : "4" ); - } else { - return OAbstractMobileDevice::setDisplayStatus(on); + QDir sysClass( "/sys/class/lcd/" ); + 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 ); + } } - res = ( ::system( QFile::encodeName(cmdline) ) == 0 ); - return res; } -- cgit v0.9.0.2