summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_ipaq.cpp71
1 files changed, 29 insertions, 42 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
@@ -397,45 +397,19 @@ bool iPAQ::setDisplayBrightness ( int bright )
397 if ( bright < 0 ) 397 if ( bright < 0 )
398 bright = 0; 398 bright = 0;
399 399
400 QString cmdline; 400 QDir sysClass( "/sys/class/backlight/" );
401
402 switch ( model()) {
403 case Model_iPAQ_H191x:
404 case Model_iPAQ_H4xxx:
405 {
406 QDir sysClass( "/sys/class/backlight/pxafb/" );
407 sysClass.setFilter(QDir::Dirs); 401 sysClass.setFilter(QDir::Dirs);
408 int fd; 402 if ( sysClass.exists() && sysClass.count() > 2 ) {
409 if ( sysClass.exists() ) { 403 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" );
410 QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" ); 404 int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK );
411 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
412 if ( fd ) {
413 char buf[10];
414 buf[0] = bright ? 0 : 4;
415 buf[1] = '\0';
416 res = ( ::write( fd, &buf[0], 2 ) == 0 );
417 ::close( fd );
418 }
419 sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" );
420 fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
421 if ( fd ) { 405 if ( fd ) {
422 char buf[100]; 406 char buf[100];
423 int len = ::snprintf( &buf[0], sizeof buf, "%d", bright ); 407 int val = bright * displayBrightnessResolution() / 255;
408 int len = ::snprintf( &buf[0], sizeof buf, "%d", val );
424 res = ( ::write( fd, &buf[0], len ) == 0 ); 409 res = ( ::write( fd, &buf[0], len ) == 0 );
425 ::close( fd ); 410 ::close( fd );
426 } 411 }
427 } 412 } else {
428 }
429 break;
430
431 case Model_iPAQ_HX4700:
432 cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright );
433 // No Global::shellQuote as we gurantee it to be sane
434 res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
435 break;
436
437
438 default:
439 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 413 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
440 FLITE_IN bl; 414 FLITE_IN bl;
441 bl. mode = 1; 415 bl. mode = 1;
@@ -445,11 +419,28 @@ bool iPAQ::setDisplayBrightness ( int bright )
445 ::close ( fd ); 419 ::close ( fd );
446 } 420 }
447 } 421 }
422
448 return res; 423 return res;
449} 424}
450 425
451int iPAQ::displayBrightnessResolution() const 426int iPAQ::displayBrightnessResolution() const
452{ 427{
428 int res = 16;
429
430 QDir sysClass( "/sys/class/backlight/" );
431 sysClass.setFilter(QDir::Dirs);
432 if ( sysClass.exists() && sysClass.count() > 2 ) {
433 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" );
434 int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK );
435 if ( fd ) {
436 char buf[100];
437 if ( ::read( fd, &buf[0], sizeof buf ) )
438 ::sscanf( &buf[0], "%d", &res );
439 ::close( fd );
440 }
441 return res;
442 }
443
453 switch ( model()) { 444 switch ( model()) {
454 case Model_iPAQ_H31xx: 445 case Model_iPAQ_H31xx:
455 case Model_iPAQ_H36xx: 446 case Model_iPAQ_H36xx:
@@ -478,11 +469,10 @@ bool iPAQ::setDisplayStatus ( bool on )
478 469
479 QString cmdline; 470 QString cmdline;
480 471
481 if ( model() == Model_iPAQ_H191x ) { 472 QDir sysClass( "/sys/class/lcd/" );
482 QDir sysClass( "/sys/class/lcd/pxafb/" );
483 sysClass.setFilter(QDir::Dirs); 473 sysClass.setFilter(QDir::Dirs);
484 if ( sysClass.exists() ) { 474 if ( sysClass.exists() && sysClass.count() > 2 ) {
485 QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" ); 475 QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" );
486 int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); 476 int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
487 if ( fd ) { 477 if ( fd ) {
488 char buf[10]; 478 char buf[10];
@@ -491,14 +481,10 @@ bool iPAQ::setDisplayStatus ( bool on )
491 res = ( ::write( fd, &buf[0], 2 ) == 0 ); 481 res = ( ::write( fd, &buf[0], 2 ) == 0 );
492 ::close( fd ); 482 ::close( fd );
493 } 483 }
494 }
495 return res;
496 } else { 484 } else {
497 return OAbstractMobileDevice::setDisplayStatus(on); 485 res = OAbstractMobileDevice::setDisplayStatus(on);
498 } 486 }
499 487
500 res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
501
502 return res; 488 return res;
503} 489}
504 490
@@ -506,6 +492,7 @@ bool iPAQ::hasLightSensor() const
506{ 492{
507 switch (model()) { 493 switch (model()) {
508 case Model_iPAQ_H191x: 494 case Model_iPAQ_H191x:
495 case Model_iPAQ_H22xx:
509 case Model_iPAQ_H4xxx: 496 case Model_iPAQ_H4xxx:
510 return false; 497 return false;
511 default: 498 default: