Kuon  1.1.3
RoadNarrows Robotics Large Outdoor Mobile Robot Project
360Controller.h
1 /*
2  Title: Header file for 360 controller handling
3  Authors: Rob Shiely & Robin Knight
4  Date: 10/12/2011
5 */
6 
7 #ifndef _360READ_H
8 #define _360READ_H
9 
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <sys/time.h>
13 #include <sys/ioctl.h>
14 #include "rnr/rnrconfig.h"
15 #include <limits.h>
16 #include <fcntl.h>
17 #include <termios.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <stdarg.h>
21 #include <time.h>
22 #include <libusb-1.0/libusb.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 #define ID_VENDOR 0x045e
27 #define ID_PRODUCT_WI 0x028e
28 #define ID_PRODUCT_WL 0x028f
29 #define ID_PRODUCT_WR 0x0291
30 #define NUMBER_OF_INTERFACES 3
31 #define ENDPOINT 0x81
32 #define LEFT_DEAD_ZONE 50
33 #define RIGHT_DEAD_ZONE 25
34 
35 C_DECLS_BEGIN
36 
37 typedef struct Control360 {
38  struct libusb_device_handle *USB_lockOn;
39  struct libusb_device *dev;
40  struct libusb_device_descriptor *desc;
41  struct libusb_transfer *Trans;
42 
43  int Pad_Up;
44  int Pad_Down;
45  int Pad_Left;
46  int Pad_Right;
47  int Left_Bump;
48  int Right_Bump;
49  int Start;
50  int Back;
51  int Left_Stick_Click;
52  int Right_Stick_Click;
53  int A_Button;
54  int B_Button;
55  int X_Button;
56  int Y_Button;
57  int Center_X;
58  int Left_X_Val;
59  int Left_Y_Val;
60  int Right_X_Val;
61  int Right_Y_Val;
62  int Left_Trig_Val;
63  int Right_Trig_Val;
64  int Controller_Connected;
65  int type;
66  int WorC;
67 } Control360_T;
68 
69 void debugController(Control360_T c);
70 
71 /*
72  Initialization function for XBox 360 Controller
73  defined by Vendor and Product IDs defined above
74 
75  Returns: 0 on success, -1 if unable to locate controller,
76  -2 if unable to claim all interfaces,
77  and -3 if unable to set up reading from controller.
78 */
79 int Init360Controller(struct Control360 *Controller);
80 
81 /*
82  Function to check the controller and update passed controller structure.
83 
84  Returns: 0 on successful update and < 0 on no-update or failure
85 */
86 int Update360ControllerValues();
87 
88 /*
89  Function to To get raw controller output buffer.
90  (also updates controller stucture)
91 
92  Returns: Length of transferred buffer on success and < 0 on failure.
93 */
94 int GetRaw360(unsigned char *TempBuff, int LeN);
95 
96 /*
97  Function to release all interfaces to the controller,
98  close controller, and exit from libusb.
99 
100  Returns: 0 on success and -1 on failure.
101 */
102 int Kill360Controller(struct Control360 *Controller);
103 C_DECLS_END
104 #endif