28 #include <QCoreApplication>
30 #include <QKeySequence>
31 #include <QTextStream>
32 #include <QStringList>
39 #include <sys/types.h>
44 #include <linux/joystick.h>
52 #define LOC QString("JoystickMenuThread: ")
86 LOG(VB_GENERAL, LOG_ERR,
LOC +
87 QString(
"Joystick disabled - Failed to open device %1")
95 LOG(VB_GENERAL, LOG_ERR,
LOC +
96 "Joystick disabled - ioctl JSIOCGAXES failed");
103 LOG(VB_GENERAL, LOG_ERR,
LOC +
104 "Joystick disabled - ioctl JSIOCGBUTTONS failed");
117 LOG(VB_GENERAL, LOG_INFO,
LOC +
118 QString(
"Initialization of %1 succeeded using config file %2")
138 if (!QFile::exists(config_file))
140 LOG(VB_GENERAL, LOG_INFO,
"No joystick configuration found, not enabling joystick control");
144 FILE *fp = fopen(qPrintable(config_file),
"r");
147 LOG(VB_GENERAL, LOG_ERR,
LOC +
148 QString(
"Joystick disabled - Failed to open %1") .
arg(config_file));
152 QTextStream istream(fp);
153 for (
int line = 1; ! istream.atEnd(); line++)
155 QString rawline = istream.readLine();
156 QString simple_line = rawline.simplified();
157 if (simple_line.isEmpty() || simple_line.startsWith(
'#'))
160 QStringList tokens = simple_line.split(
" ");
161 if (tokens.count() < 1)
164 QString firstTok = tokens[0].toLower();
166 if (firstTok.startsWith(
"devicename") && tokens.count() == 2)
170 else if (firstTok.startsWith(
"button") && tokens.count() == 3)
174 else if (firstTok.startsWith(
"axis") && tokens.count() == 5)
177 tokens[3].toInt(), tokens[4]);
179 else if (firstTok.startsWith(
"chord") && tokens.count() == 4)
185 LOG(VB_GENERAL, LOG_WARNING,
LOC +
186 QString(
"ReadConfig(%1) unrecognized or malformed line \"%2\" ")
187 .
arg(line) .
arg(rawline));
205 struct js_event js {};
216 FD_SET(
m_fd, &readfds);
222 int rc = select(
m_fd + 1, &readfds,
nullptr,
nullptr, &
timeout);
229 LOG(VB_GENERAL, LOG_ERR,
"select: " +
ENO);
239 if (rc !=
sizeof(js))
241 LOG(VB_GENERAL, LOG_ERR,
"error reading js:" +
ENO);
250 if (js.type & JS_EVENT_INIT)
255 if (js.type & JS_EVENT_AXIS && js.number <
m_axesCount)
256 m_axes[js.number] = js.value;
273 if (js.value == 0 &&
m_buttons[js.number] == 1)
279 if (js.type & JS_EVENT_AXIS && js.number <
m_axesCount)
282 m_axes[js.number] = js.value;
299 QKeySequence a(code);
310 for (
int i = 0; i < a.count(); i++)
333 JoystickMap::button_map_t::const_iterator bmap;
337 if (button == bmap->button && bmap->chord != -1
352 if (button == bmap->button && bmap->chord == -1)
362 JoystickMap::axis_map_t::const_iterator amap;
365 if (axis == amap->axis)
369 if (
m_axes[axis] < amap->from ||
m_axes[axis] > amap->to)
370 if (value >= amap->from && value <= amap->to)