Joystick.h
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2024 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 // NOTE: This file is borrowed from mrpt-hwdrivers (BSD-3 License)
11 
12 /* +------------------------------------------------------------------------+
13  | Mobile Robot Programming Toolkit (MRPT) |
14  | https://www.mrpt.org/ |
15  | |
16  | Copyright (c) 2005-2024, Individual contributors, see AUTHORS file |
17  | See: https://www.mrpt.org/Authors - All rights reserved. |
18  | Released under BSD License. See: https://www.mrpt.org/License |
19  +------------------------------------------------------------------------+ */
20 #pragma once
21 
22 #include <mrpt/config.h>
23 
24 #include <vector>
25 
26 /*---------------------------------------------------------------
27  Class
28  ---------------------------------------------------------------*/
29 namespace mvsim
30 {
39 class Joystick
40 {
41  private:
43  std::vector<int> m_minPerAxis, m_maxPerAxis;
44 
45 #if defined(MRPT_OS_LINUX)
46 
47  int m_joy_fd{-1};
49  int m_joy_index{-1};
52  std::vector<bool> m_joystate_btns;
55  std::vector<int> m_joystate_axes;
56 #endif
57 
58  public:
61  Joystick();
62 
65  virtual ~Joystick();
66 
69  static int getJoysticksCount();
70 
71  struct State
72  {
73  std::vector<bool> buttons;
74  std::vector<float> axes;
75  std::vector<int> axes_raw;
76  };
77 
103  bool getJoystickPosition(int nJoy, State& output);
104 
116  void setLimits(const std::vector<int>& minPerAxis, const std::vector<int>& maxPerAxis);
117 
118 }; // End of class def.
119 
120 } // namespace mvsim
mvsim
Definition: Client.h:21
mvsim::Joystick::m_maxPerAxis
std::vector< int > m_maxPerAxis
Definition: Joystick.h:43
mvsim::Joystick::State::buttons
std::vector< bool > buttons
Definition: Joystick.h:73
mvsim::Joystick::getJoystickPosition
bool getJoystickPosition(int nJoy, State &output)
Definition: Joystick.cpp:112
mvsim::Joystick::getJoysticksCount
static int getJoysticksCount()
Definition: Joystick.cpp:79
mvsim::Joystick::State
Definition: Joystick.h:71
mvsim::Joystick::State::axes
std::vector< float > axes
Definition: Joystick.h:74
mvsim::Joystick::State::axes_raw
std::vector< int > axes_raw
!< Normalized position values [0,1]
Definition: Joystick.h:75
mvsim::Joystick::Joystick
Joystick()
mvsim::Joystick::setLimits
void setLimits(const std::vector< int > &minPerAxis, const std::vector< int > &maxPerAxis)
Definition: Joystick.cpp:230
mvsim::Joystick
Definition: Joystick.h:39
mvsim::Joystick::~Joystick
virtual ~Joystick()
Definition: Joystick.cpp:63
mvsim::Joystick::m_minPerAxis
std::vector< int > m_minPerAxis
Definition: Joystick.h:43


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:08