00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00032 #ifndef _CLASS_GAMEPAD_H_ 00033 #define _CLASS_GAMEPAD_H_ 00034 00035 #include <linux/joystick.h> 00036 #include <unistd.h> 00037 #include <stdio.h> 00038 #include <stdlib.h> 00039 #include <signal.h> 00040 #include <string.h> 00041 #include <fcntl.h> 00042 00043 class class_gamepad 00044 { 00045 public: 00046 00047 typedef enum {AXIS,BUTTON} e_type; 00048 00052 class_gamepad(); 00053 00057 ~class_gamepad(); 00058 00064 int StartComm(const char*device); 00065 00073 int RegisterCallback(e_type type,int id,void (*callback)(int value,void*data),void*data); 00074 int UnRegisterCallback(e_type type,int id); 00075 00081 int Dispatch(bool debug=false); 00082 int CloseComm(void); 00083 00090 void plerr(int ret); 00091 private: 00092 00093 typedef struct 00094 { 00095 int value; 00096 void *userdata; 00097 void (*callback)(int value,void*data); 00098 }t_button; 00099 00104 int GetButtonMapping(void); 00105 00110 int SetButtonMapping(void); 00111 00112 int ret; 00113 int fd; 00114 int n_buttons; 00115 int n_axes; 00116 t_button*buttons; 00117 t_button*axes; 00118 00119 __u8 m_axes[ABS_CNT]; 00120 __u16 m_buttons[KEY_MAX - BTN_MISC + 1]; 00121 00122 char name[1024]; 00123 char err[1024]; 00124 char text[1024]; 00125 }; 00126 00127 #endif