[PATCH] H22xx backlight support

Slavek Banko <[email protected]>
Newsgroups gmane.comp.handhelds.opie.devel
Organization axis, spol. s r. o.
Message-ID <[email protected]>
Hi.

Here is patch to add support for backlight on H22xx.

Instead of using "::system" (and running external process as support for 
H1910 and H4700), I write to files in /sys/class/... directly.

I consider to replace all model 
specific /sys/class/backlight/_model_specific_device_/brightness 
and /sys/class/lcd/_model_specific_device_/power by code, that find 
devices by current contents of /sys/class/backlight/ and /sys/class/lcd/. 
That code will be common for more devices. Can I make it?

Slavek

_______________________________________________

http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex

Opie-devel mailing list
[email protected]
https://handhelds.org/mailman/listinfo/opie-devel
h22xx-backlight.patch (text/x-diff, 3 KB)
diff -aruN libopie2.orig/opie/libopie2/opiecore/device/odevice_ipaq.cpp libopie2/opie/libopie2/opiecore/device/odevice_ipaq.cpp
--- libopie2.orig/opie/libopie2/opiecore/device/odevice_ipaq.cpp	2006-05-27 19:29:31.000000000 +0200
+++ libopie2/opie/libopie2/opiecore/device/odevice_ipaq.cpp	2006-05-27 21:38:55.000000000 +0200
@@ -387,6 +387,18 @@
         res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
         break; 
 	
+    case Model_iPAQ_H22xx:
+        fd = ::open( "/sys/class/backlight/mq11xx_fb0/brightness", O_WRONLY|O_NONBLOCK );
+        if ( fd )
+        {
+            char buf[100];
+            int val = ( bright == 1 ) ? 1 : ( bright * displayBrightnessResolution() ) / 255;
+            int len = ::snprintf( &buf[0], sizeof buf, "%d", val );
+            res = ( ::write( fd, &buf[0], len ) == 0 );
+            ::close( fd );
+        }
+        break;
+
     case Model_iPAQ_HX4700:
             cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright );
         // No Global::shellQuote as we gurantee it to be sane
@@ -409,6 +421,7 @@
 
 int iPAQ::displayBrightnessResolution() const
 {
+    int res = 1;
     switch ( model()) {
         case Model_iPAQ_H31xx:
         case Model_iPAQ_H36xx:
@@ -425,6 +438,17 @@
             return 7;
         case Model_iPAQ_H1940:
             return 44;
+
+        case Model_iPAQ_H22xx:
+            int fd = ::open( "/sys/class/backlight/mq11xx_fb0/max_brightness", O_RDONLY|O_NONBLOCK );
+            if ( fd ) {
+                char buf[100];
+                if ( ::read( fd, &buf[0], sizeof buf ) )
+            	    ::sscanf( &buf[0], "%d", &res );
+                ::close( fd );
+            }
+            return res;
+
         default:
             return 2;
     }
@@ -436,20 +460,37 @@
 
     QString cmdline;
 
-    if ( model() == Model_iPAQ_H191x ) {
-        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" );
-    } else {
-        return OAbstractMobileDevice::setDisplayStatus(on);
-    }
-
-    res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
+    switch (model()) {
+	case Model_iPAQ_H191x:
+            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" );
+	    return ( ::system( QFile::encodeName(cmdline) ) == 0 );
+
+	case Model_iPAQ_H22xx:
+    	    int fd = ::open( "/sys/class/lcd/mq11xx_fb0/power", O_WRONLY|O_NONBLOCK );
+    	    if ( fd )
+    	    {
+        	char buf[10];
+        	buf[0] = on ? 0 : 4;
+        	buf[1] = '\0';
+        	res = ( ::write( fd, &buf[0], 2 ) == 0 );
+        	::close( fd );
+    	    }
+	    return res;
 
-    return res;
+	default:
+	    return OAbstractMobileDevice::setDisplayStatus(on);
+    }
 }
 
 bool iPAQ::hasLightSensor() const
 {
-    return true;
+    switch ( model()) {
+        case Model_iPAQ_H22xx:
+	    return false;
+
+	default:
+	    return true;
+    }
 }
 
 int iPAQ::readLightSensor()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.