00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef header_joystick_linux
00021 #define header_joystick_linux
00022 #ifdef USE_JOY
00023
00024
00025 #include <linux/version.h>
00026
00027 #ifndef KERNEL_VERSION
00028 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
00029 #endif
00030
00031 #ifndef LINUX_VERSION_CODE
00032 #error "You need to use at least 2.0 Linux kernel."
00033 #endif
00034
00035 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
00036
00037
00038 #include "API/Display/Input/inputdevice.h"
00039 #include "API/Display/Input/inputaxis.h"
00040 #include "API/Core/System/keep_alive.h"
00041 #include "Core/System/Unix/init_linux.h"
00042
00043
00044
00045 #include <linux/joystick.h>
00046
00047
00048
00049 class CL_LinuxJoystick_Axis;
00050 class CL_LinuxJoystick_Button;
00051
00052 class CL_LinuxJoystick : public CL_InputDevice, CL_KeepAlive
00053 {
00054 public:
00055 CL_LinuxJoystick();
00056 virtual ~CL_LinuxJoystick();
00057 bool init(int number = 0);
00058
00059
00060
00061
00062 virtual char *get_name() const { return "Linux Joystick"; }
00063
00064 virtual int get_num_axes() const { return num_axes; }
00065 virtual CL_InputAxis *get_axis(int num);
00066
00067 virtual int get_num_buttons() const { return num_buttons; }
00068 virtual CL_InputButton *get_button(int num);
00069
00070 virtual int get_num_hats() const { return 0; }
00071 virtual CL_InputHat *get_hat(int) { return NULL; }
00072
00073 virtual int get_num_buffers() const { return 0; }
00074 virtual CL_InputBuffer *get_buffer(int) { return NULL; }
00075
00076 virtual int get_num_cursors() const { return 0; }
00077 virtual CL_InputCursor *get_cursor(int) { return NULL; }
00078
00079
00080
00081 virtual void keep_alive();
00082 private:
00083
00084 int fd;
00085
00086 int num_buttons;
00087 int num_axes;
00088
00089 js_event jev;
00090
00091 CL_LinuxJoystick_Axis *axes;
00092 CL_LinuxJoystick_Button *buttons;
00093 };
00094
00095 class CL_LinuxJoystick_Axis : public CL_InputAxis
00096 {
00097 public:
00098 CL_LinuxJoystick_Axis() { value = 0; }
00099
00100 virtual float get_pos() { return value/(float) 32768; }
00101 void set_value(int v) { value = v; }
00102 private:
00103 int value;
00104 };
00105
00106 class CL_LinuxJoystick_Button : public CL_InputButton
00107 {
00108 public:
00109 CL_LinuxJoystick_Button() { value = 0; }
00110
00111 virtual bool is_pressed() { if (value) return true; return false; }
00112 void set_value(int v) { value = v; }
00113 private:
00114 int value;
00115 };
00116
00117 #endif
00118
00119 #endif
00120 #endif