]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/libopie/libopie2/ipaq-2.6-sys-class-backlight-support.patch
libopie2: use common code to handle backlight settings on all iPAQs running Linux...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / libopie / libopie2 / ipaq-2.6-sys-class-backlight-support.patch
1 --- libopie2/opiecore/device/odevice_ipaq.cpp.orig      2006-07-22 21:32:03.000000000 +0200
2 +++ libopie2/opiecore/device/odevice_ipaq.cpp   2006-07-22 22:49:57.000000000 +0200
3 @@ -31,6 +31,7 @@
4  
5  /* QT */
6  #include <qapplication.h>
7 +#include <qdir.h>
8  #include <qfile.h>
9  #include <qtextstream.h>
10  #include <qwindowsystem_qws.h>
11 @@ -375,26 +376,19 @@
12      if ( bright < 0 )
13          bright = 0;
14  
15 -    QString cmdline;
16 -
17 -    switch ( model()) {
18 -    case Model_iPAQ_H191x:
19 -        if ( !bright )
20 -            cmdline = QString::fromLatin1( "echo 4 > /sys/class/backlight/pxafb/power");
21 -        else
22 -            cmdline = QString::fromLatin1( "echo 0 > /sys/class/backlight/pxafb/power; echo %1 > /sys/class/backlight/pxafb/brightness" ).arg( bright );
23 -        // No Global::shellQuote as we gurantee it to be sane
24 -        res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
25 -        break; 
26 -       
27 -    case Model_iPAQ_HX4700:
28 -            cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright );
29 -        // No Global::shellQuote as we gurantee it to be sane
30 -        res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
31 -        break; 
32 -       
33 -
34 -    default:
35 +    QDir sysClass( "/sys/class/backlight/" );
36 +    sysClass.setFilter(QDir::Dirs);
37 +    if ( sysClass.exists() && sysClass.count() > 2 ) {
38 +       QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" );
39 +        int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK );
40 +        if ( fd ) {
41 +            char buf[100];
42 +            int val = bright * displayBrightnessResolution() / 255;
43 +            int len = ::snprintf( &buf[0], sizeof buf, "%d", val );
44 +            res = ( ::write( fd, &buf[0], len ) == 0 );
45 +            ::close( fd );
46 +        }
47 +    } else {
48          if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
49              FLITE_IN bl;
50              bl. mode = 1;
51 @@ -409,6 +403,22 @@
52  
53  int iPAQ::displayBrightnessResolution() const
54  {
55 +    int res = 16;
56 +
57 +    QDir sysClass( "/sys/class/backlight/" );
58 +    sysClass.setFilter(QDir::Dirs);
59 +    if ( sysClass.exists() && sysClass.count() > 2 ) {
60 +       QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" );
61 +        int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK );
62 +        if ( fd ) {
63 +            char buf[100];
64 +            if ( ::read( fd, &buf[0], sizeof buf ) )
65 +                ::sscanf( &buf[0], "%d", &res );
66 +            ::close( fd );
67 +        }
68 +       return res;
69 +    } 
70 +
71      switch ( model()) {
72          case Model_iPAQ_H31xx:
73          case Model_iPAQ_H36xx:
74 @@ -434,22 +444,35 @@
75  {
76      bool res = false;
77  
78 -    QString cmdline;
79 -
80 -    if ( model() == Model_iPAQ_H191x ) {
81 -        cmdline = QString::fromLatin1( "echo %1 > /sys/class/lcd/pxafb/power; echo %2 > /sys/class/backlight/pxafb/power").arg( on ? "0" : "4" ).arg( on ? "0" : "4" );
82 +    QDir sysClass( "/sys/class/lcd/" );
83 +    sysClass.setFilter(QDir::Dirs);
84 +    if ( sysClass.exists() && sysClass.count() > 2 ) {
85 +       QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" );
86 +        int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK );
87 +        if ( fd ) {
88 +            char buf[10];
89 +            buf[0] = on ? 0 : 4;
90 +            buf[1] = '\0';
91 +            res = ( ::write( fd, &buf[0], 2 ) == 0 );
92 +            ::close( fd );
93 +        }
94      } else {
95 -        return OAbstractMobileDevice::setDisplayStatus(on);
96 +        res = OAbstractMobileDevice::setDisplayStatus(on);
97      }
98  
99 -    res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
100 -
101      return res;
102  }
103  
104  bool iPAQ::hasLightSensor() const
105  {
106 -    return true;
107 +    switch ( model()) {
108 +        case Model_iPAQ_H191x:
109 +        case Model_iPAQ_H22xx:
110 +           return false;
111 +
112 +       default:
113 +           return true;
114 +    }
115  }
116  
117  int iPAQ::readLightSensor()