[PATCH 4/5] programs/joystick: Added command line parameter to chose joystick used

Lucas Fialho Zawacki lfzawacki at gmail.com
Fri May 18 08:50:49 CDT 2012


From: Lucas Fialho Zawacki <lfzawacki at gmail.com>

---
 programs/joystick/main.c |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/programs/joystick/main.c b/programs/joystick/main.c
index 5cf6266..e709dec 100644
--- a/programs/joystick/main.c
+++ b/programs/joystick/main.c
@@ -42,6 +42,7 @@ struct JoystickData {
     struct Joystick *joysticks;
     int num_joysticks;
     int cur_joystick;
+    int chosen_joystick;
     int poll_time;
     int axes_max;
     int axes_min;
@@ -189,8 +190,8 @@ static void WaitForInput(const struct JoystickData* data, int chosen)
 static void ProcessCmdLine(struct JoystickData *params, LPSTR lpCmdLine)
 {
     int i, j, buffer_index;
-    /* Options are { 'poll', 'max-range', 'min-range' } */
-    char options[] = { 'p', 'a', 'i' };
+    /* Options are { 'poll', 'max-range', 'min-range', 'joystick chosen' } */
+    char options[] = { 'p', 'a', 'i', 'j' };
     char buffer[32];
     char command;
 
@@ -240,6 +241,11 @@ static void ProcessCmdLine(struct JoystickData *params, LPSTR lpCmdLine)
                     if (strlen(buffer) == 0) goto invalid;
                     params->axes_min = atoi(buffer);
                 break;
+
+                case 'j':
+                    if (strlen(buffer) == 0) goto invalid;
+                    params->chosen_joystick = atoi(buffer);
+                break;
             }
         }
     }
@@ -255,8 +261,8 @@ static void ProcessCmdLine(struct JoystickData *params, LPSTR lpCmdLine)
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
 {
     /* Structure with the data and settings for the application */
-    /* data is: lpdi, joy[], num_joy, cur_joy, poll_time, axes_max, axes_min */
-    struct JoystickData data = { NULL, NULL, 0, 0, 0, 1000, -1000 };
+    /* data is: lpdi, joy[], num_joy, cur_joy, chosen_joystick, poll_time, axes_max, axes_min */
+    struct JoystickData data = { NULL, NULL, 0, 0, 0, 0, 1000, -1000 };
     HRESULT hr;
 
     /* Get settings from the command line */
@@ -297,8 +303,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nS
         /* If we'll poll the joystick for input */
         if (data.num_joysticks > 0) {
 
-            /* Use the first joystick */
-            WaitForInput(&data, 0);
+            if (data.chosen_joystick >= data.num_joysticks || data.chosen_joystick < 0) {
+                printf("Joystick '%d' is not connected\n", data.chosen_joystick);
+                return 1;
+            }
+
+            WaitForInput(&data, data.chosen_joystick);
         }
     }
 
-- 
1.7.9.5




More information about the wine-patches mailing list