MythTV  master
jsmenu.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------
2 ** jsmenu.h
3 ** GPL license; Original copyright 2004 Jeremy White <jwhite@whitesen.org>
4 **--------------------------------------------------------------------------*/
5 
6 #ifndef JSMENU_H_
7 #define JSMENU_H_
8 
9 // C++ headers
10 #include <vector>
11 
12 // QT headers
13 #include <QString>
14 
15 // MythTV headers
16 #include "mthread.h"
17 
18 typedef struct
19 {
20  int button;
21  QString keystring;
22  int chord;
24 
25 typedef struct
26 {
27  int axis;
28  int from;
29  int to;
30  QString keystring;
31 } axisMapType;
32 
51 {
52  public:
53  void AddButton(int in_button, QString in_keystr, int in_chord = -1)
54  {
55  buttonMapType new_button = { in_button, in_keystr, in_chord };
56  m_buttonMap.push_back(new_button);
57  }
58 
59  void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
60  {
61  axisMapType new_axis = { in_axis, in_from, in_to, in_keystr};
62  m_axisMap.push_back(new_axis);
63  }
64 
65  typedef std::vector<buttonMapType> button_map_t;
66  typedef std::vector<axisMapType> axis_map_t;
67  const button_map_t &buttonMap() const { return m_buttonMap; }
68  const axis_map_t &axisMap() const { return m_axisMap; }
69 
72 };
73 
82 {
83  public:
84  explicit JoystickMenuThread(QObject *main_window)
85  : MThread("JoystickMenu"), m_mainWindow(main_window) {}
87  bool Init(QString &config_file);
88 
89  void ButtonUp(int button);
90  void AxisChange(int axis, int value);
91  void EmitKey(const QString& code);
92  bool ReadConfig(const QString& config_file);
93  void Stop(void) { m_bStop = true; }
94 
95  private:
96  void run() override; // MThread
97 
98  QObject *m_mainWindow {nullptr};
99  QString m_devicename;
100  int m_fd {-1};
102 
107  unsigned char m_buttonCount {0};
108 
113  unsigned char m_axesCount {0};
114 
115  int *m_buttons {nullptr};
116  int *m_axes {nullptr};
117 
118  volatile bool m_bStop {false};
119 };
120 
121 #endif
unsigned char m_buttonCount
Track the status of the joystick buttons as we do depend slightly on state.
Definition: jsmenu.h:107
axis_map_t m_axisMap
Definition: jsmenu.h:71
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
void EmitKey(const QString &code)
Send a keyevent to the main UI loop with the appropriate keycode.
Definition: jsmenu.cpp:287
std::vector< axisMapType > axis_map_t
Definition: jsmenu.h:66
std::vector< buttonMapType > button_map_t
Definition: jsmenu.h:65
unsigned char m_axesCount
Track the status of the joystick axes as we do depend slightly on state.
Definition: jsmenu.h:113
int from
Definition: jsmenu.h:28
void run() override
This function is the heart of a thread which looks for Joystick input and translates it into key pres...
Definition: jsmenu.cpp:190
QString keystring
Definition: jsmenu.h:21
void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
Definition: jsmenu.h:59
QObject * m_mainWindow
Definition: jsmenu.h:98
int button
Definition: jsmenu.h:20
int chord
Definition: jsmenu.h:22
int to
Definition: jsmenu.h:29
QString m_devicename
Definition: jsmenu.h:99
int axis
Definition: jsmenu.h:27
button_map_t m_buttonMap
Definition: jsmenu.h:70
bool Init(QString &config_file)
Initialise the class variables with values from the config file.
Definition: jsmenu.cpp:72
const axis_map_t & axisMap() const
Definition: jsmenu.h:68
void ButtonUp(int button)
Handle a button up event.
Definition: jsmenu.cpp:318
volatile bool m_bStop
Definition: jsmenu.h:118
void AddButton(int in_button, QString in_keystr, int in_chord=-1)
Definition: jsmenu.h:53
QString keystring
Definition: jsmenu.h:30
JoystickMap m_map
Definition: jsmenu.h:101
bool ReadConfig(const QString &config_file)
Read from action to key mappings from flat file config file.
Definition: jsmenu.cpp:136
JoystickMenuThread(QObject *main_window)
Definition: jsmenu.h:84
Main object for injecting key strokes based on joystick movements.
Definition: jsmenu.h:81
void Stop(void)
Definition: jsmenu.h:93
void AxisChange(int axis, int value)
Handle a registered change in a joystick axis.
Definition: jsmenu.cpp:350
Holds the buttonMapType and axisMapType structs which map actions to events.
Definition: jsmenu.h:50
const button_map_t & buttonMap() const
Definition: jsmenu.h:67