From 66576abb43c24a74f2d616e5c2d0764f35a57afc Mon Sep 17 00:00:00 2001
From: Ingo Ruhnke <grumbel@gmx.de>
Date: Sat, 29 Jan 2011 02:10:35 +0100
Subject: [PATCH] Added support for Playstation button names

---
 NEWS            |  2 ++
 TODO            | 64 +++++++++++++------------------------------------
 src/xboxmsg.cpp | 44 +++++++++++++++++-----------------
 3 files changed, 41 insertions(+), 69 deletions(-)

diff --git a/NEWS b/NEWS
index 2ca3b3c..780829e 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ xboxdrv 0.7.1 - (??/???/2011)
 * fixed assertion in relative axis filter
 * fixed --dpad-as-button
 * fixed --dpad-only
+* added support for Playstation button names (triangle,
+  circle, square, cross, L1, L2, L3, R1, R2, R3)
 
 
 xboxdrv 0.7.0 - (28/Jan/2011)
diff --git a/TODO b/TODO
index 0e63d06..0830e95 100644
--- a/TODO
+++ b/TODO
@@ -42,18 +42,20 @@ $ dput my-ppa ../xboxdrv_0.7.1-1~lucid1_source.changes
 Stuff to do before 0.7.1 release:
 =================================
 
-* implement set_dpad_as_button(), set_dpad_only()
+* add option to increase libusb debug level
 
-* --name DEVNAME must work with multple controller slots and multiple
-    devices, also allow a way to rename mouse and keyboard emulation devices
+* document --device-name TYPE.SLOT=NAME, --name
 
-    turn --name into --ui-name SLOT=foo
+* add --device-usbid TYPE.SLOT=VENDOR:PRODUCT:VERSION
 
-  --ui-name 1=MouseEmulation:0500:0500,2=Keyboard,mouse=Mouse
-  --ui-name 1=MouseEmulation,2=Keyboard,mouse=Mouse
-  --ui-vendor =
-  --ui-product 
-  --ui-bcdversion
+* fix device name of mimic_xpad
+
+* boost::lexical_cast<> error messages are useless, make some better ones
+
+* allow multiple controllers in non-daemon mode
+
+* couldn't convert 'XK_Page_Up' to enum, not a member of X11Keysym
+  currenty code can't handle multple names for a single key
 
 * document match rules
 
@@ -64,38 +66,6 @@ Stuff to do before 0.7.1 release:
 
 * update debian package description
 
-* need magic to assign controller to a slot:
- 
-  what:  match product/vendor-id, match device name
-  where: match USB path, match /dev/input/??? path
-  when:  just assign them to the next free slot
-
-  --match RULE,...       # match any of the given rules
-  --match-group RULE,... # match all of the given rules
-
-  Rules:
-  ======
-  usbpath=005:003 (implicit vendor/product match)
-  usbid=045f:028f
-  evdev=/dev/input/event5
-  (no rules means it always matches)
-
-  1) search for match
-  2) if no match is found search slots without rules
-
-  * matching by usbpath makes very little sense, as the dev argument
-    gets incremented with each replug, bus alone might be usable
-  
-  * match again sysname could make sense, seems somewhat constant: "5-2"
-    Xbox1 controller results in "5-2.1", due to being really two devices
-
-  * redesign match rules and only use single argument? would make
-    match group more logical:
-
-    --match-group vendor=045f,product=028f
-
-* fix bugs that pop up
-
 * valgrind before release
 
 * allow named sections in INI files (start numbering at 0 or 1?):
@@ -107,17 +77,13 @@ Stuff to do before 0.7.1 release:
   [controller3/config1/modifier]
   [controller3/config2/modifier]
 
-* support for Playstation button names maybe? cross, triangle, circle, square, R3, L3, ...?
-
 * check how daemon reacts on suspend
+  - suspending the computer leads to LIBUSB_ERROR_IO, unplugging the
+    controller leads to LIBUSB_ERROR_OTHER
 
 * remember controllers that couldn't be used when all slots where full
   and use them when a slot got free
 
-* figure out a good place to set the LEDs off when Xboxdrv is quit,
-  just doing it in the destructor causes trouble, as the usbdev might
-  be no longer usable (when controller got unplugged)
-
 * implement --on-connect and --on-disconnect for the daemon
   - maybe have a more general event interface that allows to run stuff
     on configuration changes, controller plug-ins, etc. (notifiy area as example)
@@ -127,6 +93,10 @@ Stuff to do before 0.7.1 release:
 Stuff to do before 0.7.2 release:
 =================================
 
+* --match again sysname could make sense, seems somewhat constant:
+  "5-2" Xbox1 controller results in "5-2.1", due to being really two
+  devices, would help to now how exactly those are formed
+
 * --four-way-restrictor for the dpad?
 
   - keep whatever direction is pressed first, don't allow walking over diagonals?
diff --git a/src/xboxmsg.cpp b/src/xboxmsg.cpp
index 9567088..b8be05a 100644
--- a/src/xboxmsg.cpp
+++ b/src/xboxmsg.cpp
@@ -1239,33 +1239,33 @@ XboxButton string2btn(const std::string& str_)
 
   if (str == "start")
     return XBOX_BTN_START;
-  else if (str == "guide")
+  else if (str == "guide" || str == "ps")
     return XBOX_BTN_GUIDE;
-  else if (str == "back")
+  else if (str == "back" || str == "select")
     return XBOX_BTN_BACK;
 
-  else if (str == "a" || str == "1" || str == "green")
+  else if (str == "a" || str == "1" || str == "green" || str == "cross")
     return XBOX_BTN_A;
-  else if (str == "b" || str == "2" || str == "red")
+  else if (str == "b" || str == "2" || str == "red" || str == "circle")
     return XBOX_BTN_B;
-  else if (str == "x" || str == "3" || str == "blue")
+  else if (str == "x" || str == "3" || str == "blue" || str == "square")
     return XBOX_BTN_X;
-  else if (str == "y" || str == "4" || str == "yellow")
+  else if (str == "y" || str == "4" || str == "yellow" || str == "triangle")
     return XBOX_BTN_Y;
 
-  else if (str == "lb" || str == "5" || str == "orange" || str == "white")
+  else if (str == "lb" || str == "5" || str == "orange" || str == "white" || str == "l1")
     return XBOX_BTN_LB;
-  else if (str == "rb" || str == "6" || str == "black")
+  else if (str == "rb" || str == "6" || str == "black" || str == "r1")
     return XBOX_BTN_RB;
 
-  else if (str == "lt" || str == "7")
+  else if (str == "lt" || str == "7" || str == "l2")
     return XBOX_BTN_LT;
-  else if (str == "rt" || str == "8")
+  else if (str == "rt" || str == "8" || str == "r2")
     return XBOX_BTN_RT;
 
-  else if (str == "tl")
+  else if (str == "tl" || str == "l3")
     return XBOX_BTN_THUMB_L;
-  else if (str == "tr")
+  else if (str == "tr" || str == "r3")
     return XBOX_BTN_THUMB_R;
 
   else if (str == "du" || str == "up")
@@ -1294,9 +1294,9 @@ XboxAxis string2axis(const std::string& str_)
   else if (str == "y2" || str == "tilt")
     return XBOX_AXIS_Y2;
   
-  else if (str == "lt")
+  else if (str == "lt" || str == "l2")
     return XBOX_AXIS_LT;
-  else if (str == "rt")
+  else if (str == "rt" || str == "r2")
     return XBOX_AXIS_RT;
 
   else if (str == "dpad_x")
@@ -1307,24 +1307,24 @@ XboxAxis string2axis(const std::string& str_)
   else if (str == "trigger" || str == "z" || str == "rudder")
     return XBOX_AXIS_TRIGGER;
 
-  else if (str == "btn_a")
+  else if (str == "btn_a" || str == "cross")
     return XBOX_AXIS_A;
 
-  else if (str == "btn_b")
+  else if (str == "btn_b" || str == "circle")
     return XBOX_AXIS_B;
 
-  else if (str == "btn_x")
+  else if (str == "btn_x" || str == "square")
     return XBOX_AXIS_X;
 
-  else if (str == "btn_y")
+  else if (str == "btn_y" || str == "triangle")
     return XBOX_AXIS_Y;
 
-  else if (str == "black")
-    return XBOX_AXIS_BLACK;
-
-  else if (str == "white")
+  else if (str == "white" || str == "lb"|| str == "l1")
     return XBOX_AXIS_WHITE;
 
+  else if (str == "black" || str == "rb" || str == "r1")
+    return XBOX_AXIS_BLACK;
+
   else
     return XBOX_AXIS_UNKNOWN;
 }