[Pommed-commits] r507 - in trunk: . pommed/pmac
jblache at alioth.debian.org
jblache at alioth.debian.org
Tue Jul 22 08:58:09 UTC 2008
Author: jblache
Date: 2008-07-22 08:58:08 +0000 (Tue, 22 Jul 2008)
New Revision: 507
Modified:
trunk/ChangeLog
trunk/pommed/pmac/kbd_backlight.c
Log:
Factor out ADB & LMU write routines, avoids duplicated code.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-07-22 08:40:28 UTC (rev 506)
+++ trunk/ChangeLog 2008-07-22 08:58:08 UTC (rev 507)
@@ -4,6 +4,8 @@
version 1.22:
- pommed: do not probe for LMU controller on pmac machines that do
not have a backlit keyboard. Avoids a spurious error message.
+ - pommed: factor out ADB & LMU write routines, avoids duplicated
+ code in the kbd_{lmu,pmu}_backlight_set() routines.
version 1.21:
- gpomme: use compositing if available, patch by Soeren Sonnenburg.
Modified: trunk/pommed/pmac/kbd_backlight.c
===================================================================
--- trunk/pommed/pmac/kbd_backlight.c 2008-07-22 08:40:28 UTC (rev 506)
+++ trunk/pommed/pmac/kbd_backlight.c 2008-07-22 08:58:08 UTC (rev 507)
@@ -64,7 +64,30 @@
}
+/* Helper for LMU-controlled keyboards */
static void
+lmu_write_kbd_value(int fd, unsigned char val)
+{
+ unsigned char buf[3];
+
+ buf[0] = 0x01; /* i2c register */
+
+ /* The format appears to be: (taken from pbbuttonsd)
+ * byte 1 byte 2
+ * |<---->| |<---->|
+ * xxxx7654 3210xxxx
+ * |<----->|
+ * ^-- brightness
+ */
+
+ buf[1] = val >> 4;
+ buf[2] = val << 4;
+
+ if (write (fd, buf, 3) < 0)
+ logmsg(LOG_ERR, "Could not set LMU kbd brightness: %s\n", strerror(errno));
+}
+
+static void
kbd_lmu_backlight_set(int val, int who)
{
int curval;
@@ -76,7 +99,6 @@
int fd;
int ret;
- unsigned char buf[8];
if (kbd_bck_info.inhibit & ~KBD_INHIBIT_CFG)
return;
@@ -109,8 +131,6 @@
return;
}
- buf[0] = 0x01; /* i2c register */
-
if (who == KBD_AUTO)
{
fade_step.tv_sec = 0;
@@ -123,36 +143,15 @@
{
fadeval += step;
- /* See below for the format */
- buf[1] = (unsigned char) fadeval >> 4;
- buf[2] = (unsigned char) fadeval << 4;
+ lmu_write_kbd_value(fd, (unsigned char)fadeval);
- if (write (fd, buf, 3) < 0)
- {
- logmsg(LOG_ERR, "Could not set LMU 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 LMU kbd brightness: %s\n", strerror(errno));
+ lmu_write_kbd_value(fd, val);
close(fd);
@@ -161,7 +160,34 @@
kbd_bck_info.level = val;
}
+
+/* Helper for ADB keyboards */
static void
+adb_write_kbd_value(int fd, unsigned char val)
+{
+ int ret;
+ unsigned char buf[ADB_BUFFER_SIZE];
+
+ buf[0] = PMU_PACKET;
+ buf[1] = 0x4f; /* PMU command */
+ buf[2] = 0;
+ buf[3] = 0;
+ buf[4] = val;
+
+ ret = write(fd, buf, 5);
+ if (ret != 5)
+ {
+ logmsg(LOG_ERR, "Could not set PMU kbd brightness: %s\n", strerror(errno));
+ }
+ else
+ {
+ ret = read(fd, buf, ADB_BUFFER_SIZE);
+ if (ret < 0)
+ logmsg(LOG_ERR, "Could not read PMU reply: %s\n", strerror(errno));
+ }
+}
+
+static void
kbd_pmu_backlight_set(int val, int who)
{
int curval;
@@ -172,8 +198,6 @@
struct timespec fade_step;
int fd;
- int ret;
- unsigned char buf[ADB_BUFFER_SIZE];
if (kbd_bck_info.inhibit & ~KBD_INHIBIT_CFG)
return;
@@ -206,51 +230,15 @@
{
fadeval += step;
- buf[0] = PMU_PACKET;
- buf[1] = 0x4f; /* PMU command */
- buf[2] = 0;
- buf[3] = 0;
- buf[4] = (unsigned char)fadeval;
+ adb_write_kbd_value(fd, (unsigned char)val);
- ret = write(fd, buf, 5);
- if (ret != 5)
- {
- logmsg(LOG_ERR, "Could not set PMU kbd brightness: %s\n", strerror(errno));
-
- continue;
- }
-
- ret = read(fd, buf, ADB_BUFFER_SIZE);
- if (ret < 0)
- {
- logmsg(LOG_ERR, "Could not read PMU reply: %s\n", strerror(errno));
-
- continue;
- }
-
logdebug("KBD backlight value faded to %d\n", (int)fadeval);
nanosleep(&fade_step, NULL);
}
}
-
- buf[0] = PMU_PACKET;
- buf[1] = 0x4f; /* PMU command */
- buf[2] = 0;
- buf[3] = 0;
- buf[4] = val;
- ret = write(fd, buf, 5);
- if (ret != 5)
- {
- logmsg(LOG_ERR, "Could not set PMU kbd brightness: %s\n", strerror(errno));
- }
- else
- {
- ret = read(fd, buf, ADB_BUFFER_SIZE);
- if (ret < 0)
- logmsg(LOG_ERR, "Could not read PMU reply: %s\n", strerror(errno));
- }
+ adb_write_kbd_value(fd, val);
close(fd);
More information about the Pommed-commits
mailing list