Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _JOYSTICKREADER_H
00012 #define _JOYSTICKREADER_H
00013
00014 #ifdef __linux__
00015 #include <boost/thread/mutex.hpp>
00016 #include <boost/thread.hpp>
00017 #include<linux/joystick.h>
00018 #include <fstream>
00019 #endif
00020
00021 #ifdef WIN32
00022 #include <Windows.h>
00023 #include <basetsd.h>
00024 #include <dinput.h>
00025 #endif
00026
00027 #include <labust/xml/xmlfwd.hpp>
00028 #include <iostream>
00029 #include <boost/noncopyable.hpp>
00030 #include <vector>
00031
00032 namespace LABUST
00033 {
00038
00039 struct JoystickData
00040 {
00041 std::vector<short> axes;
00042 std::vector<bool> buttons;
00043 };
00044
00050
00051 class JoystickReader : private boost::noncopyable
00052 {
00053 public:
00054
00055
00056
00057
00058
00059 JoystickReader(const std::string& path, std::string configToUse = "");
00060
00061
00062
00063
00064
00065
00066 JoystickReader(const labust::xml::Reader& reader, std::string configToUse = "");
00067 virtual ~JoystickReader();
00068
00069
00070
00071
00072
00073
00074 JoystickData ReadJoystickData();
00075
00076 #ifdef WIN32
00077 BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* instance, VOID* context);
00078 #endif
00079 private:
00080 int deviceDescriptor;
00081 int axes, buttons;
00082 JoystickData joystickData;
00083 std::vector<float> axisGains;
00084
00085 #ifdef __linux__
00086
00087 boost::mutex joystickMutex;
00088 boost::thread joystickThread;
00089 bool running;
00090
00091 void ThreadFunction();
00092 #endif
00093
00094 #ifdef WIN32
00095 LPDIRECTINPUT8 di;
00096 LPDIRECTINPUTDEVICE8 joystick;
00097 #endif
00098
00099 int deviceCounter;
00100 };
00101 #ifdef WIN32
00102 BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* instance, VOID* context);
00103 #endif
00104 }
00105
00106 #endif
00107