Diffstat (limited to 'libopie2/opiecore/device/odevice_mypal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/device/odevice_mypal.cpp | 55 |
1 files changed, 34 insertions, 21 deletions
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 @@ -22,24 +22,25 @@ -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "odevice_mypal.h" /* QT */ #include <qapplication.h> +#include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <qwindowsystem_qws.h> /* OPIE */ #include <qpe/config.h> #include <qpe/sound.h> #include <qpe/qcopenvelope_qws.h> #include <opie2/okeyfilter.h> #include <opie2/oresource.h> @@ -197,56 +198,68 @@ void MyPal::playAlarmSound() #endif } bool MyPal::setDisplayBrightness ( int bright ) { bool res = false; if ( bright > 255 ) bright = 255; 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; } int MyPal::displayBrightnessResolution() const { switch ( model()) { case Model_MyPal_716: return 7; default: return OAbstractMobileDevice::displayBrightnessResolution(); } } 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; } |