You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1KB

  1. /* JoystickPlugin
  2. * Copyleft (C) 2002 William Bland <wjb@abstractnonsense.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "../SpiralPlugin.h"
  19. #include <linux/joystick.h>
  20. #include <FL/Fl_Pixmap.H>
  21. #ifndef JoystickPLUGIN
  22. #define JoystickPLUGIN
  23. #define JP_NUMBER_OF_AXES 3
  24. #define JP_NUMBER_OF_BUTTONS 3
  25. class LowLevelJoystick
  26. {
  27. public:
  28. static LowLevelJoystick *Get() { if(!m_Singleton) m_Singleton=new LowLevelJoystick; return m_Singleton; }
  29. static void PackUpAndGoHome() { if(m_Singleton) { delete m_Singleton; m_Singleton=NULL; } }
  30. ~LowLevelJoystick();
  31. void Read();
  32. void OpenRead();
  33. void Close();
  34. float GetJoystickAxis( int );
  35. float GetJoystickButton( int );
  36. bool m_invert_axis[JP_NUMBER_OF_AXES];
  37. private:
  38. static LowLevelJoystick* m_Singleton;
  39. LowLevelJoystick();
  40. float m_button[JP_NUMBER_OF_BUTTONS];
  41. float m_axis[JP_NUMBER_OF_AXES];
  42. int m_Joyfd;
  43. bool m_InputOk;
  44. };
  45. class JoystickPlugin : public SpiralPlugin
  46. {
  47. public:
  48. JoystickPlugin();
  49. virtual ~JoystickPlugin();
  50. virtual PluginInfo& Initialise(const HostInfo *Host);
  51. virtual SpiralGUIType* CreateGUI();
  52. virtual void Execute();
  53. virtual void StreamOut(ostream &s) {}
  54. virtual void StreamIn(istream &s) {}
  55. // has to be defined in the plugin
  56. virtual void UpdateGUI() { Fl::check(); }
  57. private:
  58. static int m_RefCount;
  59. static int m_NoExecuted;
  60. float m_last_axis[JP_NUMBER_OF_AXES];
  61. };
  62. #endif