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 "libmythbase/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  void Clear(){
67  m_axisMap.clear();
68  m_buttonMap.clear();
69  }
70 
71  using button_map_t = std::vector<buttonMapType>;
72  using axis_map_t = std::vector<axisMapType>;
73  const button_map_t &buttonMap() const { return m_buttonMap; }
74  const axis_map_t &axisMap() const { return m_axisMap; }
75 
78 };
79 
88 {
89  public:
90  explicit JoystickMenuThread(QObject *main_window)
91  : MThread("JoystickMenu"), m_mainWindow(main_window) {}
92  ~JoystickMenuThread() override;
93  bool Init(QString &config_file);
94 
95  void ButtonUp(int button);
96  void AxisChange(int axis, int value);
97  void EmitKey(const QString& code);
98  bool ReadConfig(const QString& config_file);
99  void Stop(void) { m_bStop = true; }
100 
101  private:
102  void run() override; // MThread
103 
104  bool m_configRead {false};
105  bool m_readError {false};
106  // put here to avoid changing other classes
107  QString m_configFile;
108 
109  QObject *m_mainWindow {nullptr};
110  QString m_devicename;
111  int m_fd {-1};
113 
118  unsigned char m_buttonCount {0};
119 
124  unsigned char m_axesCount {0};
125 
126  int *m_buttons {nullptr};
127  int *m_axes {nullptr};
128 
129  volatile bool m_bStop {false};
130 };
131 
132 #endif
JoystickMenuThread::m_map
JoystickMap m_map
Definition: jsmenu.h:112
JoystickMenuThread::m_readError
bool m_readError
Definition: jsmenu.h:105
buttonMapType::button
int button
Definition: jsmenu.h:21
JoystickMenuThread::EmitKey
void EmitKey(const QString &code)
Send a keyevent to the main UI loop with the appropriate keycode.
Definition: jsmenu.cpp:381
buttonMapType::chord
int chord
Definition: jsmenu.h:23
JoystickMenuThread::m_bStop
volatile bool m_bStop
Definition: jsmenu.h:129
JoystickMenuThread::JoystickMenuThread
JoystickMenuThread(QObject *main_window)
Definition: jsmenu.h:90
JoystickMenuThread::m_buttonCount
unsigned char m_buttonCount
Track the status of the joystick buttons as we do depend slightly on state.
Definition: jsmenu.h:118
buttonMapType::keystring
QString keystring
Definition: jsmenu.h:22
JoystickMenuThread::m_buttons
int * m_buttons
Definition: jsmenu.h:126
buttonMapType
Definition: jsmenu.h:19
axisMapType::to
int to
Definition: jsmenu.h:30
JoystickMenuThread::m_configFile
QString m_configFile
Definition: jsmenu.h:107
JoystickMenuThread::m_axes
int * m_axes
Definition: jsmenu.h:127
JoystickMap::Clear
void Clear()
Definition: jsmenu.h:66
axisMapType
Definition: jsmenu.h:26
JoystickMenuThread::m_fd
int m_fd
Definition: jsmenu.h:111
axisMapType::keystring
QString keystring
Definition: jsmenu.h:31
JoystickMenuThread::ButtonUp
void ButtonUp(int button)
Handle a button up event.
Definition: jsmenu.cpp:419
axisMapType::from
int from
Definition: jsmenu.h:29
axisMapType::axis
int axis
Definition: jsmenu.h:28
JoystickMenuThread::m_configRead
bool m_configRead
Definition: jsmenu.h:104
JoystickMap
Holds the buttonMapType and axisMapType structs which map actions to events.
Definition: jsmenu.h:51
JoystickMap::button_map_t
std::vector< buttonMapType > button_map_t
Definition: jsmenu.h:71
JoystickMap::AddAxis
void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
Definition: jsmenu.h:60
JoystickMenuThread::m_devicename
QString m_devicename
Definition: jsmenu.h:110
JoystickMenuThread::Stop
void Stop(void)
Definition: jsmenu.h:99
JoystickMap::axis_map_t
std::vector< axisMapType > axis_map_t
Definition: jsmenu.h:72
JoystickMenuThread::m_mainWindow
QObject * m_mainWindow
Definition: jsmenu.h:109
JoystickMenuThread::AxisChange
void AxisChange(int axis, int value)
Handle a registered change in a joystick axis.
Definition: jsmenu.cpp:451
JoystickMap::buttonMap
const button_map_t & buttonMap() const
Definition: jsmenu.h:73
JoystickMenuThread::run
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:222
JoystickMenuThread::~JoystickMenuThread
~JoystickMenuThread() override
Definition: jsmenu.cpp:59
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
mthread.h
JoystickMap::m_buttonMap
button_map_t m_buttonMap
Definition: jsmenu.h:76
JoystickMenuThread::ReadConfig
bool ReadConfig(const QString &config_file)
Read from action to key mappings from flat file config file.
Definition: jsmenu.cpp:156
JoystickMenuThread::Init
bool Init(QString &config_file)
Initialise the class variables with values from the config file.
Definition: jsmenu.cpp:77
JoystickMap::m_axisMap
axis_map_t m_axisMap
Definition: jsmenu.h:77
JoystickMenuThread
Main object for injecting key strokes based on joystick movements.
Definition: jsmenu.h:87
JoystickMap::AddButton
void AddButton(int in_button, QString in_keystr, int in_chord=-1)
Definition: jsmenu.h:54
JoystickMap::axisMap
const axis_map_t & axisMap() const
Definition: jsmenu.h:74
JoystickMenuThread::m_axesCount
unsigned char m_axesCount
Track the status of the joystick axes as we do depend slightly on state.
Definition: jsmenu.h:124