class_gamepad.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
32 #ifndef _CLASS_GAMEPAD_H_
33 #define _CLASS_GAMEPAD_H_
34 
35 #include <linux/joystick.h>
36 #include <unistd.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <signal.h>
40 #include <string.h>
41 #include <fcntl.h>
42 
44 {
45  public:
46 
47  typedef enum {AXIS,BUTTON} e_type;
48 
52  class_gamepad();
53 
58 
64  int StartComm(const char*device);
65 
73  int RegisterCallback(e_type type,int id,void (*callback)(int value,void*data),void*data);
74  int UnRegisterCallback(e_type type,int id);
75 
81  int Dispatch(bool debug=false);
82  int CloseComm(void);
83 
90  void plerr(int ret);
91  private:
92 
93  typedef struct
94  {
95  int value;
96  void *userdata;
97  void (*callback)(int value,void*data);
98  }t_button;
99 
104  int GetButtonMapping(void);
105 
110  int SetButtonMapping(void);
111 
112  int ret;
113  int fd;
115  int n_axes;
118 
119  __u8 m_axes[ABS_CNT];
120  __u16 m_buttons[KEY_MAX - BTN_MISC + 1];
121 
122  char name[1024];
123  char err[1024];
124  char text[1024];
125 };
126 
127 #endif
t_button * axes
void plerr(int ret)
Print local error function This function prints the error present in the err variable (this is a priv...
int Dispatch(bool debug=false)
This function checks the gamepad status and calls the respective callback.
~class_gamepad()
Class destructor.
t_button * buttons
int CloseComm(void)
class_gamepad()
Class constructor.
int GetButtonMapping(void)
Get the button mapping from the device.
char text[1024]
int SetButtonMapping(void)
Set the button mapping to the device.
char err[1024]
int RegisterCallback(e_type type, int id, void(*callback)(int value, void *data), void *data)
Register a callback for a specific button or axis.
int UnRegisterCallback(e_type type, int id)
__u8 m_axes[ABS_CNT]
char name[1024]
int StartComm(const char *device)
Initialize comm with the gamepad.
__u16 m_buttons[KEY_MAX-BTN_MISC+1]


atlasmv_base
Author(s): David Gameiro, Jorge Almeida
autogenerated on Mon Mar 2 2015 01:31:28