>From 24cb3733ebc40c96a8bad7384797c50f64f49be6 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofour...@redhat.com>
Date: Tue, 2 Oct 2012 16:39:11 +0200
Subject: [PATCH 1/2] lib: add helper functions to get LED modeswitch group

Adds a new field "ModeswitchLED" to the libwacom
database definition file to specify which buttons
feature a usable status LED for current mode.

Adds a libwacom_get_modeswitch_led_group() helper
function to compute which status LED is to use for
the given button. If a device has only one ring/strip,
use LED 0 otherwise the left ring/strip is controlled
by LED 1 and the right ring/strip by LED 0.

Also adds a convenient libwacom_get_num_rings()
to match the similar libwacom_get_num_strips().

Signed-off-by: Olivier Fourdan <ofour...@redhat.com>
---
 libwacom/libwacom-database.c |    3 +-
 libwacom/libwacom.c          |   70 ++++++++++++++++++++++++++++++++++++++++++
 libwacom/libwacom.h          |   16 +++++++++
 3 files changed, 88 insertions(+), 1 deletions(-)

diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index 5468975..6d8d4d4 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -243,7 +243,8 @@ struct {
 	{ "Ring2", WACOM_BUTTON_RING2_MODESWITCH },
 	{ "Touchstrip", WACOM_BUTTON_TOUCHSTRIP_MODESWITCH },
 	{ "Touchstrip2", WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH },
-	{ "OLEDs", WACOM_BUTTON_OLED }
+	{ "OLEDs", WACOM_BUTTON_OLED },
+	{ "ModeswitchLED", WACOM_BUTTON_MODESWITCH_LED }
 };
 
 static void
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index fe850a2..55d1ff2 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -540,6 +540,19 @@ static void print_button_flag_if(int fd, WacomDevice *device, const char *label,
 	dprintf(fd, "\n");
 }
 
+static void print_buttons_led_for_device (int fd, WacomDevice *device)
+{
+	int nbuttons = libwacom_get_num_buttons(device);
+	char b;
+	int led_group;
+
+	for (b = 'A'; b < 'A' + nbuttons; b++) {
+		led_group = libwacom_get_modeswitch_led_group (device, b);
+		if (led_group >= 0)
+			dprintf(fd, "Button%c = LED group %d\n", b, led_group);
+	}
+}
+
 static void print_buttons_for_device (int fd, WacomDevice *device)
 {
 	int nbuttons = libwacom_get_num_buttons(device);
@@ -556,8 +569,10 @@ static void print_buttons_for_device (int fd, WacomDevice *device)
 	print_button_flag_if(fd, device, "Touchstrip", WACOM_BUTTON_TOUCHSTRIP_MODESWITCH);
 	print_button_flag_if(fd, device, "Touchstrip2", WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH);
 	print_button_flag_if(fd, device, "OLEDs", WACOM_BUTTON_OLED);
+	print_button_flag_if(fd, device, "ModeswitchLED", WACOM_BUTTON_MODESWITCH_LED);
 	print_button_flag_if(fd, device, "Ring", WACOM_BUTTON_RING_MODESWITCH);
 	print_button_flag_if(fd, device, "Ring2", WACOM_BUTTON_RING2_MODESWITCH);
+	print_buttons_led_for_device (fd, device);
 	dprintf(fd, "RingNumModes=%d\n", libwacom_get_ring_num_modes(device));
 	dprintf(fd, "Ring2NumModes=%d\n", libwacom_get_ring2_num_modes(device));
 	dprintf(fd, "StripsNumModes=%d\n", libwacom_get_strips_num_modes(device));
@@ -749,6 +764,16 @@ const int *libwacom_get_supported_styli(WacomDevice *device, int *num_styli)
 	return device->supported_styli;
 }
 
+int libwacom_get_num_rings(WacomDevice *device)
+{
+	if (device->features & FEATURE_RING2)
+		return 2;
+	if (device->features & FEATURE_RING)
+		return 1;
+
+	return 0;
+}
+
 int libwacom_has_ring(WacomDevice *device)
 {
 	return !!(device->features & FEATURE_RING);
@@ -779,6 +804,51 @@ int libwacom_get_strips_num_modes(WacomDevice *device)
 	return device->strips_num_modes;
 }
 
+int libwacom_get_modeswitch_led_group (WacomDevice *device,
+				       char         button)
+{
+	int index;
+	int num_rings;
+	int num_strips;
+
+	g_return_val_if_fail (device->num_buttons > 0, -1);
+	g_return_val_if_fail (button >= 'A', -1);
+	g_return_val_if_fail (button < 'A' + device->num_buttons, -1);
+
+	index = button - 'A';
+
+	if (!(device->buttons[index] & WACOM_BUTTON_MODESWITCH) ||
+	    !(device->buttons[index] & WACOM_BUTTON_MODESWITCH_LED))
+		return -1;
+
+	/*
+	 * The rule to determine the status LED to use is as follow:
+	 *
+	 * "[...] if a device has only one ring/strip, use status_led0_select;
+	 *  otherwise the left ring/strip is controlled by status_led1_select
+	 *  and the right ring/strip by status_led0_select."
+	 *
+	 * http://sourceforge.net/mailarchive/message.php?msg_id=29898591
+	 */
+
+	num_rings = libwacom_get_num_rings (device);
+	num_strips = libwacom_get_num_strips (device);
+
+	if (((num_rings == 1) && (device->buttons[index] & WACOM_BUTTON_RING_MODESWITCH)) ||
+	    ((num_rings == 2) && (device->buttons[index] & WACOM_BUTTON_RING2_MODESWITCH)))
+		return 0;
+
+	if (((num_strips == 1) && (device->buttons[index] & WACOM_BUTTON_TOUCHSTRIP_MODESWITCH)) ||
+	    ((num_strips == 2) && (device->buttons[index] & WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH)))
+		return 0;
+
+	if (((num_rings == 2) && (device->buttons[index] & WACOM_BUTTON_RING_MODESWITCH)) ||
+	    ((num_strips == 2) && (device->buttons[index] & WACOM_BUTTON_TOUCHSTRIP_MODESWITCH)))
+		return 1;
+
+	return -1;
+}
+
 int libwacom_is_builtin(WacomDevice *device)
 {
 	return !!(device->features & FEATURE_BUILTIN);
diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h
index f7e6cf9..85a53ef 100644
--- a/libwacom/libwacom.h
+++ b/libwacom/libwacom.h
@@ -159,6 +159,7 @@ typedef enum {
 	WACOM_BUTTON_TOUCHSTRIP_MODESWITCH  = (1 << 7),
 	WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH = (1 << 8),
 	WACOM_BUTTON_OLED                   = (1 << 9),
+	WACOM_BUTTON_MODESWITCH_LED         = (1 << 10),
 	WACOM_BUTTON_MODESWITCH             = (WACOM_BUTTON_RING_MODESWITCH | WACOM_BUTTON_RING2_MODESWITCH | WACOM_BUTTON_TOUCHSTRIP_MODESWITCH | WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH),
 	WACOM_BUTTON_DIRECTION              = (WACOM_BUTTON_POSITION_LEFT | WACOM_BUTTON_POSITION_RIGHT | WACOM_BUTTON_POSITION_TOP | WACOM_BUTTON_POSITION_BOTTOM),
 	WACOM_BUTTON_RINGS_MODESWITCH       = (WACOM_BUTTON_RING_MODESWITCH | WACOM_BUTTON_RING2_MODESWITCH),
@@ -395,6 +396,12 @@ const int *libwacom_get_supported_styli(WacomDevice *device, int *num_styli);
 
 /**
  * @param device The tablet to query
+ * @return the number of touch rings on the tablet
+ */
+int libwacom_get_num_rings(WacomDevice *device);
+
+/**
+ * @param device The tablet to query
  * @return non-zero if the device has a touch ring or zero otherwise
  */
 int libwacom_has_ring(WacomDevice *device);
@@ -432,6 +439,15 @@ int libwacom_get_strips_num_modes(WacomDevice *device);
 
 /**
  * @param device The tablet to query
+ * @param button The ID of the button to check for, between 'A' and 'Z'
+ * @return the modeswitch LED group id to use
+ * or -1 if no LED is available for the given tablet / modeswitch button
+ */
+int libwacom_get_modeswitch_led_group (WacomDevice *device,
+				       char         button);
+
+/**
+ * @param device The tablet to query
  * @return non-zero if the device is built-in or zero if the device is an
  * external tablet
  */
-- 
1.7.1

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to