JoystickReader.h
Go to the documentation of this file.
00001 /* 
00002  * File:   Joystick.h
00003  * Author: user
00004  *
00005  * Created on July 13, 2010, 12:04 PM
00006  * Tested and approoved on July 14, 2010, 12:00 PM
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          * Constructor, path based
00056          * \param path path to file with configuration labust::xml
00057          * \param configToUse name of configuration to use, optional - if empty, first one will be used
00058          */
00059         JoystickReader(const std::string& path, std::string configToUse = "");
00060 
00061         /*
00062          * Constructor, labust::xmlReader based
00063          * \param labust::xml reader with the preloaded config file
00064          * \param configToUse name of configuration to use, optional - if empty, first one will be used
00065          */
00066         JoystickReader(const labust::xml::Reader& reader, std::string configToUse = "");
00067         virtual ~JoystickReader();
00068 
00069         /*
00070          * Gets data about axes and buttons of the joystick
00071          *
00072          * \param data reference to data object to write data to
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         //std::fstream joystickPort;
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  /* _JOYSTICKREADER_H */
00107 


acoustic_vr
Author(s):
autogenerated on Fri Feb 7 2014 11:37:09