author | sandman <sandman> | 2002-11-01 19:03:41 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-11-01 19:03:41 (UTC) |
commit | 0380a66a6edc8692668a24a49082881b13a4c5fc (patch) (unidiff) | |
tree | 6e1fbfe4133d493c6380da26e38d29678b8c3622 /libopie/odevice.cpp | |
parent | 6860113387bbc86ee33e86327941cafc986e6481 (diff) | |
download | opie-0380a66a6edc8692668a24a49082881b13a4c5fc.zip opie-0380a66a6edc8692668a24a49082881b13a4c5fc.tar.gz opie-0380a66a6edc8692668a24a49082881b13a4c5fc.tar.bz2 |
setDisplayBrightness calculated the wrong backlight level for iPAQs
-rw-r--r-- | libopie/odevice.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 8f4e296..7d8cdbf 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -564,204 +564,202 @@ bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, b | |||
564 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | 564 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); |
565 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | 565 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); |
566 | } | 566 | } |
567 | newkeycode = Key_unknown; | 567 | newkeycode = Key_unknown; |
568 | } | 568 | } |
569 | //nobreak; | 569 | //nobreak; |
570 | 570 | ||
571 | default: | 571 | default: |
572 | break; | 572 | break; |
573 | } | 573 | } |
574 | 574 | ||
575 | if ( newkeycode != keycode ) { | 575 | if ( newkeycode != keycode ) { |
576 | if ( newkeycode != Key_unknown ) | 576 | if ( newkeycode != Key_unknown ) |
577 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | 577 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); |
578 | return true; | 578 | return true; |
579 | } | 579 | } |
580 | else | 580 | else |
581 | return false; | 581 | return false; |
582 | } | 582 | } |
583 | 583 | ||
584 | void iPAQ::timerEvent ( QTimerEvent * ) | 584 | void iPAQ::timerEvent ( QTimerEvent * ) |
585 | { | 585 | { |
586 | killTimer ( m_power_timer ); | 586 | killTimer ( m_power_timer ); |
587 | m_power_timer = 0; | 587 | m_power_timer = 0; |
588 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 588 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
589 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 589 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
590 | } | 590 | } |
591 | 591 | ||
592 | 592 | ||
593 | void iPAQ::alarmSound ( ) | 593 | void iPAQ::alarmSound ( ) |
594 | { | 594 | { |
595 | #if defined( QT_QWS_IPAQ ) // IPAQ | 595 | #if defined( QT_QWS_IPAQ ) // IPAQ |
596 | #ifndef QT_NO_SOUND | 596 | #ifndef QT_NO_SOUND |
597 | static Sound snd ( "alarm" ); | 597 | static Sound snd ( "alarm" ); |
598 | int fd; | 598 | int fd; |
599 | int vol; | 599 | int vol; |
600 | bool vol_reset = false; | 600 | bool vol_reset = false; |
601 | 601 | ||
602 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { | 602 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { |
603 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | 603 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { |
604 | Config cfg ( "qpe" ); | 604 | Config cfg ( "qpe" ); |
605 | cfg. setGroup ( "Volume" ); | 605 | cfg. setGroup ( "Volume" ); |
606 | 606 | ||
607 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | 607 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); |
608 | if ( volalarm < 0 ) | 608 | if ( volalarm < 0 ) |
609 | volalarm = 0; | 609 | volalarm = 0; |
610 | else if ( volalarm > 100 ) | 610 | else if ( volalarm > 100 ) |
611 | volalarm = 100; | 611 | volalarm = 100; |
612 | volalarm |= ( volalarm << 8 ); | 612 | volalarm |= ( volalarm << 8 ); |
613 | 613 | ||
614 | if (( volalarm & 0xff ) > ( vol & 0xff )) { | 614 | if (( volalarm & 0xff ) > ( vol & 0xff )) { |
615 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | 615 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) |
616 | vol_reset = true; | 616 | vol_reset = true; |
617 | } | 617 | } |
618 | } | 618 | } |
619 | } | 619 | } |
620 | 620 | ||
621 | snd. play ( ); | 621 | snd. play ( ); |
622 | while ( !snd. isFinished ( )) | 622 | while ( !snd. isFinished ( )) |
623 | qApp-> processEvents ( ); | 623 | qApp-> processEvents ( ); |
624 | 624 | ||
625 | if ( fd >= 0 ) { | 625 | if ( fd >= 0 ) { |
626 | if ( vol_reset ) | 626 | if ( vol_reset ) |
627 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | 627 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); |
628 | ::close ( fd ); | 628 | ::close ( fd ); |
629 | } | 629 | } |
630 | #endif | 630 | #endif |
631 | #endif | 631 | #endif |
632 | } | 632 | } |
633 | 633 | ||
634 | 634 | ||
635 | bool iPAQ::setSoftSuspend ( bool soft ) | 635 | bool iPAQ::setSoftSuspend ( bool soft ) |
636 | { | 636 | { |
637 | bool res = false; | 637 | bool res = false; |
638 | int fd; | 638 | int fd; |
639 | 639 | ||
640 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | 640 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { |
641 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | 641 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) |
642 | res = true; | 642 | res = true; |
643 | else | 643 | else |
644 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | 644 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); |
645 | 645 | ||
646 | ::close ( fd ); | 646 | ::close ( fd ); |
647 | } | 647 | } |
648 | else | 648 | else |
649 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | 649 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); |
650 | 650 | ||
651 | return res; | 651 | return res; |
652 | } | 652 | } |
653 | 653 | ||
654 | 654 | ||
655 | bool iPAQ::setDisplayBrightness ( int bright ) | 655 | bool iPAQ::setDisplayBrightness ( int bright ) |
656 | { | 656 | { |
657 | bool res = false; | 657 | bool res = false; |
658 | int fd; | 658 | int fd; |
659 | 659 | ||
660 | int maxbright = displayBrightnessResolution ( ); | 660 | if ( bright > 255 ) |
661 | 661 | bright = 255; | |
662 | if ( bright > maxbright ) | ||
663 | bright = maxbright; | ||
664 | if ( bright < 0 ) | 662 | if ( bright < 0 ) |
665 | bright = 0; | 663 | bright = 0; |
666 | 664 | ||
667 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | 665 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { |
668 | FLITE_IN bl; | 666 | FLITE_IN bl; |
669 | bl. mode = 1; | 667 | bl. mode = 1; |
670 | bl. pwr = bright ? 1 : 0; | 668 | bl. pwr = bright ? 1 : 0; |
671 | bl. brightness = bright; | 669 | bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; |
672 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | 670 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); |
673 | ::close ( fd ); | 671 | ::close ( fd ); |
674 | } | 672 | } |
675 | return res; | 673 | return res; |
676 | } | 674 | } |
677 | 675 | ||
678 | int iPAQ::displayBrightnessResolution ( ) const | 676 | int iPAQ::displayBrightnessResolution ( ) const |
679 | { | 677 | { |
680 | switch ( model ( )) { | 678 | switch ( model ( )) { |
681 | case Model_iPAQ_H31xx: | 679 | case Model_iPAQ_H31xx: |
682 | case Model_iPAQ_H36xx: | 680 | case Model_iPAQ_H36xx: |
683 | case Model_iPAQ_H37xx: | 681 | case Model_iPAQ_H37xx: |
684 | return 128; // really 256, but >128 could damage the LCD | 682 | return 128; // really 256, but >128 could damage the LCD |
685 | 683 | ||
686 | case Model_iPAQ_H38xx: | 684 | case Model_iPAQ_H38xx: |
687 | case Model_iPAQ_H39xx: | 685 | case Model_iPAQ_H39xx: |
688 | return 64; | 686 | return 64; |
689 | 687 | ||
690 | default: | 688 | default: |
691 | return 2; | 689 | return 2; |
692 | } | 690 | } |
693 | } | 691 | } |
694 | 692 | ||
695 | 693 | ||
696 | bool iPAQ::hasLightSensor ( ) const | 694 | bool iPAQ::hasLightSensor ( ) const |
697 | { | 695 | { |
698 | return true; | 696 | return true; |
699 | } | 697 | } |
700 | 698 | ||
701 | int iPAQ::readLightSensor ( ) | 699 | int iPAQ::readLightSensor ( ) |
702 | { | 700 | { |
703 | int fd; | 701 | int fd; |
704 | int val = -1; | 702 | int val = -1; |
705 | 703 | ||
706 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { | 704 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { |
707 | char buffer [8]; | 705 | char buffer [8]; |
708 | 706 | ||
709 | if ( ::read ( fd, buffer, 5 ) == 5 ) { | 707 | if ( ::read ( fd, buffer, 5 ) == 5 ) { |
710 | char *endptr; | 708 | char *endptr; |
711 | 709 | ||
712 | buffer [4] = 0; | 710 | buffer [4] = 0; |
713 | val = ::strtol ( buffer + 2, &endptr, 16 ); | 711 | val = ::strtol ( buffer + 2, &endptr, 16 ); |
714 | 712 | ||
715 | if ( *endptr != 0 ) | 713 | if ( *endptr != 0 ) |
716 | val = -1; | 714 | val = -1; |
717 | } | 715 | } |
718 | ::close ( fd ); | 716 | ::close ( fd ); |
719 | } | 717 | } |
720 | 718 | ||
721 | return val; | 719 | return val; |
722 | } | 720 | } |
723 | 721 | ||
724 | int iPAQ::lightSensorResolution ( ) const | 722 | int iPAQ::lightSensorResolution ( ) const |
725 | { | 723 | { |
726 | return 256; | 724 | return 256; |
727 | } | 725 | } |
728 | 726 | ||
729 | /************************************************** | 727 | /************************************************** |
730 | * | 728 | * |
731 | * Zaurus | 729 | * Zaurus |
732 | * | 730 | * |
733 | **************************************************/ | 731 | **************************************************/ |
734 | 732 | ||
735 | 733 | ||
736 | 734 | ||
737 | void Zaurus::init ( ) | 735 | void Zaurus::init ( ) |
738 | { | 736 | { |
739 | d-> m_modelstr = "Zaurus SL5000"; | 737 | d-> m_modelstr = "Zaurus SL5000"; |
740 | d-> m_model = Model_Zaurus_SL5000; | 738 | d-> m_model = Model_Zaurus_SL5000; |
741 | d-> m_vendorstr = "Sharp"; | 739 | d-> m_vendorstr = "Sharp"; |
742 | d-> m_vendor = Vendor_Sharp; | 740 | d-> m_vendor = Vendor_Sharp; |
743 | 741 | ||
744 | QFile f ( "/proc/filesystems" ); | 742 | QFile f ( "/proc/filesystems" ); |
745 | 743 | ||
746 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { | 744 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { |
747 | d-> m_systemstr = "OpenZaurus"; | 745 | d-> m_systemstr = "OpenZaurus"; |
748 | d-> m_system = System_OpenZaurus; | 746 | d-> m_system = System_OpenZaurus; |
749 | 747 | ||
750 | f. close ( ); | 748 | f. close ( ); |
751 | 749 | ||
752 | f. setName ( "/etc/oz_version" ); | 750 | f. setName ( "/etc/oz_version" ); |
753 | if ( f. open ( IO_ReadOnly )) { | 751 | if ( f. open ( IO_ReadOnly )) { |
754 | QTextStream ts ( &f ); | 752 | QTextStream ts ( &f ); |
755 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | 753 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); |
756 | f. close ( ); | 754 | f. close ( ); |
757 | } | 755 | } |
758 | } | 756 | } |
759 | else { | 757 | else { |
760 | d-> m_systemstr = "Zaurus"; | 758 | d-> m_systemstr = "Zaurus"; |
761 | d-> m_system = System_Zaurus; | 759 | d-> m_system = System_Zaurus; |
762 | } | 760 | } |
763 | 761 | ||
764 | 762 | ||
765 | m_leds [0] = Led_Off; | 763 | m_leds [0] = Led_Off; |
766 | } | 764 | } |
767 | 765 | ||