summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
Unidiff
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp61
1 files changed, 58 insertions, 3 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index f808960..4b5a54e 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -43,64 +43,65 @@
43#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 43#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
44#endif 44#endif
45 45
46// _IO and friends are only defined in kernel headers ... 46// _IO and friends are only defined in kernel headers ...
47 47
48#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 48#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
49 49
50#define OD_IO(type,number) OD_IOC(0,type,number,0) 50#define OD_IO(type,number) OD_IOC(0,type,number,0)
51#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 51#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
52#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 52#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
53#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 53#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
54 54
55using namespace Opie; 55using namespace Opie;
56 56
57class ODeviceData { 57class ODeviceData {
58public: 58public:
59 QString m_vendorstr; 59 QString m_vendorstr;
60 OVendor m_vendor; 60 OVendor m_vendor;
61 61
62 QString m_modelstr; 62 QString m_modelstr;
63 OModel m_model; 63 OModel m_model;
64 64
65 QString m_systemstr; 65 QString m_systemstr;
66 OSystem m_system; 66 OSystem m_system;
67 67
68 QString m_sysverstr; 68 QString m_sysverstr;
69 69
70 Transformation m_rotation; 70 Transformation m_rotation;
71 ODirection m_direction; 71 ODirection m_direction;
72 72
73 QValueList <ODeviceButton> *m_buttons; 73 QValueList <ODeviceButton> *m_buttons;
74 uint m_holdtime; 74 uint m_holdtime;
75 QStrList *m_cpu_frequencies;
75}; 76};
76 77
77 78
78class iPAQ : public ODevice, public QWSServer::KeyboardFilter { 79class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
79protected: 80protected:
80 virtual void init ( ); 81 virtual void init ( );
81 virtual void initButtons ( ); 82 virtual void initButtons ( );
82 83
83public: 84public:
84 virtual bool setSoftSuspend ( bool soft ); 85 virtual bool setSoftSuspend ( bool soft );
85 86
86 virtual bool setDisplayBrightness ( int b ); 87 virtual bool setDisplayBrightness ( int b );
87 virtual int displayBrightnessResolution ( ) const; 88 virtual int displayBrightnessResolution ( ) const;
88 89
89 virtual void alarmSound ( ); 90 virtual void alarmSound ( );
90 91
91 virtual QValueList <OLed> ledList ( ) const; 92 virtual QValueList <OLed> ledList ( ) const;
92 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 93 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
93 virtual OLedState ledState ( OLed led ) const; 94 virtual OLedState ledState ( OLed led ) const;
94 virtual bool setLedState ( OLed led, OLedState st ); 95 virtual bool setLedState ( OLed led, OLedState st );
95 96
96 virtual bool hasLightSensor ( ) const; 97 virtual bool hasLightSensor ( ) const;
97 virtual int readLightSensor ( ); 98 virtual int readLightSensor ( );
98 virtual int lightSensorResolution ( ) const; 99 virtual int lightSensorResolution ( ) const;
99 100
100protected: 101protected:
101 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 102 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
102 virtual void timerEvent ( QTimerEvent *te ); 103 virtual void timerEvent ( QTimerEvent *te );
103 104
104 int m_power_timer; 105 int m_power_timer;
105 106
106 OLedState m_leds [2]; 107 OLedState m_leds [2];
@@ -394,64 +395,65 @@ ODevice *ODevice::inst ( )
394 else 395 else
395 dev = new ODevice ( ); 396 dev = new ODevice ( );
396 397
397 dev-> init ( ); 398 dev-> init ( );
398 } 399 }
399 return dev; 400 return dev;
400} 401}
401 402
402 403
403/************************************************** 404/**************************************************
404 * 405 *
405 * common 406 * common
406 * 407 *
407 **************************************************/ 408 **************************************************/
408 409
409 410
410ODevice::ODevice ( ) 411ODevice::ODevice ( )
411{ 412{
412 d = new ODeviceData; 413 d = new ODeviceData;
413 414
414 d-> m_modelstr = "Unknown"; 415 d-> m_modelstr = "Unknown";
415 d-> m_model = Model_Unknown; 416 d-> m_model = Model_Unknown;
416 d-> m_vendorstr = "Unknown"; 417 d-> m_vendorstr = "Unknown";
417 d-> m_vendor = Vendor_Unknown; 418 d-> m_vendor = Vendor_Unknown;
418 d-> m_systemstr = "Unknown"; 419 d-> m_systemstr = "Unknown";
419 d-> m_system = System_Unknown; 420 d-> m_system = System_Unknown;
420 d-> m_sysverstr = "0.0"; 421 d-> m_sysverstr = "0.0";
421 d-> m_rotation = Rot0; 422 d-> m_rotation = Rot0;
422 d-> m_direction = CW; 423 d-> m_direction = CW;
423 424
424 d-> m_holdtime = 1000; // 1000ms 425 d-> m_holdtime = 1000; // 1000ms
425 d-> m_buttons = 0; 426 d-> m_buttons = 0;
427 d-> m_cpu_frequencies = new QStrList;
426} 428}
427 429
428void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 430void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
429{ 431{
430 if ( msg == "deviceButtonMappingChanged()" ) { 432 if ( msg == "deviceButtonMappingChanged()" ) {
431 reloadButtonMapping ( ); 433 reloadButtonMapping ( );
432 } 434 }
433} 435}
434 436
435void ODevice::init ( ) 437void ODevice::init ( )
436{ 438{
437} 439}
438 440
439/** 441/**
440 * This method initialises the button mapping 442 * This method initialises the button mapping
441 */ 443 */
442void ODevice::initButtons ( ) 444void ODevice::initButtons ( )
443{ 445{
444 if ( d-> m_buttons ) 446 if ( d-> m_buttons )
445 return; 447 return;
446 448
447 // Simulation uses iPAQ 3660 device buttons 449 // Simulation uses iPAQ 3660 device buttons
448 450
449 qDebug ( "init Buttons" ); 451 qDebug ( "init Buttons" );
450 d-> m_buttons = new QValueList <ODeviceButton>; 452 d-> m_buttons = new QValueList <ODeviceButton>;
451 453
452 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 454 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
453 i_button *ib = ipaq_buttons + i; 455 i_button *ib = ipaq_buttons + i;
454 ODeviceButton b; 456 ODeviceButton b;
455 457
456 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 458 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
457 b. setKeycode ( ib-> code ); 459 b. setKeycode ( ib-> code );
@@ -744,64 +746,104 @@ OLedState ODevice::ledState ( OLed /*which*/ ) const
744bool ODevice::setLedState ( OLed which, OLedState st ) 746bool ODevice::setLedState ( OLed which, OLedState st )
745{ 747{
746 Q_UNUSED( which ) 748 Q_UNUSED( which )
747 Q_UNUSED( st ) 749 Q_UNUSED( st )
748 return false; 750 return false;
749} 751}
750 752
751/** 753/**
752 * @return if the device has a light sensor 754 * @return if the device has a light sensor
753 */ 755 */
754bool ODevice::hasLightSensor ( ) const 756bool ODevice::hasLightSensor ( ) const
755{ 757{
756 return false; 758 return false;
757} 759}
758 760
759/** 761/**
760 * @return a value from the light senso 762 * @return a value from the light senso
761 */ 763 */
762int ODevice::readLightSensor ( ) 764int ODevice::readLightSensor ( )
763{ 765{
764 return -1; 766 return -1;
765} 767}
766 768
767/** 769/**
768 * @return the light sensor resolution whatever that is ;) 770 * @return the light sensor resolution whatever that is ;)
769 */ 771 */
770int ODevice::lightSensorResolution ( ) const 772int ODevice::lightSensorResolution ( ) const
771{ 773{
772 return 0; 774 return 0;
773} 775}
774 776
775/** 777/**
778 * @return a list with valid CPU frequency
779 */
780QStrList &ODevice::cpuFrequencies ( ) const
781{
782qWarning("ODevice::cpuFrequencies: m_cpu_frequencies is %d", (int) d->m_cpu_frequencies);
783 return *d->m_cpu_frequencies;
784}
785
786
787/**
788 * Set desired cpu frequency
789 *
790 * @param index index into d->m_cpu_frequencies of the frequency to be set
791 */
792bool ODevice::setCpuFrequency(uint index)
793{
794 if (index >= d->m_cpu_frequencies->count())
795 return false;
796
797 char *freq = d->m_cpu_frequencies->at(index);
798 qWarning("set freq to %s", freq);
799
800 //TODO: do the change in /proc/sys/cpu/0/speed
801
802 return false;
803}
804
805/**
806 * Returns current frequency index out of d->m_cpu_frequencies
807 */
808uint ODevice::cpuFrequency() const
809{
810 // TODO: get freq from /proc/sys/cpu/0/speed and return index
811
812 return 0;
813}
814
815
816
817/**
776 * @return a list of hardware buttons 818 * @return a list of hardware buttons
777 */ 819 */
778const QValueList <ODeviceButton> &ODevice::buttons ( ) 820const QValueList <ODeviceButton> &ODevice::buttons ( )
779{ 821{
780 initButtons ( ); 822 initButtons ( );
781 823
782 return *d-> m_buttons; 824 return *d-> m_buttons;
783} 825}
784 826
785/** 827/**
786 * @return The amount of time that would count as a hold 828 * @return The amount of time that would count as a hold
787 */ 829 */
788uint ODevice::buttonHoldTime ( ) const 830uint ODevice::buttonHoldTime ( ) const
789{ 831{
790 return d-> m_holdtime; 832 return d-> m_holdtime;
791} 833}
792 834
793/** 835/**
794 * This method return a ODeviceButton for a key code 836 * This method return a ODeviceButton for a key code
795 * or 0 if no special hardware button is available for the device 837 * or 0 if no special hardware button is available for the device
796 * 838 *
797 * @return The devicebutton or 0l 839 * @return The devicebutton or 0l
798 * @see ODeviceButton 840 * @see ODeviceButton
799 */ 841 */
800const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) 842const ODeviceButton *ODevice::buttonForKeycode ( ushort code )
801{ 843{
802 initButtons ( ); 844 initButtons ( );
803 845
804 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { 846 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) {
805 if ( (*it). keycode ( ) == code ) 847 if ( (*it). keycode ( ) == code )
806 return &(*it); 848 return &(*it);
807 } 849 }
@@ -1921,172 +1963,185 @@ int SIMpad::displayBrightnessResolution ( ) const
1921 * 1963 *
1922 * Ramses 1964 * Ramses
1923 * 1965 *
1924 **************************************************/ 1966 **************************************************/
1925 1967
1926void Ramses::init() 1968void Ramses::init()
1927{ 1969{
1928 d->m_vendorstr = "M und N"; 1970 d->m_vendorstr = "M und N";
1929 d->m_vendor = Vendor_MundN; 1971 d->m_vendor = Vendor_MundN;
1930 1972
1931 QFile f("/proc/sys/board/ramses"); 1973 QFile f("/proc/sys/board/ramses");
1932 1974
1933 d->m_modelstr = "Ramses"; 1975 d->m_modelstr = "Ramses";
1934 d->m_model = Model_Ramses_MNCI; 1976 d->m_model = Model_Ramses_MNCI;
1935 1977
1936 d->m_rotation = Rot0; 1978 d->m_rotation = Rot0;
1937 d->m_holdtime = 1000; 1979 d->m_holdtime = 1000;
1938 1980
1939 f.setName("/etc/oz_version"); 1981 f.setName("/etc/oz_version");
1940 1982
1941 if (f.open(IO_ReadOnly)) { 1983 if (f.open(IO_ReadOnly)) {
1942 d->m_systemstr = "OpenEmbedded/Ramses"; 1984 d->m_systemstr = "OpenEmbedded/Ramses";
1943 d->m_system = System_OpenZaurus; 1985 d->m_system = System_OpenZaurus;
1944 1986
1945 QTextStream ts(&f); 1987 QTextStream ts(&f);
1946 ts.setDevice(&f); 1988 ts.setDevice(&f);
1947 d->m_sysverstr = ts.readLine(); 1989 d->m_sysverstr = ts.readLine();
1948 f.close(); 1990 f.close();
1949 } 1991 }
1950 1992
1951 m_power_timer = 0; 1993 m_power_timer = 0;
1952 1994
1995qWarning("adding freq");
1996 d->m_cpu_frequencies->append("100");
1997 d->m_cpu_frequencies->append("200");
1998 d->m_cpu_frequencies->append("300");
1999 d->m_cpu_frequencies->append("400");
1953} 2000}
1954 2001
1955bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat) 2002bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat)
1956{ 2003{
1957 Q_UNUSED( keycode ); 2004 Q_UNUSED( keycode );
1958 Q_UNUSED( modifiers ); 2005 Q_UNUSED( modifiers );
1959 Q_UNUSED( isPress ); 2006 Q_UNUSED( isPress );
1960 Q_UNUSED( autoRepeat ); 2007 Q_UNUSED( autoRepeat );
1961 return false; 2008 return false;
1962} 2009}
1963 2010
1964void Ramses::timerEvent(QTimerEvent *) 2011void Ramses::timerEvent(QTimerEvent *)
1965{ 2012{
1966 killTimer(m_power_timer); 2013 killTimer(m_power_timer);
1967 m_power_timer = 0; 2014 m_power_timer = 0;
1968 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false); 2015 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false);
1969 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false); 2016 QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false);
1970} 2017}
1971 2018
1972 2019
1973bool Ramses::setSoftSuspend(bool soft) 2020bool Ramses::setSoftSuspend(bool soft)
1974{ 2021{
1975 qDebug("Ramses::setSoftSuspend(%d)", soft); 2022 qDebug("Ramses::setSoftSuspend(%d)", soft);
1976#if 0 2023#if 0
1977 bool res = false; 2024 bool res = false;
1978 int fd; 2025 int fd;
1979 2026
1980 if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) || 2027 if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) ||
1981 ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) { 2028 ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) {
1982 2029
1983 int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources 2030 int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources
1984 2031
1985 if (sources >= 0) { 2032 if (sources >= 0) {
1986 if (soft) 2033 if (soft)
1987 sources &= ~APM_EVT_POWER_BUTTON; 2034 sources &= ~APM_EVT_POWER_BUTTON;
1988 else 2035 else
1989 sources |= APM_EVT_POWER_BUTTON; 2036 sources |= APM_EVT_POWER_BUTTON;
1990 2037
1991 if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources 2038 if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources
1992 res = true; 2039 res = true;
1993 else 2040 else
1994 perror("APM_IOCGEVTSRC"); 2041 perror("APM_IOCGEVTSRC");
1995 } 2042 }
1996 else 2043 else
1997 perror("APM_IOCGEVTSRC"); 2044 perror("APM_IOCGEVTSRC");
1998 2045
1999 ::close(fd); 2046 ::close(fd);
2000 } 2047 }
2001 else 2048 else
2002 perror("/dev/apm_bios or /dev/misc/apm_bios"); 2049 perror("/dev/apm_bios or /dev/misc/apm_bios");
2003 2050
2004 return res; 2051 return res;
2005#else 2052#else
2006 return true; 2053 return true;
2007#endif 2054#endif
2008} 2055}
2009 2056
2010bool Ramses::suspend ( ) 2057bool Ramses::suspend ( )
2011{ 2058{
2012 qDebug("Ramses::suspend"); 2059 qDebug("Ramses::suspend");
2060 return false;
2013} 2061}
2014 2062
2015/** 2063/**
2016 * This sets the display on or off 2064 * This sets the display on or off
2017 */ 2065 */
2018bool Ramses::setDisplayStatus(bool on) 2066bool Ramses::setDisplayStatus(bool on)
2019{ 2067{
2020 qDebug("Ramses::setDisplayStatus(%d)", on); 2068 qDebug("Ramses::setDisplayStatus(%d)", on);
2021#if 0 2069#if 0
2022 bool res = false; 2070 bool res = false;
2023 int fd; 2071 int fd;
2024 2072
2025 if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) { 2073 if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) {
2026 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); 2074 res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0);
2027 ::close(fd); 2075 ::close(fd);
2028 } 2076 }
2029 return res; 2077 return res;
2030#else 2078#else
2031 return true; 2079 return true;
2032#endif 2080#endif
2033} 2081}
2034 2082
2035 2083
2036/* 2084/*
2037 * We get something between 0..255 into us 2085 * We get something between 0..255 into us
2038*/ 2086*/
2039bool Ramses::setDisplayBrightness(int bright) 2087bool Ramses::setDisplayBrightness(int bright)
2040{ 2088{
2041 qDebug("Ramses::setDisplayBrightness(%d)", bright); 2089 qDebug("Ramses::setDisplayBrightness(%d)", bright);
2042 bool res = false; 2090 bool res = false;
2043 int fd; 2091 int fd;
2044 2092
2045 // pwm1 brighness: 20 steps 500..0 (dunkel->hell) 2093 // pwm1 brighness: 20 steps 500..0 (dunkel->hell)
2046 2094
2047 if (bright > 255 ) 2095 if (bright > 255 )
2048 bright = 255; 2096 bright = 255;
2049 if (bright < 0) 2097 if (bright < 0)
2050 bright = 0; 2098 bright = 0;
2051 bright = 500-(bright * 500 / 255);
2052 2099
2100 // Turn backlight completely off
2101 if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) {
2102 char writeCommand[10];
2103 const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0);
2104 res = (::write(fd, writeCommand, count) != -1);
2105 ::close(fd);
2106 }
2107
2108 // scale backlight brightness to hardware
2109 bright = 500-(bright * 500 / 255);
2053 if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { 2110 if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) {
2054 qDebug(" %d -> pwm1", bright); 2111 qDebug(" %d -> pwm1", bright);
2055 char writeCommand[100]; 2112 char writeCommand[100];
2056 const int count = sprintf(writeCommand, "%d\n", bright); 2113 const int count = sprintf(writeCommand, "%d\n", bright);
2057 res = (::write(fd, writeCommand, count) != -1); 2114 res = (::write(fd, writeCommand, count) != -1);
2058 ::close(fd); 2115 ::close(fd);
2059 } else {
2060 qWarning("no write");
2061 } 2116 }
2062 return res; 2117 return res;
2063} 2118}
2064 2119
2065 2120
2066int Ramses::displayBrightnessResolution() const 2121int Ramses::displayBrightnessResolution() const
2067{ 2122{
2068 return 32; 2123 return 32;
2069} 2124}
2070 2125
2071bool Ramses::setDisplayContrast(int contr) 2126bool Ramses::setDisplayContrast(int contr)
2072{ 2127{
2073 qDebug("Ramses::setDisplayContrast(%d)", contr); 2128 qDebug("Ramses::setDisplayContrast(%d)", contr);
2074 bool res = false; 2129 bool res = false;
2075 int fd; 2130 int fd;
2076 2131
2077 // pwm0 contrast: 20 steps 79..90 (dunkel->hell) 2132 // pwm0 contrast: 20 steps 79..90 (dunkel->hell)
2078 2133
2079 if (contr > 255 ) 2134 if (contr > 255 )
2080 contr = 255; 2135 contr = 255;
2081 if (contr < 0) 2136 if (contr < 0)
2082 contr = 0; 2137 contr = 0;
2083 contr = 90 - (contr * 20 / 255); 2138 contr = 90 - (contr * 20 / 255);
2084 2139
2085 if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) { 2140 if ((fd = ::open("/proc/sys/board/pwm0", O_WRONLY)) >= 0) {
2086 qDebug(" %d -> pwm0", contr); 2141 qDebug(" %d -> pwm0", contr);
2087 char writeCommand[100]; 2142 char writeCommand[100];
2088 const int count = sprintf(writeCommand, "%d\n", contr); 2143 const int count = sprintf(writeCommand, "%d\n", contr);
2089 res = (::write(fd, writeCommand, count) != -1); 2144 res = (::write(fd, writeCommand, count) != -1);
2090 res = true; 2145 res = true;
2091 ::close(fd); 2146 ::close(fd);
2092 } else { 2147 } else {