hal/hald/linux2/addons Makefile.am, 1.8, 1.9 addon-acpi-buttons-toshiba.c, NONE, 1.1

Richard Hughes hughsient at kemper.freedesktop.org
Fri Mar 3 09:48:13 PST 2006


Update of /cvs/hal/hal/hald/linux2/addons
In directory kemper:/tmp/cvs-serv12317/hald/linux2/addons

Modified Files:
	Makefile.am 
Added Files:
	addon-acpi-buttons-toshiba.c 
Log Message:
2006-03-03  Richard Hughes <richard at hughsie.com>
 * hald/linux2/addons/addon-acpi-buttons-toshiba.c, hald/linux2/addons/Makefile.am: Build hald-addon-acpi-buttons-toshiba. When the acpi->input patches get sent to the kernel, and HAL has a dependency on this new kernel version, this addon can probably be removed. Seeing as this may be years away, adding the addon is a good thing to do as it makes the Fn keys on Toshiba work.
 * fdi/policy/10osvendor/10-toshiba-buttons.fdi, fdi/policy/10osvendor/Makefile.am: Launch the toshiba acpi addon for toshiba laptops only.


Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Makefile.am	8 Feb 2006 13:54:44 -0000	1.8
+++ Makefile.am	3 Mar 2006 17:48:11 -0000	1.9
@@ -9,7 +9,13 @@
 	@PACKAGE_CFLAGS@
 
 if HALD_COMPILE_LINUX2
-libexec_PROGRAMS  = hald-addon-hid-ups hald-addon-acpi hald-addon-storage hald-addon-pmu hald-addon-keyboard
+libexec_PROGRAMS  = \
+	hald-addon-hid-ups \
+	hald-addon-acpi \
+	hald-addon-acpi-buttons-toshiba \
+	hald-addon-storage \
+	hald-addon-keyboard \
+	hald-addon-pmu
 
 if HAVE_LIBUSB
 libexec_PROGRAMS += hald-addon-usb-csr
@@ -25,6 +31,9 @@
 hald_addon_pmu_SOURCES = addon-pmu.c
 hald_addon_pmu_LDADD = $(top_builddir)/libhal/libhal.la
 
+hald_addon_acpi_buttons_toshiba_SOURCES = addon-acpi-buttons-toshiba.c
+hald_addon_acpi_buttons_toshiba_LDADD = $(top_builddir)/libhal/libhal.la @PACKAGE_LIBS@
+
 hald_addon_storage_SOURCES = addon-storage.c
 hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
 

--- NEW FILE: addon-acpi-buttons-toshiba.c ---
/*! @file	addon-acpi-buttons-toshiba.c
 *  @brief	Toshiba SMM Button Addon
 *  @author	Richard Hughes <richard at hughsie.com>
 *  @date	2005-10-15
 *
 *  @note	Low level routines from IAL, Copyright (C) 2004, 2005
 *		Timo Hoenig <thoenig at nouse.net>
 */
/*
 * Licensed under the GNU General Public License Version 2
 *
 * 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; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <linux/input.h>
#include <glib/gmain.h>

#include "libhal/libhal.h"
#include "../probing/shared.h"

/** Toshiba ACPI key interface */
#define TOSHIBA_ACPI_KEYS		"/proc/acpi/toshiba/keys"

/** Polling frequency in ms */
#define TOSHIBA_POLL_FREQ       	250

static LibHalContext *ctx = NULL;
static char* udi;

/** Flush keys from the Toshiba hotkey register */
static void
toshiba_key_flush (void)
{
	int hotkey_ready = 1;
	int value;
	FILE *fp = fopen (TOSHIBA_ACPI_KEYS, "r+");
	if (!fp) {
		dbg ("Could not open %s!", TOSHIBA_ACPI_KEYS);
		return;
	}
	while (hotkey_ready) {
		fprintf (fp, "hotkey_ready:0\n");
		fclose (fp);
		fp = fopen (TOSHIBA_ACPI_KEYS, "r+");
		fscanf (fp, "hotkey_ready: %d\nhotkey: 0x%4x",
			&hotkey_ready, &value);
	}
	if (fp)
		fclose (fp);
}

/** Check whether there is a new event in the hotkey register
 *
 *  @param	value	The key id pressed, passed by reference
 *  @returns		TRUE if there is an event pending, FALSE if no event pending.
 */
static gboolean
toshiba_key_ready (int *value)
{
	FILE *fp = fopen (TOSHIBA_ACPI_KEYS, "r+");
	int hotkey_ready = -1;

	if (!fp)
		return FALSE;

	fscanf (fp, "hotkey_ready: %1d\nhotkey: 0x%4x",
		&hotkey_ready, value);

	if (hotkey_ready) {
		fprintf (fp, "hotkey_ready:0\n");
		fclose (fp);
		return TRUE;
	}
	fclose (fp);
	return FALSE;
}

/** Callback to poll hotkey register and report occuring events.
 *
 *  @returns		TRUE on success, else FALSE.
 */
static gboolean
toshiba_key_poll (void)
{
	char *result;
	int value;
	DBusError error;
	dbus_error_init (&error);

	/* for each key */
	while (toshiba_key_ready (&value) == TRUE) {
		result = NULL;
		if (value == 0x101) /* FnESC */
			result = "mute";
		else if (value == 0x13b) /* FnF1 */
			result = "lock";
		else if (value == 0x13c) /* FnF2 */
			result = "search";
		else if (value == 0x13d) /* FnF3 */
			result = "suspend";
		else if (value == 0x13e) /* FnF4 */
			result = "hibernate";
		else if (value == 0x140) /* FnF6 */
			result = "brightness-down";
		else if (value == 0x141) /* FnF7 */
			result = "brightness-up";
		else if (value == 0x142) /* FnF8 */
			result = "wifi-power";

		if (result) {
			dbg ("Sending condition '%s'", result);
			libhal_device_emit_condition (ctx, udi, "ButtonPressed", result, &error);
			if (dbus_error_is_set (&error)) {
				dbg ("Failed to send condition: %s", error.message);
				dbus_error_free (&error);
			}
		}
	}
	return TRUE;
}

/** Main program
 */
int
main (int argc, char **argv)
{
	GMainLoop *loop = NULL;
	DBusError error;
	FILE *fp;

	if ((getenv ("HALD_VERBOSE")) != NULL)
		is_verbose = TRUE;
	udi = getenv ("UDI");
	if (udi == NULL) {
		dbg ("Failed to get UDI");
		return 1;
	}
	dbus_error_init (&error);
	if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
		dbg ("Unable to initialise libhal context: %s", error.message);
		return 1;
	}

	/* Check for Toshiba ACPI interface /proc/acpi/toshiba/keys */
	fp = fopen (TOSHIBA_ACPI_KEYS, "r+");
	if (!fp) {
		dbg ("Could not open %s! Aborting.", TOSHIBA_ACPI_KEYS);
		return 0;
	}
	fclose (fp);

	/* Flush keys as we may have some already in buffer */
	toshiba_key_flush ();

	/* Get the new input */
	g_timeout_add (TOSHIBA_POLL_FREQ, (GSourceFunc) toshiba_key_poll, NULL);

	loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (loop);
	return 0;
}




More information about the hal-commit mailing list