Deadalus
|
00001 // This program is free software: you can redistribute it and/or modify 00002 // it under the terms of the GNU General Public License as published by 00003 // the Free Software Foundation, either version 3 of the License, or 00004 // (at your option) any later version. 00005 // 00006 // This program is distributed in the hope that it will be useful, 00007 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00008 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00009 // GNU General Public License for more details. 00010 // 00011 // You should have received a copy of the GNU General Public License 00012 // along with this program. If not, see <http://www.gnu.org/licenses/> 00013 00014 #ifndef __JOYSTICK_HH__ 00015 #define __JOYSTICK_HH__ 00016 00017 #include <string> 00018 00019 #define JS_EVENT_BUTTON 0x01 // button pressed/released 00020 #define JS_EVENT_AXIS 0x02 // joystick moved 00021 #define JS_EVENT_INIT 0x80 // initial state of device 00022 00023 00025 00026 class JoystickEvent 00027 { 00028 public: 00029 unsigned int time; 00030 00031 short value; 00032 00033 00034 00035 unsigned char type; 00036 00037 unsigned char number; 00038 00040 bool isButton() 00041 { 00042 return (type & JS_EVENT_BUTTON) != 0; 00043 } 00044 00046 bool isAxis() 00047 { 00048 return (type & JS_EVENT_AXIS) != 0; 00049 } 00050 00053 bool isInitialState() 00054 { 00055 return (type & JS_EVENT_INIT) != 0; 00056 } 00057 }; 00058 00060 class Joystick 00061 { 00062 private: 00063 void openPath(std::string devicePath); 00064 00065 int _fd; 00066 00067 public: 00068 ~Joystick(); 00069 00071 Joystick(); 00072 00075 Joystick(int joystickNumber); 00076 00078 Joystick(std::string devicePath); 00079 00081 bool isFound(); 00082 00085 bool sample(JoystickEvent* event); 00086 }; 00087 00088 #endif