[Pommed-commits] r309 - trunk/pommed/pmac

Yves-Alexis Perez corsac-guest at alioth.debian.org
Sun Apr 15 16:51:36 UTC 2007


Author: corsac-guest
Date: 2007-04-15 16:51:36 +0000 (Sun, 15 Apr 2007)
New Revision: 309

Modified:
   trunk/pommed/pmac/kbd_backlight.c
Log:
apply patch from JB for kbd fade on ppc

Modified: trunk/pommed/pmac/kbd_backlight.c
===================================================================
--- trunk/pommed/pmac/kbd_backlight.c	2007-04-15 15:09:34 UTC (rev 308)
+++ trunk/pommed/pmac/kbd_backlight.c	2007-04-15 16:51:36 UTC (rev 309)
@@ -28,6 +28,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
+#include <time.h>
 
 #include <syslog.h>
 
@@ -81,7 +82,15 @@
 static void
 kbd_backlight_set(int val, int who)
 {
-  int fd, curval, ret;
+  int curval;
+
+  int i;
+  float fadeval;
+  float step;
+  struct timespec fade_step;
+
+  int fd;
+  int ret;
   unsigned char buf[8];
 
   if (kbd_bck_info.inhibit)
@@ -98,19 +107,6 @@
   if (lmuaddr == 0)
     return;
 
-  buf[0] = 0x01;   /* i2c register */
-  
-  /* The format appears to be: (taken from pbbuttonsd)
-   *          byte 1   byte 2
-   *         |<---->| |<---->|
-   *         xxxx7654 3210xxxx
-   *             |<----->|
-   *                 ^-- brightness
-   */
-  
-  buf[1] = (unsigned char) val >> 4;
-  buf[2] = (unsigned char) val << 4;
-
   fd = open (i2cdev, O_RDWR);
   if (fd < 0)
     {
@@ -128,6 +124,48 @@
       return;
     }
 
+  buf[0] = 0x01;   /* i2c register */
+
+  if (who == KBD_AUTO)
+    {
+      fade_step.tv_sec = 0;
+      fade_step.tv_nsec = (KBD_BACKLIGHT_FADE_LENGTH / KBD_BACKLIGHT_FADE_STEPS) * 1000000;
+
+      fadeval = (float)curval;
+      step = (float)(val - curval) / (float)KBD_BACKLIGHT_FADE_STEPS;
+
+      for (i = 0; i < KBD_BACKLIGHT_FADE_STEPS; i++)
+	{
+	  fadeval += step;
+
+	  /* See below for the format */
+	  buf[1] = (unsigned char) fadeval >> 4;
+	  buf[2] = (unsigned char) fadeval << 4;
+
+	  if (write (fd, buf, 3) < 0)
+	    {
+	      logmsg(LOG_ERR, "Could not set kbd brightness: %s\n", strerror(errno));
+
+	      continue;
+	    }
+
+	  logdebug("KBD backlight value faded to %d\n", (int)fadeval);
+
+	  nanosleep(&fade_step, NULL);
+	}
+    }
+  
+  /* The format appears to be: (taken from pbbuttonsd)
+   *          byte 1   byte 2
+   *         |<---->| |<---->|
+   *         xxxx7654 3210xxxx
+   *             |<----->|
+   *                 ^-- brightness
+   */
+  
+  buf[1] = (unsigned char) val >> 4;
+  buf[2] = (unsigned char) val << 4;
+
   if (write (fd, buf, 3) < 0)
     logmsg(LOG_ERR, "Could not set kbd brightness: %s\n", strerror(errno));
 




More information about the Pommed-commits mailing list