author | mickeyl <mickeyl> | 2003-12-29 16:51:07 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-12-29 16:51:07 (UTC) |
commit | 8224dfc07a698d4c40cb240d315dc81b67512015 (patch) (unidiff) | |
tree | 0cdbb05aab54948421c873ccd25881caf1e474c5 /libopie/odevice.cpp | |
parent | dae677b6e29e2a0efb7128bcc4b0d87bf2b535dd (diff) | |
download | opie-8224dfc07a698d4c40cb240d315dc81b67512015.zip opie-8224dfc07a698d4c40cb240d315dc81b67512015.tar.gz opie-8224dfc07a698d4c40cb240d315dc81b67512015.tar.bz2 |
- add fine granular backlight support for devices with the corgi backlight interface
- add hinge sensor framework for devices with hinge sensors
-rw-r--r-- | libopie/odevice.cpp | 136 |
1 files changed, 101 insertions, 35 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index e24e043..bc09e92 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -131,27 +131,30 @@ public: | |||
131 | virtual bool setDisplayBrightness ( int b ); | 131 | virtual bool setDisplayBrightness ( int b ); |
132 | virtual int displayBrightnessResolution ( ) const; | 132 | virtual int displayBrightnessResolution ( ) const; |
133 | 133 | ||
134 | virtual void alarmSound ( ); | 134 | virtual void alarmSound ( ); |
135 | virtual void keySound ( ); | 135 | virtual void keySound ( ); |
136 | virtual void touchSound ( ); | 136 | virtual void touchSound ( ); |
137 | 137 | ||
138 | virtual QValueList <OLed> ledList ( ) const; | 138 | virtual QValueList <OLed> ledList ( ) const; |
139 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 139 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
140 | virtual OLedState ledState ( OLed led ) const; | 140 | virtual OLedState ledState ( OLed led ) const; |
141 | virtual bool setLedState ( OLed led, OLedState st ); | 141 | virtual bool setLedState ( OLed led, OLedState st ); |
142 | 142 | ||
143 | virtual bool hasHingeSensor() const; | ||
144 | virtual OHingeStatus readHingeSensor(); | ||
145 | |||
143 | static bool isZaurus(); | 146 | static bool isZaurus(); |
144 | 147 | ||
145 | // Does this break BC? | 148 | // Does this break BC? |
146 | virtual bool suspend ( ); | 149 | virtual bool suspend ( ); |
147 | virtual Transformation rotation ( ) const; | 150 | virtual Transformation rotation ( ) const; |
148 | virtual ODirection direction ( ) const; | 151 | virtual ODirection direction ( ) const; |
149 | 152 | ||
150 | protected: | 153 | protected: |
151 | virtual void buzzer ( int snd ); | 154 | virtual void buzzer ( int snd ); |
152 | 155 | ||
153 | OLedState m_leds [1]; | 156 | OLedState m_leds [1]; |
154 | bool m_embedix; | 157 | bool m_embedix; |
155 | }; | 158 | }; |
156 | 159 | ||
157 | class SIMpad : public ODevice, public QWSServer::KeyboardFilter { | 160 | class SIMpad : public ODevice, public QWSServer::KeyboardFilter { |
@@ -524,25 +527,25 @@ void ODevice::initButtons ( ) | |||
524 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | 527 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); |
525 | d-> m_buttons-> append ( b ); | 528 | d-> m_buttons-> append ( b ); |
526 | } | 529 | } |
527 | } | 530 | } |
528 | reloadButtonMapping ( ); | 531 | reloadButtonMapping ( ); |
529 | 532 | ||
530 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 533 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
531 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | 534 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); |
532 | } | 535 | } |
533 | 536 | ||
534 | ODevice::~ODevice ( ) | 537 | ODevice::~ODevice ( ) |
535 | { | 538 | { |
536 | // we leak m_devicebuttons and m_cpu_frequency | 539 | // we leak m_devicebuttons and m_cpu_frequency |
537 | // but it's a singleton and it is not so importantant | 540 | // but it's a singleton and it is not so importantant |
538 | // -zecke | 541 | // -zecke |
539 | delete d; | 542 | delete d; |
540 | } | 543 | } |
541 | 544 | ||
542 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | 545 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
543 | { | 546 | { |
544 | return false; | 547 | return false; |
545 | } | 548 | } |
546 | 549 | ||
547 | //#include <linux/apm_bios.h> | 550 | //#include <linux/apm_bios.h> |
548 | 551 | ||
@@ -814,51 +817,67 @@ bool ODevice::setLedState ( OLed which, OLedState st ) | |||
814 | return false; | 817 | return false; |
815 | } | 818 | } |
816 | 819 | ||
817 | /** | 820 | /** |
818 | * @return if the device has a light sensor | 821 | * @return if the device has a light sensor |
819 | */ | 822 | */ |
820 | bool ODevice::hasLightSensor ( ) const | 823 | bool ODevice::hasLightSensor ( ) const |
821 | { | 824 | { |
822 | return false; | 825 | return false; |
823 | } | 826 | } |
824 | 827 | ||
825 | /** | 828 | /** |
826 | * @return a value from the light senso | 829 | * @return a value from the light sensor |
827 | */ | 830 | */ |
828 | int ODevice::readLightSensor ( ) | 831 | int ODevice::readLightSensor ( ) |
829 | { | 832 | { |
830 | return -1; | 833 | return -1; |
831 | } | 834 | } |
832 | 835 | ||
833 | /** | 836 | /** |
834 | * @return the light sensor resolution whatever that is ;) | 837 | * @return the light sensor resolution |
835 | */ | 838 | */ |
836 | int ODevice::lightSensorResolution ( ) const | 839 | int ODevice::lightSensorResolution ( ) const |
837 | { | 840 | { |
838 | return 0; | 841 | return 0; |
839 | } | 842 | } |
840 | 843 | ||
841 | /** | 844 | /** |
845 | * @return if the device has a hinge sensor | ||
846 | */ | ||
847 | bool ODevice::hasHingeSensor ( ) const | ||
848 | { | ||
849 | return false; | ||
850 | } | ||
851 | |||
852 | /** | ||
853 | * @return a value from the hinge sensor | ||
854 | */ | ||
855 | OHingeStatus ODevice::readHingeSensor ( ) | ||
856 | { | ||
857 | return CASE_UNKNOWN; | ||
858 | } | ||
859 | |||
860 | /** | ||
842 | * @return a list with CPU frequencies supported by the hardware | 861 | * @return a list with CPU frequencies supported by the hardware |
843 | */ | 862 | */ |
844 | const QStrList &ODevice::allowedCpuFrequencies ( ) const | 863 | const QStrList &ODevice::allowedCpuFrequencies ( ) const |
845 | { | 864 | { |
846 | return *d->m_cpu_frequencies; | 865 | return *d->m_cpu_frequencies; |
847 | } | 866 | } |
848 | 867 | ||
849 | 868 | ||
850 | /** | 869 | /** |
851 | * Set desired CPU frequency | 870 | * Set desired CPU frequency |
852 | * | 871 | * |
853 | * @param index index into d->m_cpu_frequencies of the frequency to be set | 872 | * @param index index into d->m_cpu_frequencies of the frequency to be set |
854 | */ | 873 | */ |
855 | bool ODevice::setCurrentCpuFrequency(uint index) | 874 | bool ODevice::setCurrentCpuFrequency(uint index) |
856 | { | 875 | { |
857 | if (index >= d->m_cpu_frequencies->count()) | 876 | if (index >= d->m_cpu_frequencies->count()) |
858 | return false; | 877 | return false; |
859 | 878 | ||
860 | char *freq = d->m_cpu_frequencies->at(index); | 879 | char *freq = d->m_cpu_frequencies->at(index); |
861 | qWarning("set freq to %s", freq); | 880 | qWarning("set freq to %s", freq); |
862 | 881 | ||
863 | int fd; | 882 | int fd; |
864 | 883 | ||
@@ -1773,25 +1792,25 @@ void Zaurus::buzzer ( int sound ) | |||
1773 | switch ( sound ){ | 1792 | switch ( sound ){ |
1774 | case SHARP_BUZ_SCHEDULE_ALARM: | 1793 | case SHARP_BUZ_SCHEDULE_ALARM: |
1775 | soundname = "alarm"; | 1794 | soundname = "alarm"; |
1776 | break; | 1795 | break; |
1777 | case SHARP_BUZ_TOUCHSOUND: | 1796 | case SHARP_BUZ_TOUCHSOUND: |
1778 | soundname = "touchsound"; | 1797 | soundname = "touchsound"; |
1779 | break; | 1798 | break; |
1780 | case SHARP_BUZ_KEYSOUND: | 1799 | case SHARP_BUZ_KEYSOUND: |
1781 | soundname = "keysound"; | 1800 | soundname = "keysound"; |
1782 | break; | 1801 | break; |
1783 | default: | 1802 | default: |
1784 | soundname = "alarm"; | 1803 | soundname = "alarm"; |
1785 | 1804 | ||
1786 | } | 1805 | } |
1787 | } | 1806 | } |
1788 | 1807 | ||
1789 | // If a soundname is defined, we expect that this device has | 1808 | // If a soundname is defined, we expect that this device has |
1790 | // sound capabilities.. Otherwise we expect to have the buzzer | 1809 | // sound capabilities.. Otherwise we expect to have the buzzer |
1791 | // device.. | 1810 | // device.. |
1792 | if ( !soundname.isEmpty() ){ | 1811 | if ( !soundname.isEmpty() ){ |
1793 | int fd; | 1812 | int fd; |
1794 | int vol; | 1813 | int vol; |
1795 | bool vol_reset = false; | 1814 | bool vol_reset = false; |
1796 | 1815 | ||
1797 | Sound snd ( soundname ); | 1816 | Sound snd ( soundname ); |
@@ -1936,51 +1955,67 @@ bool Zaurus::setSoftSuspend ( bool soft ) | |||
1936 | 1955 | ||
1937 | ::close ( fd ); | 1956 | ::close ( fd ); |
1938 | } | 1957 | } |
1939 | else | 1958 | else |
1940 | perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); | 1959 | perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); |
1941 | 1960 | ||
1942 | return res; | 1961 | return res; |
1943 | } | 1962 | } |
1944 | 1963 | ||
1945 | 1964 | ||
1946 | bool Zaurus::setDisplayBrightness ( int bright ) | 1965 | bool Zaurus::setDisplayBrightness ( int bright ) |
1947 | { | 1966 | { |
1948 | // FIXME The C7x0 have a proc-interface (/proc/drivers/corgi-bl) which | 1967 | bool res = false; |
1949 | // is nice to use. Currently it exposes 16+1 levels. Implement this! | 1968 | int fd; |
1950 | // (or wait for kergoth unifying the interfaces in the OpenZaurus kernel.) | 1969 | |
1951 | bool res = false; | 1970 | if ( bright > 255 ) bright = 255; |
1952 | int fd; | 1971 | if ( bright < 0 ) bright = 0; |
1953 | 1972 | ||
1954 | if ( bright > 255 ) | 1973 | if ( m_embedix ) |
1955 | bright = 255; | 1974 | { |
1956 | if ( bright < 0 ) | 1975 | if ( d->m_model == Model_Zaurus_SLC7x0 ) |
1957 | bright = 0; | 1976 | { |
1958 | 1977 | // special treatment for devices with the corgi backlight interface | |
1959 | if (m_embedix) { | 1978 | if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 ) |
1960 | if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { | 1979 | { |
1961 | int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus | 1980 | if ( bright > 0x11 ) bright = 0x11; |
1962 | if ( bright && !bl ) | 1981 | char writeCommand[100]; |
1963 | bl = 1; | 1982 | const int count = sprintf( writeCommand, "0x%x\n", bright ); |
1964 | res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); | 1983 | res = ( ::write ( fd, writeCommand, count ) != -1 ); |
1965 | ::close ( fd ); | 1984 | ::close ( fd ); |
1966 | } | 1985 | } |
1967 | } else { | 1986 | return res; |
1968 | #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */ | 1987 | } |
1969 | if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) { | 1988 | else |
1970 | res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 ); | 1989 | { |
1971 | ::close ( fd ); | 1990 | // standard treatment for devices with the dumb embedix frontlight interface |
1972 | } | 1991 | if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { |
1973 | } | 1992 | int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus |
1974 | return res; | 1993 | if ( bright && !bl ) |
1994 | bl = 1; | ||
1995 | res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); | ||
1996 | ::close ( fd ); | ||
1997 | } | ||
1998 | } | ||
1999 | } | ||
2000 | else | ||
2001 | { | ||
2002 | // special treatment for the OpenZaurus unified interface | ||
2003 | #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */ | ||
2004 | if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) { | ||
2005 | res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 ); | ||
2006 | ::close ( fd ); | ||
2007 | } | ||
2008 | } | ||
2009 | return res; | ||
1975 | } | 2010 | } |
1976 | 2011 | ||
1977 | bool Zaurus::suspend ( ) | 2012 | bool Zaurus::suspend ( ) |
1978 | { | 2013 | { |
1979 | qDebug("ODevice::suspend"); | 2014 | qDebug("ODevice::suspend"); |
1980 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | 2015 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend |
1981 | return false; | 2016 | return false; |
1982 | 2017 | ||
1983 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | 2018 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices |
1984 | return false; | 2019 | return false; |
1985 | 2020 | ||
1986 | bool res = false; | 2021 | bool res = false; |
@@ -2064,29 +2099,60 @@ ODirection Zaurus::direction ( ) const | |||
2064 | case Model_Zaurus_SL5000: | 2099 | case Model_Zaurus_SL5000: |
2065 | default: | 2100 | default: |
2066 | dir = d-> m_direction; | 2101 | dir = d-> m_direction; |
2067 | break; | 2102 | break; |
2068 | } | 2103 | } |
2069 | return dir; | 2104 | return dir; |
2070 | 2105 | ||
2071 | } | 2106 | } |
2072 | 2107 | ||
2073 | int Zaurus::displayBrightnessResolution ( ) const | 2108 | int Zaurus::displayBrightnessResolution ( ) const |
2074 | { | 2109 | { |
2075 | if (m_embedix) | 2110 | if (m_embedix) |
2076 | return 5; | 2111 | return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5; |
2077 | else | 2112 | else |
2078 | return 256; | 2113 | return 256; |
2079 | } | 2114 | } |
2080 | 2115 | ||
2116 | bool Zaurus::hasHingeSensor() const | ||
2117 | { | ||
2118 | return d->m_model == Model_Zaurus_SLC7x0; | ||
2119 | } | ||
2120 | |||
2121 | OHingeStatus Zaurus::readHingeSensor() | ||
2122 | { | ||
2123 | int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); | ||
2124 | if (handle == -1) | ||
2125 | { | ||
2126 | qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror | ||
2127 | return CASE_UNKNOWN; | ||
2128 | } | ||
2129 | else | ||
2130 | { | ||
2131 | int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); | ||
2132 | ::close (handle); | ||
2133 | if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) | ||
2134 | { | ||
2135 | qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); | ||
2136 | return static_cast<OHingeStatus>( retval ); | ||
2137 | } | ||
2138 | else | ||
2139 | { | ||
2140 | qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); | ||
2141 | return CASE_UNKNOWN; | ||
2142 | } | ||
2143 | } | ||
2144 | } | ||
2145 | |||
2146 | |||
2081 | /************************************************** | 2147 | /************************************************** |
2082 | * | 2148 | * |
2083 | * SIMpad | 2149 | * SIMpad |
2084 | * | 2150 | * |
2085 | **************************************************/ | 2151 | **************************************************/ |
2086 | 2152 | ||
2087 | void SIMpad::init ( ) | 2153 | void SIMpad::init ( ) |
2088 | { | 2154 | { |
2089 | d-> m_vendorstr = "SIEMENS"; | 2155 | d-> m_vendorstr = "SIEMENS"; |
2090 | d-> m_vendor = Vendor_SIEMENS; | 2156 | d-> m_vendor = Vendor_SIEMENS; |
2091 | 2157 | ||
2092 | QFile f ( "/proc/hal/model" ); | 2158 | QFile f ( "/proc/hal/model" ); |