author | sandman <sandman> | 2002-10-28 04:41:42 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-28 04:41:42 (UTC) |
commit | 226ddd19ef0adeb279c3a864e24cbfcf556b2f17 (patch) (unidiff) | |
tree | c1c95e39fa0634a881ffbeba190653dc7ee6201c | |
parent | 37397a824a807195ba440117a6bac0043ea788a1 (diff) | |
download | opie-226ddd19ef0adeb279c3a864e24cbfcf556b2f17.zip opie-226ddd19ef0adeb279c3a864e24cbfcf556b2f17.tar.gz opie-226ddd19ef0adeb279c3a864e24cbfcf556b2f17.tar.bz2 |
- read ( fd, buffer, 4 ); return 5 (!!) for /proc/hal/light_sensor
so we better try to read 5 bytes ...
- small "off by one" fix for the lcd brightness resolution
-rw-r--r-- | libopie/odevice.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 6ea4d45..2b7e927 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -629,123 +629,123 @@ bool iPAQ::setSoftSuspend ( bool soft ) | |||
629 | { | 629 | { |
630 | bool res = false; | 630 | bool res = false; |
631 | int fd; | 631 | int fd; |
632 | 632 | ||
633 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | 633 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { |
634 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | 634 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) |
635 | res = true; | 635 | res = true; |
636 | else | 636 | else |
637 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | 637 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); |
638 | 638 | ||
639 | ::close ( fd ); | 639 | ::close ( fd ); |
640 | } | 640 | } |
641 | else | 641 | else |
642 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | 642 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); |
643 | 643 | ||
644 | return res; | 644 | return res; |
645 | } | 645 | } |
646 | 646 | ||
647 | 647 | ||
648 | bool iPAQ::setDisplayBrightness ( int bright ) | 648 | bool iPAQ::setDisplayBrightness ( int bright ) |
649 | { | 649 | { |
650 | bool res = false; | 650 | bool res = false; |
651 | int fd; | 651 | int fd; |
652 | 652 | ||
653 | if ( bright > 255 ) | 653 | if ( bright > 255 ) |
654 | bright = 255; | 654 | bright = 255; |
655 | if ( bright < 0 ) | 655 | if ( bright < 0 ) |
656 | bright = 0; | 656 | bright = 0; |
657 | 657 | ||
658 | // 128 is the maximum if you want a decent lifetime for the LCD | 658 | // 128 is the maximum if you want a decent lifetime for the LCD |
659 | 659 | ||
660 | if ( bright > 1 ) | 660 | if ( bright > 1 ) |
661 | bright = (int) ( 0.5 + ( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic | 661 | bright = (int) ( 0.5 + ( ::pow ( 2, double( bright ) / 255.0 ) - 1 ) * 128.0 ); // logarithmic |
662 | //bright = ( bright + 1 ) / 2; | 662 | //bright = ( bright + 1 ) / 2; |
663 | 663 | ||
664 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | 664 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { |
665 | FLITE_IN bl; | 665 | FLITE_IN bl; |
666 | bl. mode = 1; | 666 | bl. mode = 1; |
667 | bl. pwr = bright ? 1 : 0; | 667 | bl. pwr = bright ? 1 : 0; |
668 | bl. brightness = bright; | 668 | bl. brightness = bright; |
669 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | 669 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); |
670 | ::close ( fd ); | 670 | ::close ( fd ); |
671 | } | 671 | } |
672 | return res; | 672 | return res; |
673 | } | 673 | } |
674 | 674 | ||
675 | int iPAQ::displayBrightnessResolution ( ) const | 675 | int iPAQ::displayBrightnessResolution ( ) const |
676 | { | 676 | { |
677 | return 255; // really 128, but logarithmic control is smoother this way | 677 | return 256; // really 128, but logarithmic control is smoother this way |
678 | } | 678 | } |
679 | 679 | ||
680 | 680 | ||
681 | bool iPAQ::hasLightSensor ( ) const | 681 | bool iPAQ::hasLightSensor ( ) const |
682 | { | 682 | { |
683 | return true; | 683 | return true; |
684 | } | 684 | } |
685 | 685 | #include <errno.h> | |
686 | #include <string.h> | ||
686 | int iPAQ::readLightSensor ( ) | 687 | int iPAQ::readLightSensor ( ) |
687 | { | 688 | { |
688 | int fd; | 689 | int fd; |
689 | int val = -1; | 690 | int val = -1; |
690 | 691 | ||
691 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { | 692 | if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { |
692 | char buffer [5]; | 693 | char buffer [8]; |
693 | 694 | ||
694 | if ( ::read ( fd, buffer, 4 ) == 4 ) { | 695 | if ( ::read ( fd, buffer, 5 ) == 5 ) |
695 | char *endptr; | 696 | char *endptr; |
696 | 697 | ||
697 | buffer [4] = 0; | 698 | buffer [4] = 0; |
698 | val = ::strtol ( buffer + 2, &endptr, 16 ); | 699 | val = ::strtol ( buffer + 2, &endptr, 16 ); |
699 | 700 | ||
700 | if ( *endptr != 0 ) | 701 | if ( *endptr != 0 ) |
701 | val = -1; | 702 | val = -1; |
702 | } | 703 | } |
703 | |||
704 | ::close ( fd ); | 704 | ::close ( fd ); |
705 | } | 705 | } |
706 | 706 | ||
707 | return val; | 707 | return val; |
708 | } | 708 | } |
709 | 709 | ||
710 | 710 | ||
711 | /************************************************** | 711 | /************************************************** |
712 | * | 712 | * |
713 | * Zaurus | 713 | * Zaurus |
714 | * | 714 | * |
715 | **************************************************/ | 715 | **************************************************/ |
716 | 716 | ||
717 | 717 | ||
718 | 718 | ||
719 | void Zaurus::init ( ) | 719 | void Zaurus::init ( ) |
720 | { | 720 | { |
721 | d-> m_modelstr = "Zaurus SL5000"; | 721 | d-> m_modelstr = "Zaurus SL5000"; |
722 | d-> m_model = Model_Zaurus_SL5000; | 722 | d-> m_model = Model_Zaurus_SL5000; |
723 | d-> m_vendorstr = "Sharp"; | 723 | d-> m_vendorstr = "Sharp"; |
724 | d-> m_vendor = Vendor_Sharp; | 724 | d-> m_vendor = Vendor_Sharp; |
725 | 725 | ||
726 | QFile f ( "/proc/filesystems" ); | 726 | QFile f ( "/proc/filesystems" ); |
727 | 727 | ||
728 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { | 728 | if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { |
729 | d-> m_systemstr = "OpenZaurus"; | 729 | d-> m_systemstr = "OpenZaurus"; |
730 | d-> m_system = System_OpenZaurus; | 730 | d-> m_system = System_OpenZaurus; |
731 | 731 | ||
732 | f. close ( ); | 732 | f. close ( ); |
733 | 733 | ||
734 | f. setName ( "/etc/oz_version" ); | 734 | f. setName ( "/etc/oz_version" ); |
735 | if ( f. open ( IO_ReadOnly )) { | 735 | if ( f. open ( IO_ReadOnly )) { |
736 | QTextStream ts ( &f ); | 736 | QTextStream ts ( &f ); |
737 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | 737 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); |
738 | f. close ( ); | 738 | f. close ( ); |
739 | } | 739 | } |
740 | } | 740 | } |
741 | else { | 741 | else { |
742 | d-> m_systemstr = "Zaurus"; | 742 | d-> m_systemstr = "Zaurus"; |
743 | d-> m_system = System_Zaurus; | 743 | d-> m_system = System_Zaurus; |
744 | } | 744 | } |
745 | 745 | ||
746 | 746 | ||
747 | m_leds [0] = Led_Off; | 747 | m_leds [0] = Led_Off; |
748 | } | 748 | } |
749 | 749 | ||
750 | #include <unistd.h> | 750 | #include <unistd.h> |
751 | #include <fcntl.h> | 751 | #include <fcntl.h> |
@@ -901,58 +901,58 @@ bool Zaurus::setSoftSuspend ( bool soft ) | |||
901 | int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources | 901 | int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources |
902 | 902 | ||
903 | if ( sources >= 0 ) { | 903 | if ( sources >= 0 ) { |
904 | if ( soft ) | 904 | if ( soft ) |
905 | sources &= ~APM_EVT_POWER_BUTTON; | 905 | sources &= ~APM_EVT_POWER_BUTTON; |
906 | else | 906 | else |
907 | sources |= APM_EVT_POWER_BUTTON; | 907 | sources |= APM_EVT_POWER_BUTTON; |
908 | 908 | ||
909 | if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources | 909 | if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources |
910 | res = true; | 910 | res = true; |
911 | else | 911 | else |
912 | perror ( "APM_IOCGEVTSRC" ); | 912 | perror ( "APM_IOCGEVTSRC" ); |
913 | } | 913 | } |
914 | else | 914 | else |
915 | perror ( "APM_IOCGEVTSRC" ); | 915 | perror ( "APM_IOCGEVTSRC" ); |
916 | 916 | ||
917 | ::close ( fd ); | 917 | ::close ( fd ); |
918 | } | 918 | } |
919 | else | 919 | else |
920 | perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); | 920 | perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); |
921 | 921 | ||
922 | return res; | 922 | return res; |
923 | } | 923 | } |
924 | 924 | ||
925 | 925 | ||
926 | bool Zaurus::setDisplayBrightness ( int bright ) | 926 | bool Zaurus::setDisplayBrightness ( int bright ) |
927 | { | 927 | { |
928 | bool res = false; | 928 | bool res = false; |
929 | int fd; | 929 | int fd; |
930 | 930 | ||
931 | if ( bright > 255 ) | 931 | if ( bright > 255 ) |
932 | bright = 255; | 932 | bright = 255; |
933 | if ( bright < 0 ) | 933 | if ( bright < 0 ) |
934 | bright = 0; | 934 | bright = 0; |
935 | 935 | ||
936 | if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { | 936 | if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { |
937 | int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus | 937 | int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus |
938 | if ( bright && !bl ) | 938 | if ( bright && !bl ) |
939 | bl = 1; | 939 | bl = 1; |
940 | res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); | 940 | res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); |
941 | ::close ( fd ); | 941 | ::close ( fd ); |
942 | } | 942 | } |
943 | return res; | 943 | return res; |
944 | } | 944 | } |
945 | 945 | ||
946 | 946 | ||
947 | int Zaurus::displayBrightnessResolution ( ) const | 947 | int Zaurus::displayBrightnessResolution ( ) const |
948 | { | 948 | { |
949 | return 4; | 949 | return 5; |
950 | } | 950 | } |
951 | 951 | ||
952 | //QValueList <int> Zaurus::keyList ( ) const | 952 | //QValueList <int> Zaurus::keyList ( ) const |
953 | //{ | 953 | //{ |
954 | //QValueList <int> vl; | 954 | //QValueList <int> vl; |
955 | //vl << HardKey_Datebook << HardKey_Contacts << HardKey_Mail << HardKey_Menu << HardKey_Home << HardKey_Suspend << HardKey_Backlight; | 955 | //vl << HardKey_Datebook << HardKey_Contacts << HardKey_Mail << HardKey_Menu << HardKey_Home << HardKey_Suspend << HardKey_Backlight; |
956 | //return vl; | 956 | //return vl; |
957 | //} | 957 | //} |
958 | 958 | ||