[Pommed-commits] r291 - in trunk/pommed: . mactel pmac

Julien Blache jblache at alioth.debian.org
Fri Mar 2 20:45:47 CET 2007


Author: jblache
Date: 2007-03-02 19:45:47 +0000 (Fri, 02 Mar 2007)
New Revision: 291

Added:
   trunk/pommed/kbd_auto.c
Modified:
   trunk/pommed/Makefile
   trunk/pommed/kbd_backlight.h
   trunk/pommed/mactel/kbd_backlight.c
   trunk/pommed/pmac/kbd_backlight.c
Log:
Split automatic backlight code into kbd_auto.c.

Adapt pmac code to the new automatic backlight.


Modified: trunk/pommed/Makefile
===================================================================
--- trunk/pommed/Makefile	2007-03-02 19:34:39 UTC (rev 290)
+++ trunk/pommed/Makefile	2007-03-02 19:45:47 UTC (rev 291)
@@ -57,7 +57,7 @@
 
 
 # PowerMac-specific files
-pmac/kbd_backlight.o: pmac/kbd_backlight.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
+pmac/kbd_backlight.o: pmac/kbd_backlight.c kbd_auto.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
 
 pmac/sysfs_backlight.o: pmac/sysfs_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
 
@@ -79,7 +79,7 @@
 
 mactel/gma950_backlight.o: mactel/gma950_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
 
-mactel/kbd_backlight.o: mactel/kbd_backlight.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
+mactel/kbd_backlight.o: mactel/kbd_backlight.c kbd_auto.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
 
 mactel/ambient.o: mactel/ambient.c ambient.h pommed.h dbus.h
 

Added: trunk/pommed/kbd_auto.c
===================================================================
--- trunk/pommed/kbd_auto.c	2007-03-02 19:34:39 UTC (rev 290)
+++ trunk/pommed/kbd_auto.c	2007-03-02 19:45:47 UTC (rev 291)
@@ -0,0 +1,109 @@
+/*
+ * pommed - Apple laptops hotkeys handler daemon
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006-2007 Julien BLACHE <jb at jblache.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+void
+kbd_backlight_inhibit_set(int mask)
+{
+  if (!kbd_bck_info.inhibit)
+    kbd_bck_info.inhibit_lvl = kbd_bck_info.level;
+
+  kbd_backlight_set(KBD_BACKLIGHT_OFF,
+		    (mask == KBD_INHIBIT_LID) ? (KBD_AUTO) : (KBD_USER));
+
+  kbd_bck_info.inhibit |= mask;
+
+  logdebug("KBD: inhibit set 0x%02x -> 0x%02x\n", mask, kbd_bck_info.inhibit);
+}
+
+void
+kbd_backlight_inhibit_clear(int mask)
+{
+  kbd_bck_info.inhibit &= ~mask;
+
+  logdebug("KBD: inhibit clear 0x%02x -> 0x%02x\n", mask, kbd_bck_info.inhibit);
+
+  if (kbd_bck_info.inhibit)
+    return;
+
+  if (kbd_bck_info.auto_on)
+    {
+      kbd_bck_info.auto_on = 0;
+      kbd_bck_info.inhibit_lvl = 0;
+    }
+
+  kbd_backlight_set(kbd_bck_info.inhibit_lvl,
+		    (mask == KBD_INHIBIT_LID) ? (KBD_AUTO) : (KBD_USER));
+}
+
+void
+kbd_backlight_inhibit_toggle(int mask)
+{
+  if (kbd_bck_info.inhibit & mask)
+    kbd_backlight_inhibit_clear(mask);
+  else
+    kbd_backlight_inhibit_set(mask);
+}
+
+
+void
+kbd_backlight_ambient_check(void)
+{
+  int amb_r, amb_l;
+
+  ambient_get(&amb_r, &amb_l);
+
+  if ((amb_r < 0) || (amb_l < 0))
+    return;
+
+  mbpdbus_send_ambient_light(amb_l, kbd_bck_info.l_sens, amb_r, kbd_bck_info.r_sens);
+
+  kbd_bck_info.r_sens = amb_r;
+  kbd_bck_info.l_sens = amb_l;
+
+  /* Inhibited */
+  if (kbd_bck_info.inhibit)
+    return;
+
+  if ((amb_r < kbd_cfg.on_thresh) && (amb_l < kbd_cfg.on_thresh))
+    {
+      logdebug("Ambient light lower threshold reached\n");
+
+      /* backlight already on */
+      if (kbd_backlight_get() > KBD_BACKLIGHT_OFF)
+	return;
+
+      /* turn on backlight */
+      kbd_bck_info.auto_on = 1;
+
+      kbd_backlight_set(kbd_cfg.auto_lvl, KBD_AUTO);
+    }
+  else if (kbd_bck_info.auto_on)
+    {
+      if ((amb_r > kbd_cfg.off_thresh) || (amb_l > kbd_cfg.off_thresh))
+	{
+	  logdebug("Ambient light upper threshold reached\n");
+
+	  kbd_bck_info.auto_on = 0;
+
+	  kbd_backlight_set(KBD_BACKLIGHT_OFF, KBD_AUTO);
+	}
+    }
+}


Property changes on: trunk/pommed/kbd_auto.c
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/pommed/kbd_backlight.h
===================================================================
--- trunk/pommed/kbd_backlight.h	2007-03-02 19:34:39 UTC (rev 290)
+++ trunk/pommed/kbd_backlight.h	2007-03-02 19:45:47 UTC (rev 291)
@@ -52,25 +52,27 @@
 has_kbd_backlight(void);
 
 void
-kbd_backlight_inhibit_set(int mask);
+kbd_backlight_step(int dir);
 
 void
-kbd_backlight_inhibit_clear(int mask);
+kbd_backlight_init(void);
 
 void
-kbd_backlight_inhibit_toggle(int mask);
+kbd_backlight_fix_config(void);
 
+
+/* In kbd_auto.c */
 void
-kbd_backlight_step(int dir);
+kbd_backlight_inhibit_set(int mask);
 
 void
-kbd_backlight_init(void);
+kbd_backlight_inhibit_clear(int mask);
 
 void
-kbd_backlight_ambient_check(void);
+kbd_backlight_inhibit_toggle(int mask);
 
 void
-kbd_backlight_fix_config(void);
+kbd_backlight_ambient_check(void);
 
 
 #endif /* !__KBD_BACKLIGHT_H__ */

Modified: trunk/pommed/mactel/kbd_backlight.c
===================================================================
--- trunk/pommed/mactel/kbd_backlight.c	2007-03-02 19:34:39 UTC (rev 290)
+++ trunk/pommed/mactel/kbd_backlight.c	2007-03-02 19:45:47 UTC (rev 291)
@@ -157,51 +157,11 @@
 }
 
 
-void
-kbd_backlight_inhibit_set(int mask)
-{
-  if (!kbd_bck_info.inhibit)
-    kbd_bck_info.inhibit_lvl = kbd_bck_info.level;
+/* Include automatic backlight routines */
+#include "../kbd_auto.c"
 
-  kbd_backlight_set(KBD_BACKLIGHT_OFF,
-		    (mask == KBD_INHIBIT_LID) ? (KBD_AUTO) : (KBD_USER));
 
-  kbd_bck_info.inhibit |= mask;
-
-  logdebug("KBD: inhibit set 0x%02x -> 0x%02x\n", mask, kbd_bck_info.inhibit);
-}
-
 void
-kbd_backlight_inhibit_clear(int mask)
-{
-  kbd_bck_info.inhibit &= ~mask;
-
-  logdebug("KBD: inhibit clear 0x%02x -> 0x%02x\n", mask, kbd_bck_info.inhibit);
-
-  if (kbd_bck_info.inhibit)
-    return;
-
-  if (kbd_bck_info.auto_on)
-    {
-      kbd_bck_info.auto_on = 0;
-      kbd_bck_info.inhibit_lvl = 0;
-    }
-
-  kbd_backlight_set(kbd_bck_info.inhibit_lvl,
-		    (mask == KBD_INHIBIT_LID) ? (KBD_AUTO) : (KBD_USER));
-}
-
-void
-kbd_backlight_inhibit_toggle(int mask)
-{
-  if (kbd_bck_info.inhibit & mask)
-    kbd_backlight_inhibit_clear(mask);
-  else
-    kbd_backlight_inhibit_set(mask);
-}
-
-
-void
 kbd_backlight_init(void)
 {
   if (kbd_cfg.auto_on)
@@ -236,52 +196,7 @@
   ambient_init(&kbd_bck_info.r_sens, &kbd_bck_info.l_sens);
 }
 
-void
-kbd_backlight_ambient_check(void)
-{
-  int amb_r, amb_l;
 
-  ambient_get(&amb_r, &amb_l);
-
-  if ((amb_r < 0) || (amb_l < 0))
-    return;
-
-  mbpdbus_send_ambient_light(amb_l, kbd_bck_info.l_sens, amb_r, kbd_bck_info.r_sens);
-
-  kbd_bck_info.r_sens = amb_r;
-  kbd_bck_info.l_sens = amb_l;
-
-  /* Inhibited */
-  if (kbd_bck_info.inhibit)
-    return;
-
-  if ((amb_r < kbd_cfg.on_thresh) && (amb_l < kbd_cfg.on_thresh))
-    {
-      logdebug("Ambient light lower threshold reached\n");
-
-      /* backlight already on */
-      if (kbd_backlight_get() > KBD_BACKLIGHT_OFF)
-	return;
-
-      /* turn on backlight */
-      kbd_bck_info.auto_on = 1;
-
-      kbd_backlight_set(kbd_cfg.auto_lvl, KBD_AUTO);
-    }
-  else if (kbd_bck_info.auto_on)
-    {
-      if ((amb_r > kbd_cfg.off_thresh) || (amb_l > kbd_cfg.off_thresh))
-	{
-	  logdebug("Ambient light upper threshold reached\n");
-
-	  kbd_bck_info.auto_on = 0;
-
-	  kbd_backlight_set(KBD_BACKLIGHT_OFF, KBD_AUTO);
-	}
-    }
-}
-
-
 void
 kbd_backlight_fix_config(void)
 {

Modified: trunk/pommed/pmac/kbd_backlight.c
===================================================================
--- trunk/pommed/pmac/kbd_backlight.c	2007-03-02 19:34:39 UTC (rev 290)
+++ trunk/pommed/pmac/kbd_backlight.c	2007-03-02 19:45:47 UTC (rev 291)
@@ -83,28 +83,11 @@
   int fd, curval, ret;
   unsigned char buf[8];
 
+  if (kbd_bck_info.inhibit)
+    return;
+
   curval = kbd_backlight_get();
 
-  /* automatic backlight toggle by user */
-  if ((val == KBD_BACKLIGHT_OFF) && (kbd_bck_info.auto_on))
-    {
-      if (!kbd_bck_info.off)
-        {
-          kbd_bck_info.off = 1;
-          kbd_bck_info.level = curval;
-        }
-      else
-        {
-          kbd_bck_info.off = 0;
-          val = kbd_bck_info.level;
-        }
-    }
-
-  /* backlight turned on again by user */
-  if ((val > KBD_BACKLIGHT_OFF)
-      && (kbd_bck_info.auto_on) && (kbd_bck_info.off))
-    kbd_bck_info.off = 0;
-
   if (val == curval)
     return;
 
@@ -155,17 +138,14 @@
 }
 
 void
-kbd_backlight_off(void)
-{
-  kbd_backlight_set(KBD_BACKLIGHT_OFF, KBD_USER);
-}
-
-void
 kbd_backlight_step(int dir)
 {
   int val;
   int newval;
 
+  if (kbd_bck_info.inhibit)
+    return;
+
   if (lmuaddr == 0)
     return;
 
@@ -198,13 +178,24 @@
   kbd_backlight_set(newval, KBD_USER);
 }
 
+
+/* Include automatic backlight routines */
+#include "../kbd_auto.c"
+
+
 void
 kbd_backlight_init(void)
 {
   int ret;
 
+  if (kbd_cfg.auto_on)
+    kbd_bck_info.inhibit = 0;
+  else
+    kbd_bck_info.inhibit = KBD_INHIBIT_USER;
+
+  kbd_bck_info.inhibit_lvl = 0;
+
   kbd_bck_info.auto_on = 0;
-  kbd_bck_info.off = 0;
 
   lmuaddr = kbd_get_lmuaddr();
   i2cdev = "/dev/i2c-7";
@@ -238,54 +229,7 @@
   ambient_init(&kbd_bck_info.r_sens, &kbd_bck_info.l_sens);
 }
 
-void
-kbd_backlight_ambient_check(void)
-{
-  int amb_r, amb_l;
 
-  ambient_get(&amb_r, &amb_l);
-
-  if ((amb_r < 0) || (amb_l < 0))
-    return;
-
-  if ((amb_r < kbd_cfg.on_thresh) && (amb_l < kbd_cfg.on_thresh))
-    {
-      logdebug("Ambient light lower threshold reached\n");
-
-      /* backlight turned on automatically, then disabled by user */
-      if (kbd_bck_info.auto_on && kbd_bck_info.off)
-	return;
-
-      /* backlight already on */
-      if (kbd_backlight_get() > KBD_BACKLIGHT_OFF)
-	return;
-
-      /* turn on backlight */
-      kbd_bck_info.auto_on = 1;
-      kbd_bck_info.off = 0;
-
-      kbd_backlight_set(kbd_cfg.auto_lvl, KBD_AUTO);
-    }
-  else if (kbd_bck_info.auto_on)
-    {
-      if ((amb_r > kbd_cfg.off_thresh) || (amb_l > kbd_cfg.off_thresh))
-	{
-	  logdebug("Ambient light upper threshold reached\n");
-
-	  kbd_bck_info.auto_on = 0;
-	  kbd_bck_info.off = 0;
-
-	  kbd_backlight_set(KBD_BACKLIGHT_OFF, KBD_AUTO);
-	}
-    }
-
-  mbpdbus_send_ambient_light(amb_l, kbd_bck_info.l_sens, amb_r, kbd_bck_info.r_sens);
-
-  kbd_bck_info.r_sens = amb_r;
-  kbd_bck_info.l_sens = amb_l;
-}
-
-
 void
 kbd_backlight_fix_config(void)
 {




More information about the Pommed-commits mailing list