[gnome-bluetooth] wizard: Add support for pairing the iCade



commit 823dd92109e0b664999de95b3952b1e5120e82f0
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jan 19 20:31:58 2012 +0000

    wizard: Add support for pairing the iCade
    
    Instead of expecting the user to convert every digit of the PIN
    to joystick moves and button presses, only require joystick movements
    and show them as arrows.

 wizard/main.c                |   47 ++++++++++++++++++++++++++++++++++++++---
 wizard/pin-code-database.xml |    3 ++
 2 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/wizard/main.c b/wizard/main.c
index 5ffc2e0..c99caac 100644
--- a/wizard/main.c
+++ b/wizard/main.c
@@ -57,7 +57,8 @@ enum {
 
 typedef enum {
 	PAIRING_UI_NORMAL,
-	PAIRING_UI_KEYBOARD
+	PAIRING_UI_KEYBOARD,
+	PAIRING_UI_ICADE
 } PairingUIBehaviour;
 
 static gboolean set_page_search_complete(void);
@@ -143,7 +144,7 @@ set_large_label (GtkLabel *label, const char *text)
 	g_free(str);
 }
 
-static gchar* 
+static char *
 get_random_pincode (guint num_digits)
 {
 	if (num_digits == 0)
@@ -152,6 +153,39 @@ get_random_pincode (guint num_digits)
 							  pow (10, num_digits)));
 }
 
+static char *
+get_icade_pincode (char **pin_display_str)
+{
+	GString *pin, *pin_display;
+	guint i;
+	static char *arrows[] = {
+		NULL,
+		"â", /* up = 1    */
+		"â", /* down = 2  */
+		"â", /* left = 3  */
+		"â"  /* right = 4 */
+	};
+
+	pin = g_string_new (NULL);
+	pin_display = g_string_new (NULL);
+
+	for (i = 0; i < PIN_NUM_DIGITS; i++) {
+		int r;
+		char *c;
+
+		r = g_random_int_range (1, 4);
+
+		c = g_strdup_printf ("%d", r);
+		g_string_append (pin, c);
+		g_free (c);
+
+		g_string_append (pin_display, arrows[r]);
+	}
+
+	*pin_display_str = g_string_free (pin_display, FALSE);
+	return g_string_free (pin, FALSE);
+}
+
 static gboolean
 pincode_callback (GDBusMethodInvocation *invocation,
 		  GDBusProxy *device,
@@ -488,6 +522,10 @@ void prepare_callback (GtkWidget *assistant,
 				pincode = get_random_pincode (target_max_digits);
 				pincode_display = g_strdup_printf ("%sâ", pincode);
 				break;
+			case PAIRING_UI_ICADE:
+				help = g_strdup (_("Please move the joystick of your iCade in the following directions:"));
+				pincode = get_icade_pincode (&pincode_display);
+				break;
 			}
 
 			if (pincode == NULL)
@@ -713,9 +751,10 @@ select_device_changed (BluetoothChooser *selector,
 	user_pincode = get_pincode_for_device (target_type, target_address, target_name, &target_max_digits);
 	if (user_pincode != NULL &&
 	    g_str_equal (user_pincode, "NULL") == FALSE) {
-		if (g_str_equal (user_pincode, "KEYBOARD")) {
+		if (g_str_equal (user_pincode, "KEYBOARD"))
 			target_ui_behaviour = PAIRING_UI_KEYBOARD;
-		}
+		else if (g_str_equal (user_pincode, "ICADE"));
+			target_ui_behaviour = PAIRING_UI_ICADE;
 		g_free (user_pincode);
 		user_pincode = NULL;
 	}
diff --git a/wizard/pin-code-database.xml b/wizard/pin-code-database.xml
index ed442f9..354a08c 100644
--- a/wizard/pin-code-database.xml
+++ b/wizard/pin-code-database.xml
@@ -76,6 +76,9 @@
 	<!-- Lenovo Ideacenter remote -->
 	<device oui="00:08:1B:" name="lenovo_RC" pin="0000"/>
 
+	<!-- ION iCade Game Controller -->
+	<device oui="00:12:A1:" name="ION iCade Game Controller" type="keyboard" pin="ICADE"/>
+
 <!-- GPS devices -->
 	<device oui="00:0D:B5:" name="TomTom Wireless GPS MkII" pin="0000"/>
 	<device oui="00:0D:B5:" name="GPS-GW-005" pin="0000"/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]