author | erik <erik> | 2007-02-08 01:15:31 (UTC) |
---|---|---|
committer | erik <erik> | 2007-02-08 01:15:31 (UTC) |
commit | c36a2e25a8875a31957968482ba8a0831a8b0aba (patch) (unidiff) | |
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 | |||
@@ -368,173 +368,160 @@ bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, b | |||
368 | 368 | ||
369 | void iPAQ::timerEvent ( QTimerEvent * ) | 369 | void iPAQ::timerEvent ( QTimerEvent * ) |
370 | { | 370 | { |
371 | killTimer ( m_power_timer ); | 371 | killTimer ( m_power_timer ); |
372 | m_power_timer = 0; | 372 | m_power_timer = 0; |
373 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 373 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
374 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 374 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
375 | } | 375 | } |
376 | 376 | ||
377 | 377 | ||
378 | void iPAQ::playAlarmSound() | 378 | void iPAQ::playAlarmSound() |
379 | { | 379 | { |
380 | #ifndef QT_NO_SOUND | 380 | #ifndef QT_NO_SOUND |
381 | static Sound snd ( "alarm" ); | 381 | static Sound snd ( "alarm" ); |
382 | if(!snd.isFinished()) | 382 | if(!snd.isFinished()) |
383 | return; | 383 | return; |
384 | 384 | ||
385 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); | 385 | changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); |
386 | snd. play(); | 386 | snd. play(); |
387 | #endif | 387 | #endif |
388 | } | 388 | } |
389 | 389 | ||
390 | bool iPAQ::setDisplayBrightness ( int bright ) | 390 | bool iPAQ::setDisplayBrightness ( int bright ) |
391 | { | 391 | { |
392 | bool res = false; | 392 | bool res = false; |
393 | int fd; | 393 | int fd; |
394 | 394 | ||
395 | if ( bright > 255 ) | 395 | if ( bright > 255 ) |
396 | bright = 255; | 396 | bright = 255; |
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 | 401 | sysClass.setFilter(QDir::Dirs); | |
402 | switch ( model()) { | 402 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
403 | case Model_iPAQ_H191x: | 403 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" ); |
404 | case Model_iPAQ_H4xxx: | 404 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
405 | { | 405 | if ( fd ) { |
406 | QDir sysClass( "/sys/class/backlight/pxafb/" ); | 406 | char buf[100]; |
407 | sysClass.setFilter(QDir::Dirs); | 407 | int val = bright * displayBrightnessResolution() / 255; |
408 | int fd; | 408 | int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); |
409 | if ( sysClass.exists() ) { | 409 | res = ( ::write( fd, &buf[0], len ) == 0 ); |
410 | QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" ); | 410 | ::close( fd ); |
411 | fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | 411 | } |
412 | if ( fd ) { | 412 | } else { |
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 ) { | ||
422 | char buf[100]; | ||
423 | int len = ::snprintf( &buf[0], sizeof buf, "%d", bright ); | ||
424 | res = ( ::write( fd, &buf[0], len ) == 0 ); | ||
425 | ::close( fd ); | ||
426 | } | ||
427 | } | ||
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; |
442 | bl. pwr = bright ? 1 : 0; | 416 | bl. pwr = bright ? 1 : 0; |
443 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; | 417 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; |
444 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | 418 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); |
445 | ::close ( fd ); | 419 | ::close ( fd ); |
446 | } | 420 | } |
447 | } | 421 | } |
422 | |||
448 | return res; | 423 | return res; |
449 | } | 424 | } |
450 | 425 | ||
451 | int iPAQ::displayBrightnessResolution() const | 426 | int 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: |
456 | case Model_iPAQ_H37xx: | 447 | case Model_iPAQ_H37xx: |
457 | return 128; // really 256, but >128 could damage the LCD | 448 | return 128; // really 256, but >128 could damage the LCD |
458 | 449 | ||
459 | case Model_iPAQ_H38xx: | 450 | case Model_iPAQ_H38xx: |
460 | case Model_iPAQ_H39xx: | 451 | case Model_iPAQ_H39xx: |
461 | return 64; | 452 | return 64; |
462 | case Model_iPAQ_H5xxx: | 453 | case Model_iPAQ_H5xxx: |
463 | case Model_iPAQ_HX4700: | 454 | case Model_iPAQ_HX4700: |
464 | case Model_iPAQ_H4xxx: | 455 | case Model_iPAQ_H4xxx: |
465 | return 255; | 456 | return 255; |
466 | case Model_iPAQ_H191x: | 457 | case Model_iPAQ_H191x: |
467 | return 7; | 458 | return 7; |
468 | case Model_iPAQ_H1940: | 459 | case Model_iPAQ_H1940: |
469 | return 44; | 460 | return 44; |
470 | default: | 461 | default: |
471 | return 2; | 462 | return 2; |
472 | } | 463 | } |
473 | } | 464 | } |
474 | 465 | ||
475 | bool iPAQ::setDisplayStatus ( bool on ) | 466 | bool iPAQ::setDisplayStatus ( bool on ) |
476 | { | 467 | { |
477 | bool res = false; | 468 | bool res = false; |
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/" ); | 473 | sysClass.setFilter(QDir::Dirs); |
483 | sysClass.setFilter(QDir::Dirs); | 474 | if ( sysClass.exists() && sysClass.count() > 2 ) { |
484 | if ( sysClass.exists() ) { | 475 | QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" ); |
485 | QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" ); | 476 | int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK ); |
486 | int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK ); | 477 | if ( fd ) { |
487 | if ( fd ) { | 478 | char buf[10]; |
488 | char buf[10]; | 479 | buf[0] = on ? 0 : 4; |
489 | buf[0] = on ? 0 : 4; | 480 | buf[1] = '\0'; |
490 | buf[1] = '\0'; | 481 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); |
491 | res = ( ::write( fd, &buf[0], 2 ) == 0 ); | 482 | ::close( fd ); |
492 | ::close( fd ); | 483 | } |
493 | } | ||
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 | ||
505 | bool iPAQ::hasLightSensor() const | 491 | 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: |
512 | return true; | 499 | return true; |
513 | } | 500 | } |
514 | } | 501 | } |
515 | 502 | ||
516 | int iPAQ::readLightSensor() | 503 | int iPAQ::readLightSensor() |
517 | { | 504 | { |
518 | int fd; | 505 | int fd; |
519 | int val = -1; | 506 | int val = -1; |
520 | 507 | ||
521 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { | 508 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { |
522 | char buffer [8]; | 509 | char buffer [8]; |
523 | 510 | ||
524 | if ( ::read ( fd, buffer, 5 ) == 5 ) { | 511 | if ( ::read ( fd, buffer, 5 ) == 5 ) { |
525 | char *endptr; | 512 | char *endptr; |
526 | 513 | ||
527 | buffer [4] = 0; | 514 | buffer [4] = 0; |
528 | val = ::strtol ( buffer + 2, &endptr, 16 ); | 515 | val = ::strtol ( buffer + 2, &endptr, 16 ); |
529 | 516 | ||
530 | if ( *endptr != 0 ) | 517 | if ( *endptr != 0 ) |
531 | val = -1; | 518 | val = -1; |
532 | } | 519 | } |
533 | ::close ( fd ); | 520 | ::close ( fd ); |
534 | } | 521 | } |
535 | 522 | ||
536 | return val; | 523 | return val; |
537 | } | 524 | } |
538 | 525 | ||
539 | int iPAQ::lightSensorResolution() const | 526 | int iPAQ::lightSensorResolution() const |
540 | { | 527 | { |