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 <utility>
11 #include <vector>
12 
13 // QT headers
14 #include <QString>
15 
16 // MythTV headers
17 #include "mthread.h"
18 
20 {
21  int button;
22  QString keystring;
23  int chord;
24 };
25 
27 {
28  int axis;
29  int from;
30  int to;
31  QString keystring;
32 };
33 
52 {
53  public:
54  void AddButton(int in_button, QString in_keystr, int in_chord = -1)
55  {
56  buttonMapType new_button = { in_button, std::move(in_keystr), in_chord };
57  m_buttonMap.push_back(new_button);
58  }
59 
60  void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
61  {
62  axisMapType new_axis = { in_axis, in_from, in_to, std::move(in_keystr)};
63  m_axisMap.push_back(new_axis);
64  }
65 
66  using button_map_t = std::vector<buttonMapType>;
67  using axis_map_t = std::vector<axisMapType>;
68  const button_map_t &buttonMap() const { return m_buttonMap; }
69  const axis_map_t &axisMap() const { return m_axisMap; }
70 
73 };
74 
83 {
84  public:
85  explicit JoystickMenuThread(QObject *main_window)
86  : MThread("JoystickMenu"), m_mainWindow(main_window) {}
87  ~JoystickMenuThread() override;
88  bool Init(QString &config_file);
89 
90  void ButtonUp(int button);
91  void AxisChange(int axis, int value);
92  void EmitKey(const QString& code);
93  bool ReadConfig(const QString& config_file);
94  void Stop(void) { m_bStop = true; }
95 
96  private:
97  void run() override; // MThread
98 
99  QObject *m_mainWindow {nullptr};
100  QString m_devicename;
101  int m_fd {-1};
103 
108  unsigned char m_buttonCount {0};
109 
114  unsigned char m_axesCount {0};
115 
116  int *m_buttons {nullptr};
117  int *m_axes {nullptr};
118 
119  volatile bool m_bStop {false};
120 };
121 
122 #endif
unsigned char m_buttonCount
Track the status of the joystick buttons as we do depend slightly on state.
Definition: jsmenu.h:108
axis_map_t m_axisMap
Definition: jsmenu.h:72
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:297
unsigned char m_axesCount
Track the status of the joystick axes as we do depend slightly on state.
Definition: jsmenu.h:114
int from
Definition: jsmenu.h:29
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:200
QString keystring
Definition: jsmenu.h:22
std::vector< buttonMapType > button_map_t
Definition: jsmenu.h:66
void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
Definition: jsmenu.h:60
QObject * m_mainWindow
Definition: jsmenu.h:99
std::vector< axisMapType > axis_map_t
Definition: jsmenu.h:67
int button
Definition: jsmenu.h:21
int chord
Definition: jsmenu.h:23
int to
Definition: jsmenu.h:30
QString m_devicename
Definition: jsmenu.h:100
int axis
Definition: jsmenu.h:28
button_map_t m_buttonMap
Definition: jsmenu.h:71
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:69
void ButtonUp(int button)
Handle a button up event.
Definition: jsmenu.cpp:328
volatile bool m_bStop
Definition: jsmenu.h:119
void AddButton(int in_button, QString in_keystr, int in_chord=-1)
Definition: jsmenu.h:54
QString keystring
Definition: jsmenu.h:31
JoystickMap m_map
Definition: jsmenu.h:102
~JoystickMenuThread() override
Definition: jsmenu.cpp:54
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:85
Main object for injecting key strokes based on joystick movements.
Definition: jsmenu.h:82
void Stop(void)
Definition: jsmenu.h:94
void AxisChange(int axis, int value)
Handle a registered change in a joystick axis.
Definition: jsmenu.cpp:360
Holds the buttonMapType and axisMapType structs which map actions to events.
Definition: jsmenu.h:51
const button_map_t & buttonMap() const
Definition: jsmenu.h:68