00001 #ifndef GameController_H 00002 #define GameController_H 00003 00004 00005 #include <string> 00006 #include <boost/dynamic_bitset.hpp> 00007 #include <pthread.h> 00008 #include <wds-debug.h> 00009 #include <map> 00010 00011 class GameController { 00012 public: 00013 GameController(const std::string &device = "/dev/input/js0"); 00014 ~GameController(); 00015 00016 const std::string &name() const {return m_name;} 00017 int numAxes() const {return m_axes;} 00018 int numButtons() const {return m_buttons;} 00019 00020 int axis(const int number) const {assert_range(number, 0, m_axes); return m_axis_data[number];} 00021 int axis(std::string name) { return axis(axisMap[name]);} 00022 bool button(const int number) const {assert_range(number, 0, m_buttons); return m_button_data[number];} 00023 bool button(std::string name ) { return button(buttonMap[name]);} 00024 00025 void setAxisMap(int,std::string); 00026 void setButtonMap(int,std::string); 00027 00028 //someone can implement these later 00029 /* std::string getAxisMapping(int); 00030 std::string getButtonMapping(int); 00031 */ 00032 // don't know what'll happen if the name doesn't exist; that's your 00033 // responsibility to check 00034 int getAxisMapping(std::string name){return axisMap[name];} 00035 int getButtonMapping(std::string name){return buttonMap[name];} 00036 00037 00038 00039 00040 private: 00041 int m_fd; 00042 00043 // Static information 00044 std::string m_name; 00045 int m_axes; 00046 int m_buttons; 00047 int m_driver_version; 00048 00049 // Data 00050 int *m_axis_data; 00051 boost::dynamic_bitset<> m_button_data; 00052 00053 // Thread stuff 00054 pthread_t m_read_thread; 00055 static void *readThread(void *ptr); 00056 00057 std::map<std::string,int> buttonMap; 00058 std::map<std::string,int> axisMap; 00059 00060 // Not allowed to use these 00061 GameController(const GameController &controller); 00062 GameController &operator=(const GameController &controller); 00063 }; 00064 00065 00066 #endif