Merge branch 'rr1-maint'
This commit is contained in:
commit
6f229e6a93
12 changed files with 890 additions and 2748 deletions
105
include/core/joystick.hpp
Normal file
105
include/core/joystick.hpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
#ifndef _joystick__hpp__included__
|
||||
#define _joystick__hpp__included__
|
||||
|
||||
#include "core/keymapper.hpp"
|
||||
|
||||
/**
|
||||
* Create a new joystick.
|
||||
*
|
||||
* Parameter id: The id of new joystick.
|
||||
* Parameter xname: The name of new joystick.
|
||||
*/
|
||||
void joystick_create(uint64_t id, const std::string& xname);
|
||||
/**
|
||||
* Free all joysticks.
|
||||
*/
|
||||
void joystick_quit();
|
||||
/**
|
||||
* Create a new axis.
|
||||
*
|
||||
* Parameter jid: The id of joystick.
|
||||
* Parameter id: The id of the axis.
|
||||
* Parameter minv: The minimal calibration value.
|
||||
* Parameter maxv: The maximal calibration value.
|
||||
* Parameter xname: The name of axis.
|
||||
* Parameter atype: The axis type.
|
||||
*/
|
||||
void joystick_new_axis(uint64_t jid, uint64_t id, int64_t minv, int64_t maxv, const std::string& xname,
|
||||
enum keygroup::type atype);
|
||||
/**
|
||||
* Create a new button.
|
||||
*
|
||||
* Parameter jid: The id of joystick.
|
||||
* Parameter id: The id of button.
|
||||
* Parameter xname: The name of button.
|
||||
* Returns: The number of button.
|
||||
*/
|
||||
void joystick_new_button(uint64_t jid, uint64_t id, const std::string& xname);
|
||||
/**
|
||||
* Create a new hat from pair of axes.
|
||||
*
|
||||
* Parameter jid: The id of joystick.
|
||||
* Parameter id_x: The id of x axis of the hat.
|
||||
* Parameter id_y: The id of y axis of the hat.
|
||||
* Parameter min_dev: The smallest deviation from zero to react to.
|
||||
* Parameter xname_x: The name of x axis.
|
||||
* Parameter xname_y: The name of y axis.
|
||||
* Returns: The number of hat.
|
||||
*/
|
||||
void joystick_new_hat(uint64_t jid, uint64_t id_x, uint64_t id_y, int64_t min_dev, const std::string& xname_x,
|
||||
const std::string& xname_y);
|
||||
/**
|
||||
* Create a new hat from POV control.
|
||||
*
|
||||
* Parameter jid: The id of joystick.
|
||||
* Parameter id: The id of POV control.
|
||||
* Parameter xname: The name of POV control.
|
||||
* Returns: The number of hat.
|
||||
*/
|
||||
void joystick_new_hat(uint64_t jid, uint64_t id, const std::string& xname);
|
||||
/**
|
||||
* Report possible change in axis value.
|
||||
*
|
||||
* Requests to update unknown axes are ignored.
|
||||
*
|
||||
* Parameter jid: The id of joystick.
|
||||
* Parameter id: The ID of axis.
|
||||
* Parameter value: The value.
|
||||
*/
|
||||
void joystick_report_axis(uint64_t jid, uint64_t id, int64_t value);
|
||||
/**
|
||||
* Report possible change in button value.
|
||||
*
|
||||
* Requests to update unknown buttons are ignored.
|
||||
*
|
||||
* Parameter jid: The id of joystick.
|
||||
* Parameter id: The ID of button.
|
||||
* Parameter value: The value.
|
||||
*/
|
||||
void joystick_report_button(uint64_t jid, uint64_t id, bool value);
|
||||
/**
|
||||
* Report possible change in POV value.
|
||||
*
|
||||
* Requests to update unknown POVs are ignored.
|
||||
*
|
||||
* Parameter jid: The id of joystick.
|
||||
* Parameter id: The ID of POV.
|
||||
* Parameter value: The angle in hundredths of degree clockwise from up, or negative if centered.
|
||||
*/
|
||||
void joystick_report_pov(uint64_t jid, uint64_t id, int angle);
|
||||
/**
|
||||
* Print message about joystick.
|
||||
*
|
||||
* Parameter jid: The joystick id.
|
||||
*/
|
||||
void joystick_message(uint64_t jid);
|
||||
/**
|
||||
* Get set of all joysticks.
|
||||
*/
|
||||
std::set<uint64_t> joystick_set();
|
||||
/**
|
||||
* Flush all pending joystick requests.
|
||||
*/
|
||||
void joystick_flush();
|
||||
|
||||
#endif
|
|
@ -2,6 +2,9 @@
|
|||
#define _library__joyfun__hpp__included__
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* Perform axis calibration correction.
|
||||
|
@ -38,4 +41,190 @@ template<typename T> bool make_equal(T& a, const T& b)
|
|||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Joystick.
|
||||
*/
|
||||
class joystick_model
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Set name of joystick field.
|
||||
*/
|
||||
void name(const std::string& newn);
|
||||
/**
|
||||
* Get name of joystick field.
|
||||
*/
|
||||
const std::string& name();
|
||||
/**
|
||||
* Create a new axis.
|
||||
*
|
||||
* Parameter id: The id of the axis.
|
||||
* Parameter minv: The minimal calibration value.
|
||||
* Parameter maxv: The maximal calibration value.
|
||||
* Parameter xname: The name of axis.
|
||||
* Returns: The number of axis.
|
||||
*/
|
||||
unsigned new_axis(uint64_t id, int64_t minv, int64_t maxv, const std::string& xname);
|
||||
/**
|
||||
* Create a new button.
|
||||
*
|
||||
* Parameter id: The id of button.
|
||||
* Parameter xname: The name of button.
|
||||
* Returns: The number of button.
|
||||
*/
|
||||
unsigned new_button(uint64_t id, const std::string& xname);
|
||||
/**
|
||||
* Create a new hat from pair of axes.
|
||||
*
|
||||
* Parameter id_x: The id of x axis of the hat.
|
||||
* Parameter id_y: The id of y axis of the hat.
|
||||
* Parameter min_dev: The smallest deviation from zero to react to.
|
||||
* Parameter xname_x: The name of x axis.
|
||||
* Parameter xname_y: The name of y axis.
|
||||
* Returns: The number of hat.
|
||||
*/
|
||||
unsigned new_hat(uint64_t id_x, uint64_t id_y, int64_t min_dev, const std::string& xname_x,
|
||||
const std::string& xname_y);
|
||||
/**
|
||||
* Create a new hat from POV control.
|
||||
*
|
||||
* Parameter id: The id of POV control.
|
||||
* Parameter xname: The name of POV control.
|
||||
* Returns: The number of hat.
|
||||
*/
|
||||
unsigned new_hat(uint64_t id, const std::string& xname);
|
||||
/**
|
||||
* Get the number of axes.
|
||||
*/
|
||||
unsigned axes() { return size_common(_axes); }
|
||||
/**
|
||||
* Get the number of buttons.
|
||||
*/
|
||||
unsigned buttons() { return size_common(_buttons); }
|
||||
/**
|
||||
* Get the number of hats.
|
||||
*/
|
||||
unsigned hats() { return size_common(_hats); }
|
||||
/**
|
||||
* Report on specified axis.
|
||||
*
|
||||
* Parameter id: The number of axis to report.
|
||||
* Parameter res: Place to write the calibrated axis value to.
|
||||
* Returns: True if value has changed since last call, false otherwise.
|
||||
*/
|
||||
bool axis(unsigned id, short& res) { return read_common(_axes, id, res); }
|
||||
/**
|
||||
* Report on specified button.
|
||||
*
|
||||
* Parameter id: The number of button to report.
|
||||
* Parameter res: Place to write the value to.
|
||||
* Returns: True if value has changed since last call, false otherwise.
|
||||
*/
|
||||
bool button(unsigned id, short& res) { return read_common(_buttons, id, res); }
|
||||
/**
|
||||
* Report on specified hat.
|
||||
*
|
||||
* Parameter id: The number of hat to report.
|
||||
* Parameter res: Place to write the value to.
|
||||
* Returns: True if value has changed since last call, false otherwise.
|
||||
*/
|
||||
bool hat(unsigned id, short& res) { return read_common(_hats, id, res); }
|
||||
/**
|
||||
* Return name of axis.
|
||||
*
|
||||
* Parameter id: The axis number.
|
||||
* Returns: The name of the axis, or "" if not found.
|
||||
*/
|
||||
std::string axisname(unsigned id);
|
||||
/**
|
||||
* Return axis calibration data.
|
||||
*
|
||||
* Parameter id: The axis number.
|
||||
* Returns: The axis calibration (first minimum, then maximum).
|
||||
*/
|
||||
std::pair<int64_t, int64_t> axiscalibration(unsigned id);
|
||||
/**
|
||||
* Return name of button.
|
||||
*
|
||||
* Parameter id: The button number.
|
||||
* Returns: The name of the button, or "" if not found.
|
||||
*/
|
||||
std::string buttonname(unsigned id);
|
||||
/**
|
||||
* Return name of hat.
|
||||
*
|
||||
* Parameter id: The hat number.
|
||||
* Returns: The name of the hat, or "" if not found.
|
||||
*/
|
||||
std::string hatname(unsigned id);
|
||||
/**
|
||||
* Report possible change in axis value.
|
||||
*
|
||||
* Requests to update unknown axes are ignored.
|
||||
*
|
||||
* Parameter id: The ID of axis.
|
||||
* Parameter value: The value.
|
||||
*/
|
||||
void report_axis(uint64_t id, int64_t value);
|
||||
/**
|
||||
* Report possible change in button value.
|
||||
*
|
||||
* Requests to update unknown buttons are ignored.
|
||||
*
|
||||
* Parameter id: The ID of button.
|
||||
* Parameter value: The value.
|
||||
*/
|
||||
void report_button(uint64_t id, bool value);
|
||||
/**
|
||||
* Report possible change in POV value.
|
||||
*
|
||||
* Requests to update unknown POVs are ignored.
|
||||
*
|
||||
* Parameter id: The ID of POV.
|
||||
* Parameter value: The angle in hundredths of degree clockwise from up, or negative if centered.
|
||||
*/
|
||||
void report_pov(uint64_t id, int angle);
|
||||
/**
|
||||
* Report on joystick.
|
||||
*/
|
||||
std::string compose_report(unsigned jnum);
|
||||
private:
|
||||
struct change_info
|
||||
{
|
||||
change_info();
|
||||
void update(short newv);
|
||||
bool read(short& val);
|
||||
private:
|
||||
bool has_been_read;
|
||||
short last_read;
|
||||
short last_known;
|
||||
};
|
||||
struct hat_info
|
||||
{
|
||||
int xstate;
|
||||
int ystate;
|
||||
};
|
||||
struct hat_axis_info
|
||||
{
|
||||
bool yflag; //Set on y axis, clear on x axis.
|
||||
int64_t mindev;
|
||||
unsigned hnum;
|
||||
};
|
||||
bool read_common(std::vector<change_info>& i, unsigned id, short& res);
|
||||
unsigned size_common(std::vector<change_info>& i);
|
||||
std::vector<change_info> _axes;
|
||||
std::vector<change_info> _buttons;
|
||||
std::vector<change_info> _hats;
|
||||
std::map<uint64_t, unsigned> button_map;
|
||||
std::map<uint64_t, unsigned> axis_map; //No hats here!
|
||||
std::map<uint64_t, unsigned> pov_map;
|
||||
std::map<uint64_t, std::pair<int64_t, int64_t>> aranges;
|
||||
std::vector<hat_info> hatinfos;
|
||||
std::map<uint64_t, hat_axis_info> hataxis_map;
|
||||
std::map<unsigned, std::string> axisnames;
|
||||
std::map<unsigned, std::string> buttonnames;
|
||||
std::map<unsigned, std::string> hatnames;
|
||||
std::string joyname;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
142
src/core/joystick.cpp
Normal file
142
src/core/joystick.cpp
Normal file
|
@ -0,0 +1,142 @@
|
|||
#include "core/command.hpp"
|
||||
#include "core/joystick.hpp"
|
||||
#include "core/window.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/joyfun.hpp"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
std::map<uint64_t, joystick_model> joysticks;
|
||||
std::map<uint64_t, unsigned> joynumbers;
|
||||
std::map<std::pair<uint64_t, unsigned>, keygroup*> axes;
|
||||
std::map<std::pair<uint64_t, unsigned>, keygroup*> buttons;
|
||||
std::map<std::pair<uint64_t, unsigned>, keygroup*> hats;
|
||||
unsigned joystick_count = 0;
|
||||
|
||||
function_ptr_command<> show_joysticks("show-joysticks", "Show joysticks",
|
||||
"Syntax: show-joysticks\nShow joystick data.\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
messages << "Driver: " << joystick_plugin::name << std::endl;
|
||||
messages << "--------------------------------------" << std::endl;
|
||||
for(auto i : joynumbers)
|
||||
messages << joysticks[i.first].compose_report(i.second) << std::endl;
|
||||
messages << "--------------------------------------" << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
void joystick_create(uint64_t id, const std::string& xname)
|
||||
{
|
||||
joynumbers[id] = joystick_count++;
|
||||
joysticks[id].name(xname);
|
||||
}
|
||||
|
||||
void joystick_quit()
|
||||
{
|
||||
for(auto i : axes)
|
||||
delete i.second;
|
||||
for(auto i : buttons)
|
||||
delete i.second;
|
||||
for(auto i : hats)
|
||||
delete i.second;
|
||||
joysticks.clear();
|
||||
joynumbers.clear();
|
||||
axes.clear();
|
||||
buttons.clear();
|
||||
hats.clear();
|
||||
joystick_count = 0;
|
||||
}
|
||||
|
||||
void joystick_new_axis(uint64_t jid, uint64_t id, int64_t minv, int64_t maxv, const std::string& xname,
|
||||
enum keygroup::type atype)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
unsigned jnum = joynumbers[jid];
|
||||
unsigned n = joysticks[jid].new_axis(id, minv, maxv, xname);
|
||||
std::string name = (stringfmt() << "joystick" << jnum << "axis" << n).str();
|
||||
axes[std::make_pair(jid, n)] = new keygroup(name, "joystick", atype);
|
||||
}
|
||||
|
||||
void joystick_new_button(uint64_t jid, uint64_t id, const std::string& xname)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
unsigned jnum = joynumbers[jid];
|
||||
unsigned n = joysticks[jid].new_button(id, xname);
|
||||
std::string name = (stringfmt() << "joystick" << jnum << "button" << n).str();
|
||||
buttons[std::make_pair(jid, n)] = new keygroup(name, "joystick", keygroup::KT_KEY);
|
||||
}
|
||||
|
||||
void joystick_new_hat(uint64_t jid, uint64_t id_x, uint64_t id_y, int64_t min_dev, const std::string& xname_x,
|
||||
const std::string& xname_y)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
unsigned jnum = joynumbers[jid];
|
||||
unsigned n = joysticks[jid].new_hat(id_x, id_y, min_dev, xname_x, xname_y);
|
||||
std::string name = (stringfmt() << "joystick" << jnum << "hat" << n).str();
|
||||
hats[std::make_pair(jid, n)] = new keygroup(name, "joystick", keygroup::KT_HAT);
|
||||
}
|
||||
|
||||
void joystick_new_hat(uint64_t jid, uint64_t id, const std::string& xname)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
unsigned jnum = joynumbers[jid];
|
||||
unsigned n = joysticks[jid].new_hat(id, xname);
|
||||
std::string name = (stringfmt() << "joystick" << jnum << "hat" << n).str();
|
||||
hats[std::make_pair(jid, n)] = new keygroup(name, "joystick", keygroup::KT_HAT);
|
||||
}
|
||||
|
||||
void joystick_report_axis(uint64_t jid, uint64_t id, int64_t value)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
joysticks[jid].report_axis(id, value);
|
||||
}
|
||||
|
||||
void joystick_report_button(uint64_t jid, uint64_t id, bool value)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
joysticks[jid].report_button(id, value);
|
||||
}
|
||||
|
||||
void joystick_report_pov(uint64_t jid, uint64_t id, int angle)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
joysticks[jid].report_pov(id, angle);
|
||||
}
|
||||
|
||||
void joystick_message(uint64_t jid)
|
||||
{
|
||||
if(!joysticks.count(jid))
|
||||
return;
|
||||
messages << "Found '" << joysticks[jid].name() << "' (" << joysticks[jid].buttons() << " buttons, "
|
||||
<< joysticks[jid].axes() << " axes, " << joysticks[jid].hats() << " hats)" << std::endl;
|
||||
}
|
||||
|
||||
std::set<uint64_t> joystick_set()
|
||||
{
|
||||
std::set<uint64_t> x;
|
||||
for(auto i : joynumbers)
|
||||
x.insert(i.first);
|
||||
return x;
|
||||
}
|
||||
|
||||
void joystick_flush()
|
||||
{
|
||||
short x;
|
||||
for(auto i : buttons)
|
||||
if(joysticks[i.first.first].button(i.first.second, x))
|
||||
platform::queue(keypress(modifier_set(), *i.second, x));
|
||||
for(auto i : axes)
|
||||
if(joysticks[i.first.first].axis(i.first.second, x))
|
||||
platform::queue(keypress(modifier_set(), *i.second, x));
|
||||
for(auto i : hats)
|
||||
if(joysticks[i.first.first].hat(i.first.second, x))
|
||||
platform::queue(keypress(modifier_set(), *i.second, x));
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
#include "library/joyfun.hpp"
|
||||
|
||||
#include "library/string.hpp"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
short calibration_correction(int64_t v, int64_t low, int64_t high)
|
||||
{
|
||||
|
@ -28,3 +30,168 @@ short angle_to_bitmask(int pov)
|
|||
m |= 8;
|
||||
return m;
|
||||
}
|
||||
|
||||
joystick_model::change_info::change_info()
|
||||
{
|
||||
has_been_read = false;
|
||||
last_read = 0;
|
||||
last_known = 0;
|
||||
}
|
||||
|
||||
void joystick_model::change_info::update(short newv)
|
||||
{
|
||||
last_known = newv;
|
||||
}
|
||||
|
||||
bool joystick_model::change_info::read(short& val)
|
||||
{
|
||||
bool r = (last_known != last_read || !has_been_read);
|
||||
has_been_read = true;
|
||||
val = last_read = last_known;
|
||||
return r;
|
||||
}
|
||||
|
||||
bool joystick_model::read_common(std::vector<change_info>& i, unsigned id, short& res)
|
||||
{
|
||||
if(id >= i.size())
|
||||
return false;
|
||||
return i[id].read(res);
|
||||
}
|
||||
|
||||
unsigned joystick_model::size_common(std::vector<change_info>& i)
|
||||
{
|
||||
return i.size();
|
||||
}
|
||||
|
||||
void joystick_model::report_button(uint64_t id, bool value)
|
||||
{
|
||||
if(button_map.count(id))
|
||||
_buttons[button_map[id]].update(value ? 1 : 0);
|
||||
}
|
||||
|
||||
void joystick_model::report_pov(uint64_t id, int angle)
|
||||
{
|
||||
if(pov_map.count(id))
|
||||
_hats[pov_map[id]].update(angle_to_bitmask(angle));
|
||||
}
|
||||
|
||||
void joystick_model::report_axis(uint64_t id, int64_t value)
|
||||
{
|
||||
//The axis case.
|
||||
if(axis_map.count(id))
|
||||
_axes[axis_map[id]].update(calibration_correction(value, aranges[id].first, aranges[id].second));
|
||||
//It isn't known axis. See if it is connected with axis pair for hat.
|
||||
else if(hataxis_map.count(id)) {
|
||||
struct hat_axis_info& ai = hataxis_map[id];
|
||||
struct hat_info& hi = hatinfos[ai.hnum];
|
||||
short v = 0;
|
||||
if(value <= -ai.mindev) v = -1;
|
||||
if(value >= ai.mindev) v = 1;
|
||||
if(ai.yflag) hi.ystate = v;
|
||||
else hi.xstate = v;
|
||||
v = 0;
|
||||
if(hi.ystate < 0) v |= 1;
|
||||
if(hi.xstate > 0) v |= 2;
|
||||
if(hi.ystate > 0) v |= 4;
|
||||
if(hi.xstate < 0) v |= 8;
|
||||
_hats[ai.hnum].update(v);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned joystick_model::new_axis(uint64_t id, int64_t minv, int64_t maxv, const std::string& xname)
|
||||
{
|
||||
unsigned n = axes();
|
||||
aranges[id] = std::make_pair(minv, maxv);
|
||||
_axes.resize(n + 1);
|
||||
axis_map[id] = n;
|
||||
axisnames[n] = xname;
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned joystick_model::new_button(uint64_t id, const std::string& xname)
|
||||
{
|
||||
unsigned n = buttons();
|
||||
_buttons.resize(n + 1);
|
||||
button_map[id] = n;
|
||||
buttonnames[n] = xname;
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned joystick_model::new_hat(uint64_t id_x, uint64_t id_y, int64_t min_dev, const std::string& xname_x,
|
||||
const std::string& xname_y)
|
||||
{
|
||||
unsigned n = hats();
|
||||
hatinfos.resize(n + 1);
|
||||
hatinfos[n].xstate = 0;
|
||||
hatinfos[n].ystate = 0;
|
||||
_hats.resize(n + 1);
|
||||
hataxis_map[id_x].yflag = false;
|
||||
hataxis_map[id_x].hnum = n;
|
||||
hataxis_map[id_x].mindev = min_dev;
|
||||
hataxis_map[id_y].yflag = true;
|
||||
hataxis_map[id_y].hnum = n;
|
||||
hataxis_map[id_y].mindev = min_dev;
|
||||
hatnames[n] = "<X: " + xname_x + " Y: " + xname_y + ">";
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned joystick_model::new_hat(uint64_t id, const std::string& xname)
|
||||
{
|
||||
unsigned n = hats();
|
||||
_hats.resize(n + 1);
|
||||
pov_map[id] = n;
|
||||
hatnames[n] = xname;
|
||||
return n;
|
||||
}
|
||||
|
||||
std::pair<int64_t, int64_t> joystick_model::axiscalibration(unsigned id)
|
||||
{
|
||||
for(auto i : axis_map)
|
||||
if(i.second == id)
|
||||
return aranges[i.first];
|
||||
return std::make_pair(0, 0);
|
||||
}
|
||||
|
||||
std::string joystick_model::axisname(unsigned id)
|
||||
{
|
||||
if(axisnames.count(id)) return axisnames[id];
|
||||
else return "";
|
||||
}
|
||||
|
||||
std::string joystick_model::buttonname(unsigned id)
|
||||
{
|
||||
if(buttonnames.count(id)) return buttonnames[id];
|
||||
else return "";
|
||||
}
|
||||
|
||||
std::string joystick_model::hatname(unsigned id)
|
||||
{
|
||||
if(hatnames.count(id)) return hatnames[id];
|
||||
else return "";
|
||||
}
|
||||
|
||||
void joystick_model::name(const std::string& newn)
|
||||
{
|
||||
joyname = newn;
|
||||
}
|
||||
|
||||
const std::string& joystick_model::name()
|
||||
{
|
||||
return joyname;
|
||||
}
|
||||
|
||||
std::string joystick_model::compose_report(unsigned jnum)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "Joystick #" << jnum << ": " << joyname << std::endl;
|
||||
for(size_t i = 0; i < _axes.size(); i++) {
|
||||
auto c = axiscalibration(i);
|
||||
out << " Axis #" << i << ": " << axisnames[i] << "(" << c.first << " - " << c.second << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
for(size_t i = 0; i < _buttons.size(); i++)
|
||||
out << " Button #" << i << ": " << buttonnames[i] << std::endl;
|
||||
for(size_t i = 0; i < _hats.size(); i++)
|
||||
out << " Hat #" << i << ": " << hatnames[i] << std::endl;
|
||||
return out.str();
|
||||
}
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
extern "C" {
|
||||
#include <linux/input.h>
|
||||
}
|
||||
void evdev_init_axes(const char** x) {
|
||||
#ifdef ABS_X
|
||||
x[ABS_X] = "X";
|
||||
#endif
|
||||
#ifdef ABS_Y
|
||||
x[ABS_Y] = "Y";
|
||||
#endif
|
||||
#ifdef ABS_Z
|
||||
x[ABS_Z] = "Z";
|
||||
#endif
|
||||
#ifdef ABS_RX
|
||||
x[ABS_RX] = "RX";
|
||||
#endif
|
||||
#ifdef ABS_RY
|
||||
x[ABS_RY] = "RY";
|
||||
#endif
|
||||
#ifdef ABS_RZ
|
||||
x[ABS_RZ] = "RZ";
|
||||
#endif
|
||||
#ifdef ABS_THROTTLE
|
||||
x[ABS_THROTTLE] = "THROTTLE";
|
||||
#endif
|
||||
#ifdef ABS_RUDDER
|
||||
x[ABS_RUDDER] = "RUDDER";
|
||||
#endif
|
||||
#ifdef ABS_WHEEL
|
||||
x[ABS_WHEEL] = "WHEEL";
|
||||
#endif
|
||||
#ifdef ABS_GAS
|
||||
x[ABS_GAS] = "GAS";
|
||||
#endif
|
||||
#ifdef ABS_BRAKE
|
||||
x[ABS_BRAKE] = "BRAKE";
|
||||
#endif
|
||||
#ifdef ABS_HAT0X
|
||||
x[ABS_HAT0X] = "HAT0X";
|
||||
#endif
|
||||
#ifdef ABS_HAT0Y
|
||||
x[ABS_HAT0Y] = "HAT0Y";
|
||||
#endif
|
||||
#ifdef ABS_HAT1X
|
||||
x[ABS_HAT1X] = "HAT1X";
|
||||
#endif
|
||||
#ifdef ABS_HAT1Y
|
||||
x[ABS_HAT1Y] = "HAT1Y";
|
||||
#endif
|
||||
#ifdef ABS_HAT2X
|
||||
x[ABS_HAT2X] = "HAT2X";
|
||||
#endif
|
||||
#ifdef ABS_HAT2Y
|
||||
x[ABS_HAT2Y] = "HAT2Y";
|
||||
#endif
|
||||
#ifdef ABS_HAT3X
|
||||
x[ABS_HAT3X] = "HAT3X";
|
||||
#endif
|
||||
#ifdef ABS_HAT3Y
|
||||
x[ABS_HAT3Y] = "HAT3Y";
|
||||
#endif
|
||||
#ifdef ABS_PRESSURE
|
||||
x[ABS_PRESSURE] = "PRESSURE";
|
||||
#endif
|
||||
#ifdef ABS_DISTANCE
|
||||
x[ABS_DISTANCE] = "DISTANCE";
|
||||
#endif
|
||||
#ifdef ABS_TILT_X
|
||||
x[ABS_TILT_X] = "TILT_X";
|
||||
#endif
|
||||
#ifdef ABS_TILT_Y
|
||||
x[ABS_TILT_Y] = "TILT_Y";
|
||||
#endif
|
||||
#ifdef ABS_TOOL_WIDTH
|
||||
x[ABS_TOOL_WIDTH] = "TOOL_WIDTH";
|
||||
#endif
|
||||
#ifdef ABS_VOLUME
|
||||
x[ABS_VOLUME] = "VOLUME";
|
||||
#endif
|
||||
#ifdef ABS_MISC
|
||||
x[ABS_MISC] = "MISC";
|
||||
#endif
|
||||
#ifdef ABS_MT_SLOT
|
||||
x[ABS_MT_SLOT] = "MT_SLOT";
|
||||
#endif
|
||||
#ifdef ABS_MT_TOUCH_MAJOR
|
||||
x[ABS_MT_TOUCH_MAJOR] = "MT_TOUCH_MAJOR";
|
||||
#endif
|
||||
#ifdef ABS_MT_TOUCH_MINOR
|
||||
x[ABS_MT_TOUCH_MINOR] = "MT_TOUCH_MINOR";
|
||||
#endif
|
||||
#ifdef ABS_MT_WIDTH_MAJOR
|
||||
x[ABS_MT_WIDTH_MAJOR] = "MT_WIDTH_MAJOR";
|
||||
#endif
|
||||
#ifdef ABS_MT_WIDTH_MINOR
|
||||
x[ABS_MT_WIDTH_MINOR] = "MT_WIDTH_MINOR";
|
||||
#endif
|
||||
#ifdef ABS_MT_ORIENTATION
|
||||
x[ABS_MT_ORIENTATION] = "MT_ORIENTATION";
|
||||
#endif
|
||||
#ifdef ABS_MT_POSITION_X
|
||||
x[ABS_MT_POSITION_X] = "MT_POSITION_X";
|
||||
#endif
|
||||
#ifdef ABS_MT_POSITION_Y
|
||||
x[ABS_MT_POSITION_Y] = "MT_POSITION_Y";
|
||||
#endif
|
||||
#ifdef ABS_MT_TOOL_TYPE
|
||||
x[ABS_MT_TOOL_TYPE] = "MT_TOOL_TYPE";
|
||||
#endif
|
||||
#ifdef ABS_MT_BLOB_ID
|
||||
x[ABS_MT_BLOB_ID] = "MT_BLOB_ID";
|
||||
#endif
|
||||
#ifdef ABS_MT_TRACKING_ID
|
||||
x[ABS_MT_TRACKING_ID] = "MT_TRACKING_ID";
|
||||
#endif
|
||||
#ifdef ABS_MT_PRESSURE
|
||||
x[ABS_MT_PRESSURE] = "MT_PRESSURE";
|
||||
#endif
|
||||
#ifdef ABS_MT_DISTANCE
|
||||
x[ABS_MT_DISTANCE] = "MT_DISTANCE";
|
||||
#endif
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
evdev_init_axes
|
||||
ABS_X X
|
||||
ABS_Y Y
|
||||
ABS_Z Z
|
||||
ABS_RX RX
|
||||
ABS_RY RY
|
||||
ABS_RZ RZ
|
||||
ABS_THROTTLE THROTTLE
|
||||
ABS_RUDDER RUDDER
|
||||
ABS_WHEEL WHEEL
|
||||
ABS_GAS GAS
|
||||
ABS_BRAKE BRAKE
|
||||
ABS_HAT0X HAT0X
|
||||
ABS_HAT0Y HAT0Y
|
||||
ABS_HAT1X HAT1X
|
||||
ABS_HAT1Y HAT1Y
|
||||
ABS_HAT2X HAT2X
|
||||
ABS_HAT2Y HAT2Y
|
||||
ABS_HAT3X HAT3X
|
||||
ABS_HAT3Y HAT3Y
|
||||
ABS_PRESSURE PRESSURE
|
||||
ABS_DISTANCE DISTANCE
|
||||
ABS_TILT_X TILT_X
|
||||
ABS_TILT_Y TILT_Y
|
||||
ABS_TOOL_WIDTH TOOL_WIDTH
|
||||
ABS_VOLUME VOLUME
|
||||
ABS_MISC MISC
|
||||
ABS_MT_SLOT MT_SLOT
|
||||
ABS_MT_TOUCH_MAJOR MT_TOUCH_MAJOR
|
||||
ABS_MT_TOUCH_MINOR MT_TOUCH_MINOR
|
||||
ABS_MT_WIDTH_MAJOR MT_WIDTH_MAJOR
|
||||
ABS_MT_WIDTH_MINOR MT_WIDTH_MINOR
|
||||
ABS_MT_ORIENTATION MT_ORIENTATION
|
||||
ABS_MT_POSITION_X MT_POSITION_X
|
||||
ABS_MT_POSITION_Y MT_POSITION_Y
|
||||
ABS_MT_TOOL_TYPE MT_TOOL_TYPE
|
||||
ABS_MT_BLOB_ID MT_BLOB_ID
|
||||
ABS_MT_TRACKING_ID MT_TRACKING_ID
|
||||
ABS_MT_PRESSURE MT_PRESSURE
|
||||
ABS_MT_DISTANCE MT_DISTANCE
|
File diff suppressed because it is too large
Load diff
|
@ -1,504 +0,0 @@
|
|||
evdev_init_buttons
|
||||
KEY_RESERVED RESERVED
|
||||
KEY_ESC ESC
|
||||
KEY_1 1
|
||||
KEY_2 2
|
||||
KEY_3 3
|
||||
KEY_4 4
|
||||
KEY_5 5
|
||||
KEY_6 6
|
||||
KEY_7 7
|
||||
KEY_8 8
|
||||
KEY_9 9
|
||||
KEY_0 0
|
||||
KEY_MINUS MINUS
|
||||
KEY_EQUAL EQUAL
|
||||
KEY_BACKSPACE BACKSPACE
|
||||
KEY_TAB TAB
|
||||
KEY_Q Q
|
||||
KEY_W W
|
||||
KEY_E E
|
||||
KEY_R R
|
||||
KEY_T T
|
||||
KEY_Y Y
|
||||
KEY_U U
|
||||
KEY_I I
|
||||
KEY_O O
|
||||
KEY_P P
|
||||
KEY_LEFTBRACE LEFTBRACE
|
||||
KEY_RIGHTBRACE RIGHTBRACE
|
||||
KEY_ENTER ENTER
|
||||
KEY_LEFTCTRL LEFTCTRL
|
||||
KEY_A A
|
||||
KEY_S S
|
||||
KEY_D D
|
||||
KEY_F F
|
||||
KEY_G G
|
||||
KEY_H H
|
||||
KEY_J J
|
||||
KEY_K K
|
||||
KEY_L L
|
||||
KEY_SEMICOLON SEMICOLON
|
||||
KEY_APOSTROPHE APOSTROPHE
|
||||
KEY_GRAVE GRAVE
|
||||
KEY_LEFTSHIFT LEFTSHIFT
|
||||
KEY_BACKSLASH BACKSLASH
|
||||
KEY_Z Z
|
||||
KEY_X X
|
||||
KEY_C C
|
||||
KEY_V V
|
||||
KEY_B B
|
||||
KEY_N N
|
||||
KEY_M M
|
||||
KEY_COMMA COMMA
|
||||
KEY_DOT DOT
|
||||
KEY_SLASH SLASH
|
||||
KEY_RIGHTSHIFT RIGHTSHIFT
|
||||
KEY_KPASTERISK KPASTERISK
|
||||
KEY_LEFTALT LEFTALT
|
||||
KEY_SPACE SPACE
|
||||
KEY_CAPSLOCK CAPSLOCK
|
||||
KEY_F1 F1
|
||||
KEY_F2 F2
|
||||
KEY_F3 F3
|
||||
KEY_F4 F4
|
||||
KEY_F5 F5
|
||||
KEY_F6 F6
|
||||
KEY_F7 F7
|
||||
KEY_F8 F8
|
||||
KEY_F9 F9
|
||||
KEY_F10 F10
|
||||
KEY_NUMLOCK NUMLOCK
|
||||
KEY_SCROLLLOCK SCROLLLOCK
|
||||
KEY_KP7 KP7
|
||||
KEY_KP8 KP8
|
||||
KEY_KP9 KP9
|
||||
KEY_KPMINUS KPMINUS
|
||||
KEY_KP4 KP4
|
||||
KEY_KP5 KP5
|
||||
KEY_KP6 KP6
|
||||
KEY_KPPLUS KPPLUS
|
||||
KEY_KP1 KP1
|
||||
KEY_KP2 KP2
|
||||
KEY_KP3 KP3
|
||||
KEY_KP0 KP0
|
||||
KEY_KPDOT KPDOT
|
||||
KEY_ZENKAKUHANKAKU ZENKAKUHANKAKU
|
||||
KEY_102ND 102ND
|
||||
KEY_F11 F11
|
||||
KEY_F12 F12
|
||||
KEY_RO RO
|
||||
KEY_KATAKANA KATAKANA
|
||||
KEY_HIRAGANA HIRAGANA
|
||||
KEY_HENKAN HENKAN
|
||||
KEY_KATAKANAHIRAGANA KATAKANAHIRAGANA
|
||||
KEY_MUHENKAN MUHENKAN
|
||||
KEY_KPJPCOMMA KPJPCOMMA
|
||||
KEY_KPENTER KPENTER
|
||||
KEY_RIGHTCTRL RIGHTCTRL
|
||||
KEY_KPSLASH KPSLASH
|
||||
KEY_SYSRQ SYSRQ
|
||||
KEY_RIGHTALT RIGHTALT
|
||||
KEY_LINEFEED LINEFEED
|
||||
KEY_HOME HOME
|
||||
KEY_UP UP
|
||||
KEY_PAGEUP PAGEUP
|
||||
KEY_LEFT LEFT
|
||||
KEY_RIGHT RIGHT
|
||||
KEY_END END
|
||||
KEY_DOWN DOWN
|
||||
KEY_PAGEDOWN PAGEDOWN
|
||||
KEY_INSERT INSERT
|
||||
KEY_DELETE DELETE
|
||||
KEY_MACRO MACRO
|
||||
KEY_MUTE MUTE
|
||||
KEY_VOLUMEDOWN VOLUMEDOWN
|
||||
KEY_VOLUMEUP VOLUMEUP
|
||||
KEY_POWER POWER
|
||||
KEY_KPEQUAL KPEQUAL
|
||||
KEY_KPPLUSMINUS KPPLUSMINUS
|
||||
KEY_PAUSE PAUSE
|
||||
KEY_SCALE SCALE
|
||||
KEY_KPCOMMA KPCOMMA
|
||||
KEY_HANGEUL HANGEUL
|
||||
KEY_HANGUEL HANGUEL
|
||||
KEY_HANJA HANJA
|
||||
KEY_YEN YEN
|
||||
KEY_LEFTMETA LEFTMETA
|
||||
KEY_RIGHTMETA RIGHTMETA
|
||||
KEY_COMPOSE COMPOSE
|
||||
KEY_STOP STOP
|
||||
KEY_AGAIN AGAIN
|
||||
KEY_PROPS PROPS
|
||||
KEY_UNDO UNDO
|
||||
KEY_FRONT FRONT
|
||||
KEY_COPY COPY
|
||||
KEY_OPEN OPEN
|
||||
KEY_PASTE PASTE
|
||||
KEY_FIND FIND
|
||||
KEY_CUT CUT
|
||||
KEY_HELP HELP
|
||||
KEY_MENU MENU
|
||||
KEY_CALC CALC
|
||||
KEY_SETUP SETUP
|
||||
KEY_SLEEP SLEEP
|
||||
KEY_WAKEUP WAKEUP
|
||||
KEY_FILE FILE
|
||||
KEY_SENDFILE SENDFILE
|
||||
KEY_DELETEFILE DELETEFILE
|
||||
KEY_XFER XFER
|
||||
KEY_PROG1 PROG1
|
||||
KEY_PROG2 PROG2
|
||||
KEY_WWW WWW
|
||||
KEY_MSDOS MSDOS
|
||||
KEY_COFFEE COFFEE
|
||||
KEY_SCREENLOCK SCREENLOCK
|
||||
KEY_DIRECTION DIRECTION
|
||||
KEY_CYCLEWINDOWS CYCLEWINDOWS
|
||||
KEY_MAIL MAIL
|
||||
KEY_BOOKMARKS BOOKMARKS
|
||||
KEY_COMPUTER COMPUTER
|
||||
KEY_BACK BACK
|
||||
KEY_FORWARD FORWARD
|
||||
KEY_CLOSECD CLOSECD
|
||||
KEY_EJECTCD EJECTCD
|
||||
KEY_EJECTCLOSECD EJECTCLOSECD
|
||||
KEY_NEXTSONG NEXTSONG
|
||||
KEY_PLAYPAUSE PLAYPAUSE
|
||||
KEY_PREVIOUSSONG PREVIOUSSONG
|
||||
KEY_STOPCD STOPCD
|
||||
KEY_RECORD RECORD
|
||||
KEY_REWIND REWIND
|
||||
KEY_PHONE PHONE
|
||||
KEY_ISO ISO
|
||||
KEY_CONFIG CONFIG
|
||||
KEY_HOMEPAGE HOMEPAGE
|
||||
KEY_REFRESH REFRESH
|
||||
KEY_EXIT EXIT
|
||||
KEY_MOVE MOVE
|
||||
KEY_EDIT EDIT
|
||||
KEY_SCROLLUP SCROLLUP
|
||||
KEY_SCROLLDOWN SCROLLDOWN
|
||||
KEY_KPLEFTPAREN KPLEFTPAREN
|
||||
KEY_KPRIGHTPAREN KPRIGHTPAREN
|
||||
KEY_NEW NEW
|
||||
KEY_REDO REDO
|
||||
KEY_F13 F13
|
||||
KEY_F14 F14
|
||||
KEY_F15 F15
|
||||
KEY_F16 F16
|
||||
KEY_F17 F17
|
||||
KEY_F18 F18
|
||||
KEY_F19 F19
|
||||
KEY_F20 F20
|
||||
KEY_F21 F21
|
||||
KEY_F22 F22
|
||||
KEY_F23 F23
|
||||
KEY_F24 F24
|
||||
KEY_PLAYCD PLAYCD
|
||||
KEY_PAUSECD PAUSECD
|
||||
KEY_PROG3 PROG3
|
||||
KEY_PROG4 PROG4
|
||||
KEY_DASHBOARD DASHBOARD
|
||||
KEY_SUSPEND SUSPEND
|
||||
KEY_CLOSE CLOSE
|
||||
KEY_PLAY PLAY
|
||||
KEY_FASTFORWARD FASTFORWARD
|
||||
KEY_BASSBOOST BASSBOOST
|
||||
KEY_PRINT PRINT
|
||||
KEY_HP HP
|
||||
KEY_CAMERA CAMERA
|
||||
KEY_SOUND SOUND
|
||||
KEY_QUESTION QUESTION
|
||||
KEY_EMAIL EMAIL
|
||||
KEY_CHAT CHAT
|
||||
KEY_SEARCH SEARCH
|
||||
KEY_CONNECT CONNECT
|
||||
KEY_FINANCE FINANCE
|
||||
KEY_SPORT SPORT
|
||||
KEY_SHOP SHOP
|
||||
KEY_ALTERASE ALTERASE
|
||||
KEY_CANCEL CANCEL
|
||||
KEY_BRIGHTNESSDOWN BRIGHTNESSDOWN
|
||||
KEY_BRIGHTNESSUP BRIGHTNESSUP
|
||||
KEY_MEDIA MEDIA
|
||||
KEY_SWITCHVIDEOMODE SWITCHVIDEOMODE
|
||||
KEY_KBDILLUMTOGGLE KBDILLUMTOGGLE
|
||||
KEY_KBDILLUMDOWN KBDILLUMDOWN
|
||||
KEY_KBDILLUMUP KBDILLUMUP
|
||||
KEY_SEND SEND
|
||||
KEY_REPLY REPLY
|
||||
KEY_FORWARDMAIL FORWARDMAIL
|
||||
KEY_SAVE SAVE
|
||||
KEY_DOCUMENTS DOCUMENTS
|
||||
KEY_BATTERY BATTERY
|
||||
KEY_BLUETOOTH BLUETOOTH
|
||||
KEY_WLAN WLAN
|
||||
KEY_UWB UWB
|
||||
KEY_UNKNOWN UNKNOWN
|
||||
KEY_VIDEO_NEXT VIDEO_NEXT
|
||||
KEY_VIDEO_PREV VIDEO_PREV
|
||||
KEY_BRIGHTNESS_CYCLE BRIGHTNESS_CYCLE
|
||||
KEY_BRIGHTNESS_ZERO BRIGHTNESS_ZERO
|
||||
KEY_DISPLAY_OFF DISPLAY_OFF
|
||||
KEY_WIMAX WIMAX
|
||||
KEY_RFKILL RFKILL
|
||||
KEY_MICMUTE MICMUTE
|
||||
BTN_MISC Button MISC
|
||||
BTN_0 Button 0
|
||||
BTN_1 Button 1
|
||||
BTN_2 Button 2
|
||||
BTN_3 Button 3
|
||||
BTN_4 Button 4
|
||||
BTN_5 Button 5
|
||||
BTN_6 Button 6
|
||||
BTN_7 Button 7
|
||||
BTN_8 Button 8
|
||||
BTN_9 Button 9
|
||||
BTN_MOUSE Button MOUSE
|
||||
BTN_LEFT Button LEFT
|
||||
BTN_RIGHT Button RIGHT
|
||||
BTN_MIDDLE Button MIDDLE
|
||||
BTN_SIDE Button SIDE
|
||||
BTN_EXTRA Button EXTRA
|
||||
BTN_FORWARD Button FORWARD
|
||||
BTN_BACK Button BACK
|
||||
BTN_TASK Button TASK
|
||||
BTN_JOYSTICK Button JOYSTICK
|
||||
BTN_TRIGGER Button TRIGGER
|
||||
BTN_THUMB Button THUMB
|
||||
BTN_THUMB2 Button THUMB2
|
||||
BTN_TOP Button TOP
|
||||
BTN_TOP2 Button TOP2
|
||||
BTN_PINKIE Button PINKIE
|
||||
BTN_BASE Button BASE
|
||||
BTN_BASE2 Button BASE2
|
||||
BTN_BASE3 Button BASE3
|
||||
BTN_BASE4 Button BASE4
|
||||
BTN_BASE5 Button BASE5
|
||||
BTN_BASE6 Button BASE6
|
||||
BTN_DEAD Button DEAD
|
||||
BTN_GAMEPAD Button GAMEPAD
|
||||
BTN_A Button A
|
||||
BTN_B Button B
|
||||
BTN_C Button C
|
||||
BTN_X Button X
|
||||
BTN_Y Button Y
|
||||
BTN_Z Button Z
|
||||
BTN_TL Button TL
|
||||
BTN_TR Button TR
|
||||
BTN_TL2 Button TL2
|
||||
BTN_TR2 Button TR2
|
||||
BTN_SELECT Button SELECT
|
||||
BTN_START Button START
|
||||
BTN_MODE Button MODE
|
||||
BTN_THUMBL Button THUMBL
|
||||
BTN_THUMBR Button THUMBR
|
||||
BTN_DIGI Button DIGI
|
||||
BTN_TOOL_PEN Button TOOL_PEN
|
||||
BTN_TOOL_RUBBER Button TOOL_RUBBER
|
||||
BTN_TOOL_BRUSH Button TOOL_BRUSH
|
||||
BTN_TOOL_PENCIL Button TOOL_PENCIL
|
||||
BTN_TOOL_AIRBRUSH Button TOOL_AIRBRUSH
|
||||
BTN_TOOL_FINGER Button TOOL_FINGER
|
||||
BTN_TOOL_MOUSE Button TOOL_MOUSE
|
||||
BTN_TOOL_LENS Button TOOL_LENS
|
||||
BTN_TOUCH Button TOUCH
|
||||
BTN_STYLUS Button STYLUS
|
||||
BTN_STYLUS2 Button STYLUS2
|
||||
BTN_TOOL_DOUBLETAP Button TOOL_DOUBLETAP
|
||||
BTN_TOOL_TRIPLETAP Button TOOL_TRIPLETAP
|
||||
BTN_TOOL_QUADTAP Button TOOL_QUADTAP
|
||||
BTN_WHEEL Button WHEEL
|
||||
BTN_GEAR_DOWN Button GEAR_DOWN
|
||||
BTN_GEAR_UP Button GEAR_UP
|
||||
KEY_OK OK
|
||||
KEY_SELECT SELECT
|
||||
KEY_GOTO GOTO
|
||||
KEY_CLEAR CLEAR
|
||||
KEY_POWER2 POWER2
|
||||
KEY_OPTION OPTION
|
||||
KEY_INFO INFO
|
||||
KEY_TIME TIME
|
||||
KEY_VENDOR VENDOR
|
||||
KEY_ARCHIVE ARCHIVE
|
||||
KEY_PROGRAM PROGRAM
|
||||
KEY_CHANNEL CHANNEL
|
||||
KEY_FAVORITES FAVORITES
|
||||
KEY_EPG EPG
|
||||
KEY_PVR PVR
|
||||
KEY_MHP MHP
|
||||
KEY_LANGUAGE LANGUAGE
|
||||
KEY_TITLE TITLE
|
||||
KEY_SUBTITLE SUBTITLE
|
||||
KEY_ANGLE ANGLE
|
||||
KEY_ZOOM ZOOM
|
||||
KEY_MODE MODE
|
||||
KEY_KEYBOARD KEYBOARD
|
||||
KEY_SCREEN SCREEN
|
||||
KEY_PC PC
|
||||
KEY_TV TV
|
||||
KEY_TV2 TV2
|
||||
KEY_VCR VCR
|
||||
KEY_VCR2 VCR2
|
||||
KEY_SAT SAT
|
||||
KEY_SAT2 SAT2
|
||||
KEY_CD CD
|
||||
KEY_TAPE TAPE
|
||||
KEY_RADIO RADIO
|
||||
KEY_TUNER TUNER
|
||||
KEY_PLAYER PLAYER
|
||||
KEY_TEXT TEXT
|
||||
KEY_DVD DVD
|
||||
KEY_AUX AUX
|
||||
KEY_MP3 MP3
|
||||
KEY_AUDIO AUDIO
|
||||
KEY_VIDEO VIDEO
|
||||
KEY_DIRECTORY DIRECTORY
|
||||
KEY_LIST LIST
|
||||
KEY_MEMO MEMO
|
||||
KEY_CALENDAR CALENDAR
|
||||
KEY_RED RED
|
||||
KEY_GREEN GREEN
|
||||
KEY_YELLOW YELLOW
|
||||
KEY_BLUE BLUE
|
||||
KEY_CHANNELUP CHANNELUP
|
||||
KEY_CHANNELDOWN CHANNELDOWN
|
||||
KEY_FIRST FIRST
|
||||
KEY_LAST LAST
|
||||
KEY_AB AB
|
||||
KEY_NEXT NEXT
|
||||
KEY_RESTART RESTART
|
||||
KEY_SLOW SLOW
|
||||
KEY_SHUFFLE SHUFFLE
|
||||
KEY_BREAK BREAK
|
||||
KEY_PREVIOUS PREVIOUS
|
||||
KEY_DIGITS DIGITS
|
||||
KEY_TEEN TEEN
|
||||
KEY_TWEN TWEN
|
||||
KEY_VIDEOPHONE VIDEOPHONE
|
||||
KEY_GAMES GAMES
|
||||
KEY_ZOOMIN ZOOMIN
|
||||
KEY_ZOOMOUT ZOOMOUT
|
||||
KEY_ZOOMRESET ZOOMRESET
|
||||
KEY_WORDPROCESSOR WORDPROCESSOR
|
||||
KEY_EDITOR EDITOR
|
||||
KEY_SPREADSHEET SPREADSHEET
|
||||
KEY_GRAPHICSEDITOR GRAPHICSEDITOR
|
||||
KEY_PRESENTATION PRESENTATION
|
||||
KEY_DATABASE DATABASE
|
||||
KEY_NEWS NEWS
|
||||
KEY_VOICEMAIL VOICEMAIL
|
||||
KEY_ADDRESSBOOK ADDRESSBOOK
|
||||
KEY_MESSENGER MESSENGER
|
||||
KEY_DISPLAYTOGGLE DISPLAYTOGGLE
|
||||
KEY_SPELLCHECK SPELLCHECK
|
||||
KEY_LOGOFF LOGOFF
|
||||
KEY_DOLLAR DOLLAR
|
||||
KEY_EURO EURO
|
||||
KEY_FRAMEBACK FRAMEBACK
|
||||
KEY_FRAMEFORWARD FRAMEFORWARD
|
||||
KEY_CONTEXT_MENU CONTEXT_MENU
|
||||
KEY_MEDIA_REPEAT MEDIA_REPEAT
|
||||
KEY_10CHANNELSUP 10CHANNELSUP
|
||||
KEY_10CHANNELSDOWN 10CHANNELSDOWN
|
||||
KEY_IMAGES IMAGES
|
||||
KEY_DEL_EOL DEL_EOL
|
||||
KEY_DEL_EOS DEL_EOS
|
||||
KEY_INS_LINE INS_LINE
|
||||
KEY_DEL_LINE DEL_LINE
|
||||
KEY_FN FN
|
||||
KEY_FN_ESC FN_ESC
|
||||
KEY_FN_F1 FN_F1
|
||||
KEY_FN_F2 FN_F2
|
||||
KEY_FN_F3 FN_F3
|
||||
KEY_FN_F4 FN_F4
|
||||
KEY_FN_F5 FN_F5
|
||||
KEY_FN_F6 FN_F6
|
||||
KEY_FN_F7 FN_F7
|
||||
KEY_FN_F8 FN_F8
|
||||
KEY_FN_F9 FN_F9
|
||||
KEY_FN_F10 FN_F10
|
||||
KEY_FN_F11 FN_F11
|
||||
KEY_FN_F12 FN_F12
|
||||
KEY_FN_1 FN_1
|
||||
KEY_FN_2 FN_2
|
||||
KEY_FN_D FN_D
|
||||
KEY_FN_E FN_E
|
||||
KEY_FN_F FN_F
|
||||
KEY_FN_S FN_S
|
||||
KEY_FN_B FN_B
|
||||
KEY_BRL_DOT1 BRL_DOT1
|
||||
KEY_BRL_DOT2 BRL_DOT2
|
||||
KEY_BRL_DOT3 BRL_DOT3
|
||||
KEY_BRL_DOT4 BRL_DOT4
|
||||
KEY_BRL_DOT5 BRL_DOT5
|
||||
KEY_BRL_DOT6 BRL_DOT6
|
||||
KEY_BRL_DOT7 BRL_DOT7
|
||||
KEY_BRL_DOT8 BRL_DOT8
|
||||
KEY_BRL_DOT9 BRL_DOT9
|
||||
KEY_BRL_DOT10 BRL_DOT10
|
||||
KEY_NUMERIC_0 NUMERIC_0
|
||||
KEY_NUMERIC_1 NUMERIC_1
|
||||
KEY_NUMERIC_2 NUMERIC_2
|
||||
KEY_NUMERIC_3 NUMERIC_3
|
||||
KEY_NUMERIC_4 NUMERIC_4
|
||||
KEY_NUMERIC_5 NUMERIC_5
|
||||
KEY_NUMERIC_6 NUMERIC_6
|
||||
KEY_NUMERIC_7 NUMERIC_7
|
||||
KEY_NUMERIC_8 NUMERIC_8
|
||||
KEY_NUMERIC_9 NUMERIC_9
|
||||
KEY_NUMERIC_STAR NUMERIC_STAR
|
||||
KEY_NUMERIC_POUND NUMERIC_POUND
|
||||
KEY_CAMERA_FOCUS CAMERA_FOCUS
|
||||
KEY_WPS_BUTTON WPS_BUTTON
|
||||
KEY_TOUCHPAD_TOGGLE TOUCHPAD_TOGGLE
|
||||
KEY_TOUCHPAD_ON TOUCHPAD_ON
|
||||
KEY_TOUCHPAD_OFF TOUCHPAD_OFF
|
||||
KEY_CAMERA_ZOOMIN CAMERA_ZOOMIN
|
||||
KEY_CAMERA_ZOOMOUT CAMERA_ZOOMOUT
|
||||
KEY_CAMERA_UP CAMERA_UP
|
||||
KEY_CAMERA_DOWN CAMERA_DOWN
|
||||
KEY_CAMERA_LEFT CAMERA_LEFT
|
||||
KEY_CAMERA_RIGHT CAMERA_RIGHT
|
||||
BTN_TRIGGER_HAPPY Button TRIGGER_HAPPY
|
||||
BTN_TRIGGER_HAPPY1 Button TRIGGER_HAPPY1
|
||||
BTN_TRIGGER_HAPPY2 Button TRIGGER_HAPPY2
|
||||
BTN_TRIGGER_HAPPY3 Button TRIGGER_HAPPY3
|
||||
BTN_TRIGGER_HAPPY4 Button TRIGGER_HAPPY4
|
||||
BTN_TRIGGER_HAPPY5 Button TRIGGER_HAPPY5
|
||||
BTN_TRIGGER_HAPPY6 Button TRIGGER_HAPPY6
|
||||
BTN_TRIGGER_HAPPY7 Button TRIGGER_HAPPY7
|
||||
BTN_TRIGGER_HAPPY8 Button TRIGGER_HAPPY8
|
||||
BTN_TRIGGER_HAPPY9 Button TRIGGER_HAPPY9
|
||||
BTN_TRIGGER_HAPPY10 Button TRIGGER_HAPPY10
|
||||
BTN_TRIGGER_HAPPY11 Button TRIGGER_HAPPY11
|
||||
BTN_TRIGGER_HAPPY12 Button TRIGGER_HAPPY12
|
||||
BTN_TRIGGER_HAPPY13 Button TRIGGER_HAPPY13
|
||||
BTN_TRIGGER_HAPPY14 Button TRIGGER_HAPPY14
|
||||
BTN_TRIGGER_HAPPY15 Button TRIGGER_HAPPY15
|
||||
BTN_TRIGGER_HAPPY16 Button TRIGGER_HAPPY16
|
||||
BTN_TRIGGER_HAPPY17 Button TRIGGER_HAPPY17
|
||||
BTN_TRIGGER_HAPPY18 Button TRIGGER_HAPPY18
|
||||
BTN_TRIGGER_HAPPY19 Button TRIGGER_HAPPY19
|
||||
BTN_TRIGGER_HAPPY20 Button TRIGGER_HAPPY20
|
||||
BTN_TRIGGER_HAPPY21 Button TRIGGER_HAPPY21
|
||||
BTN_TRIGGER_HAPPY22 Button TRIGGER_HAPPY22
|
||||
BTN_TRIGGER_HAPPY23 Button TRIGGER_HAPPY23
|
||||
BTN_TRIGGER_HAPPY24 Button TRIGGER_HAPPY24
|
||||
BTN_TRIGGER_HAPPY25 Button TRIGGER_HAPPY25
|
||||
BTN_TRIGGER_HAPPY26 Button TRIGGER_HAPPY26
|
||||
BTN_TRIGGER_HAPPY27 Button TRIGGER_HAPPY27
|
||||
BTN_TRIGGER_HAPPY28 Button TRIGGER_HAPPY28
|
||||
BTN_TRIGGER_HAPPY29 Button TRIGGER_HAPPY29
|
||||
BTN_TRIGGER_HAPPY30 Button TRIGGER_HAPPY30
|
||||
BTN_TRIGGER_HAPPY31 Button TRIGGER_HAPPY31
|
||||
BTN_TRIGGER_HAPPY32 Button TRIGGER_HAPPY32
|
||||
BTN_TRIGGER_HAPPY33 Button TRIGGER_HAPPY33
|
||||
BTN_TRIGGER_HAPPY34 Button TRIGGER_HAPPY34
|
||||
BTN_TRIGGER_HAPPY35 Button TRIGGER_HAPPY35
|
||||
BTN_TRIGGER_HAPPY36 Button TRIGGER_HAPPY36
|
||||
BTN_TRIGGER_HAPPY37 Button TRIGGER_HAPPY37
|
||||
BTN_TRIGGER_HAPPY38 Button TRIGGER_HAPPY38
|
||||
BTN_TRIGGER_HAPPY39 Button TRIGGER_HAPPY39
|
||||
BTN_TRIGGER_HAPPY40 Button TRIGGER_HAPPY40
|
|
@ -1,7 +1,8 @@
|
|||
#include "core/command.hpp"
|
||||
#include "core/keymapper.hpp"
|
||||
#include "core/joystick.hpp"
|
||||
#include "core/window.hpp"
|
||||
#include "library/joyfun.hpp"
|
||||
#include "library/string.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <map>
|
||||
|
@ -19,219 +20,171 @@ extern "C"
|
|||
#include <linux/input.h>
|
||||
}
|
||||
|
||||
extern void evdev_init_buttons(const char** x);
|
||||
extern void evdev_init_axes(const char** x);
|
||||
|
||||
namespace
|
||||
{
|
||||
const char* axisnames[ABS_MAX + 1] = {0};
|
||||
const char* buttonnames[KEY_MAX + 1] = {0};
|
||||
|
||||
enum event_type
|
||||
{
|
||||
ET_BUTTON,
|
||||
ET_AXIS,
|
||||
ET_HAT_X,
|
||||
ET_HAT_Y
|
||||
const char* axisnames[64] = {
|
||||
"X", "Y", "Z", "RX", "RY", "RZ", "THROTTLE", "RUDDER", "WHEEL", "GAS", "BRAKE", "Unknown axis #11",
|
||||
"Unknown axis #12", "Unknown axis #13", "Unknown axis #14", "Unknown axis #15", "HAT0X", "HAT0Y",
|
||||
"HAT1X", "HAT1Y", "HAT2X", "HAT2Y", "HAT3X", "HAT3Y", "PRESSURE", "DISTANCE", "TILT_X", "TILT_Y",
|
||||
"TOOL_WIDTH", "Unknown axis #29", "Unknown axis #30", "Unknown axis #31", "VOLUME", "Unknown axis #33",
|
||||
"Unknown axis #34", "Unknown axis #35", "Unknown axis #36", "Unknown axis #37", "Unknown axis #38",
|
||||
"Unknown axis #39", "MISC", "Unknown axis #41", "Unknown axis #42", "Unknown axis #43",
|
||||
"Unknown axis #44", "Unknown axis #45", "Unknown axis #46", "MT_SLOT", "MT_TOUCH_MAJOR",
|
||||
"MT_TOUCH_MINOR", "MT_WIDTH_MAJOR", "MT_WIDTH_MINOR", "MT_ORIENTATION", "MT_POSITION_X",
|
||||
"MT_POSITION_Y", "MT_TOOL_TYPE", "MT_BLOB_ID", "MT_TRACKING_ID", "MT_PRESSURE", "MT_DISTANCE",
|
||||
"Unknown axis #60", "Unknown axis #61", "Unknown axis #62", "Unknown axis #63"
|
||||
};
|
||||
const char* buttonnames[768] = {
|
||||
"RESERVED", "ESC", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "MINUS", "EQUAL", "BACKSPACE",
|
||||
"TAB", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "LEFTBRACE", "RIGHTBRACE", "ENTER",
|
||||
"LEFTCTRL", "A", "S", "D", "F", "G", "H", "J", "K", "L", "SEMICOLON", "APOSTROPHE", "GRAVE",
|
||||
"LEFTSHIFT", "BACKSLASH", "Z", "X", "C", "V", "B", "N", "M", "COMMA", "DOT", "SLASH", "RIGHTSHIFT",
|
||||
"KPASTERISK", "LEFTALT", "SPACE", "CAPSLOCK", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9",
|
||||
"F10", "NUMLOCK", "SCROLLLOCK", "KP7", "KP8", "KP9", "KPMINUS", "KP4", "KP5", "KP6", "KPPLUS", "KP1",
|
||||
"KP2", "KP3", "KP0", "KPDOT", "Unknown button #84", "ZENKAKUHANKAKU", "102ND", "F11", "F12", "RO",
|
||||
"KATAKANA", "HIRAGANA", "HENKAN", "KATAKANAHIRAGANA", "MUHENKAN", "KPJPCOMMA", "KPENTER", "RIGHTCTRL",
|
||||
"KPSLASH", "SYSRQ", "RIGHTALT", "LINEFEED", "HOME", "UP", "PAGEUP", "LEFT", "RIGHT", "END", "DOWN",
|
||||
"PAGEDOWN", "INSERT", "DELETE", "MACRO", "MUTE", "VOLUMEDOWN", "VOLUMEUP", "POWER", "KPEQUAL",
|
||||
"KPPLUSMINUS", "PAUSE", "SCALE", "KPCOMMA", "HANGUEL", "HANJA", "YEN", "LEFTMETA", "RIGHTMETA",
|
||||
"COMPOSE", "STOP", "AGAIN", "PROPS", "UNDO", "FRONT", "COPY", "OPEN", "PASTE", "FIND", "CUT", "HELP",
|
||||
"MENU", "CALC", "SETUP", "SLEEP", "WAKEUP", "FILE", "SENDFILE", "DELETEFILE", "XFER", "PROG1", "PROG2",
|
||||
"WWW", "MSDOS", "SCREENLOCK", "DIRECTION", "CYCLEWINDOWS", "MAIL", "BOOKMARKS", "COMPUTER", "BACK",
|
||||
"FORWARD", "CLOSECD", "EJECTCD", "EJECTCLOSECD", "NEXTSONG", "PLAYPAUSE", "PREVIOUSSONG", "STOPCD",
|
||||
"RECORD", "REWIND", "PHONE", "ISO", "CONFIG", "HOMEPAGE", "REFRESH", "EXIT", "MOVE", "EDIT",
|
||||
"SCROLLUP", "SCROLLDOWN", "KPLEFTPAREN", "KPRIGHTPAREN", "NEW", "REDO", "F13", "F14", "F15", "F16",
|
||||
"F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", "Unknown button #195", "Unknown button #196",
|
||||
"Unknown button #197", "Unknown button #198", "Unknown button #199", "PLAYCD", "PAUSECD", "PROG3",
|
||||
"PROG4", "DASHBOARD", "SUSPEND", "CLOSE", "PLAY", "FASTFORWARD", "BASSBOOST", "PRINT", "HP", "CAMERA",
|
||||
"SOUND", "QUESTION", "EMAIL", "CHAT", "SEARCH", "CONNECT", "FINANCE", "SPORT", "SHOP", "ALTERASE",
|
||||
"CANCEL", "BRIGHTNESSDOWN", "BRIGHTNESSUP", "MEDIA", "SWITCHVIDEOMODE", "KBDILLUMTOGGLE",
|
||||
"KBDILLUMDOWN", "KBDILLUMUP", "SEND", "REPLY", "FORWARDMAIL", "SAVE", "DOCUMENTS", "BATTERY",
|
||||
"BLUETOOTH", "WLAN", "UWB", "UNKNOWN", "VIDEO_NEXT", "VIDEO_PREV", "BRIGHTNESS_CYCLE",
|
||||
"BRIGHTNESS_ZERO", "DISPLAY_OFF", "WIMAX", "RFKILL", "MICMUTE", "Unknown button #249",
|
||||
"Unknown button #250", "Unknown button #251", "Unknown button #252", "Unknown button #253",
|
||||
"Unknown button #254", "Unknown button #255", "Button 0", "Button 1", "Button 2", "Button 3",
|
||||
"Button 4", "Button 5", "Button 6", "Button 7", "Button 8", "Button 9", "Unknown button #266",
|
||||
"Unknown button #267", "Unknown button #268", "Unknown button #269", "Unknown button #270",
|
||||
"Unknown button #271", "Button LEFT", "Button RIGHT", "Button MIDDLE", "Button SIDE", "Button EXTRA",
|
||||
"Button FORWARD", "Button BACK", "Button TASK", "Unknown button #280", "Unknown button #281",
|
||||
"Unknown button #282", "Unknown button #283", "Unknown button #284", "Unknown button #285",
|
||||
"Unknown button #286", "Unknown button #287", "Button TRIGGER", "Button THUMB", "Button THUMB2",
|
||||
"Button TOP", "Button TOP2", "Button PINKIE", "Button BASE", "Button BASE2", "Button BASE3",
|
||||
"Button BASE4", "Button BASE5", "Button BASE6", "Unknown button #300", "Unknown button #301",
|
||||
"Unknown button #302", "Button DEAD", "Button A", "Button B", "Button C", "Button X", "Button Y",
|
||||
"Button Z", "Button TL", "Button TR", "Button TL2", "Button TR2", "Button SELECT", "Button START",
|
||||
"Button MODE", "Button THUMBL", "Button THUMBR", "Unknown button #319", "Button TOOL_PEN",
|
||||
"Button TOOL_RUBBER", "Button TOOL_BRUSH", "Button TOOL_PENCIL", "Button TOOL_AIRBRUSH",
|
||||
"Button TOOL_FINGER", "Button TOOL_MOUSE", "Button TOOL_LENS", "Button TOOL_QUINTTAP",
|
||||
"Unknown button #329", "Button TOUCH", "Button STYLUS", "Button STYLUS2", "Button TOOL_DOUBLETAP",
|
||||
"Button TOOL_TRIPLETAP", "Button TOOL_QUADTAP", "Button GEAR_DOWN", "Button GEAR_UP",
|
||||
"Unknown button #338", "Unknown button #339", "Unknown button #340", "Unknown button #341",
|
||||
"Unknown button #342", "Unknown button #343", "Unknown button #344", "Unknown button #345",
|
||||
"Unknown button #346", "Unknown button #347", "Unknown button #348", "Unknown button #349",
|
||||
"Unknown button #350", "Unknown button #351", "OK", "SELECT", "GOTO", "CLEAR", "POWER2", "OPTION",
|
||||
"INFO", "TIME", "VENDOR", "ARCHIVE", "PROGRAM", "CHANNEL", "FAVORITES", "EPG", "PVR", "MHP",
|
||||
"LANGUAGE", "TITLE", "SUBTITLE", "ANGLE", "ZOOM", "MODE", "KEYBOARD", "SCREEN", "PC", "TV", "TV2",
|
||||
"VCR", "VCR2", "SAT", "SAT2", "CD", "TAPE", "RADIO", "TUNER", "PLAYER", "TEXT", "DVD", "AUX", "MP3",
|
||||
"AUDIO", "VIDEO", "DIRECTORY", "LIST", "MEMO", "CALENDAR", "RED", "GREEN", "YELLOW", "BLUE",
|
||||
"CHANNELUP", "CHANNELDOWN", "FIRST", "LAST", "AB", "NEXT", "RESTART", "SLOW", "SHUFFLE", "BREAK",
|
||||
"PREVIOUS", "DIGITS", "TEEN", "TWEN", "VIDEOPHONE", "GAMES", "ZOOMIN", "ZOOMOUT", "ZOOMRESET",
|
||||
"WORDPROCESSOR", "EDITOR", "SPREADSHEET", "GRAPHICSEDITOR", "PRESENTATION", "DATABASE", "NEWS",
|
||||
"VOICEMAIL", "ADDRESSBOOK", "MESSENGER", "DISPLAYTOGGLE", "SPELLCHECK", "LOGOFF", "DOLLAR", "EURO",
|
||||
"FRAMEBACK", "FRAMEFORWARD", "CONTEXT_MENU", "MEDIA_REPEAT", "10CHANNELSUP", "10CHANNELSDOWN",
|
||||
"IMAGES", "Unknown button #443", "Unknown button #444", "Unknown button #445", "Unknown button #446",
|
||||
"Unknown button #447", "DEL_EOL", "DEL_EOS", "INS_LINE", "DEL_LINE", "Unknown button #452",
|
||||
"Unknown button #453", "Unknown button #454", "Unknown button #455", "Unknown button #456",
|
||||
"Unknown button #457", "Unknown button #458", "Unknown button #459", "Unknown button #460",
|
||||
"Unknown button #461", "Unknown button #462", "Unknown button #463", "FN", "FN_ESC", "FN_F1", "FN_F2",
|
||||
"FN_F3", "FN_F4", "FN_F5", "FN_F6", "FN_F7", "FN_F8", "FN_F9", "FN_F10", "FN_F11", "FN_F12", "FN_1",
|
||||
"FN_2", "FN_D", "FN_E", "FN_F", "FN_S", "FN_B", "Unknown button #485", "Unknown button #486",
|
||||
"Unknown button #487", "Unknown button #488", "Unknown button #489", "Unknown button #490",
|
||||
"Unknown button #491", "Unknown button #492", "Unknown button #493", "Unknown button #494",
|
||||
"Unknown button #495", "Unknown button #496", "BRL_DOT1", "BRL_DOT2", "BRL_DOT3", "BRL_DOT4",
|
||||
"BRL_DOT5", "BRL_DOT6", "BRL_DOT7", "BRL_DOT8", "BRL_DOT9", "BRL_DOT10", "Unknown button #507",
|
||||
"Unknown button #508", "Unknown button #509", "Unknown button #510", "Unknown button #511",
|
||||
"NUMERIC_0", "NUMERIC_1", "NUMERIC_2", "NUMERIC_3", "NUMERIC_4", "NUMERIC_5", "NUMERIC_6", "NUMERIC_7",
|
||||
"NUMERIC_8", "NUMERIC_9", "NUMERIC_STAR", "NUMERIC_POUND", "Unknown button #524",
|
||||
"Unknown button #525", "Unknown button #526", "Unknown button #527", "CAMERA_FOCUS", "WPS_BUTTON",
|
||||
"TOUCHPAD_TOGGLE", "TOUCHPAD_ON", "TOUCHPAD_OFF", "CAMERA_ZOOMIN", "CAMERA_ZOOMOUT", "CAMERA_UP",
|
||||
"CAMERA_DOWN", "CAMERA_LEFT", "CAMERA_RIGHT", "Unknown button #539", "Unknown button #540",
|
||||
"Unknown button #541", "Unknown button #542", "Unknown button #543", "Unknown button #544",
|
||||
"Unknown button #545", "Unknown button #546", "Unknown button #547", "Unknown button #548",
|
||||
"Unknown button #549", "Unknown button #550", "Unknown button #551", "Unknown button #552",
|
||||
"Unknown button #553", "Unknown button #554", "Unknown button #555", "Unknown button #556",
|
||||
"Unknown button #557", "Unknown button #558", "Unknown button #559", "Unknown button #560",
|
||||
"Unknown button #561", "Unknown button #562", "Unknown button #563", "Unknown button #564",
|
||||
"Unknown button #565", "Unknown button #566", "Unknown button #567", "Unknown button #568",
|
||||
"Unknown button #569", "Unknown button #570", "Unknown button #571", "Unknown button #572",
|
||||
"Unknown button #573", "Unknown button #574", "Unknown button #575", "Unknown button #576",
|
||||
"Unknown button #577", "Unknown button #578", "Unknown button #579", "Unknown button #580",
|
||||
"Unknown button #581", "Unknown button #582", "Unknown button #583", "Unknown button #584",
|
||||
"Unknown button #585", "Unknown button #586", "Unknown button #587", "Unknown button #588",
|
||||
"Unknown button #589", "Unknown button #590", "Unknown button #591", "Unknown button #592",
|
||||
"Unknown button #593", "Unknown button #594", "Unknown button #595", "Unknown button #596",
|
||||
"Unknown button #597", "Unknown button #598", "Unknown button #599", "Unknown button #600",
|
||||
"Unknown button #601", "Unknown button #602", "Unknown button #603", "Unknown button #604",
|
||||
"Unknown button #605", "Unknown button #606", "Unknown button #607", "Unknown button #608",
|
||||
"Unknown button #609", "Unknown button #610", "Unknown button #611", "Unknown button #612",
|
||||
"Unknown button #613", "Unknown button #614", "Unknown button #615", "Unknown button #616",
|
||||
"Unknown button #617", "Unknown button #618", "Unknown button #619", "Unknown button #620",
|
||||
"Unknown button #621", "Unknown button #622", "Unknown button #623", "Unknown button #624",
|
||||
"Unknown button #625", "Unknown button #626", "Unknown button #627", "Unknown button #628",
|
||||
"Unknown button #629", "Unknown button #630", "Unknown button #631", "Unknown button #632",
|
||||
"Unknown button #633", "Unknown button #634", "Unknown button #635", "Unknown button #636",
|
||||
"Unknown button #637", "Unknown button #638", "Unknown button #639", "Unknown button #640",
|
||||
"Unknown button #641", "Unknown button #642", "Unknown button #643", "Unknown button #644",
|
||||
"Unknown button #645", "Unknown button #646", "Unknown button #647", "Unknown button #648",
|
||||
"Unknown button #649", "Unknown button #650", "Unknown button #651", "Unknown button #652",
|
||||
"Unknown button #653", "Unknown button #654", "Unknown button #655", "Unknown button #656",
|
||||
"Unknown button #657", "Unknown button #658", "Unknown button #659", "Unknown button #660",
|
||||
"Unknown button #661", "Unknown button #662", "Unknown button #663", "Unknown button #664",
|
||||
"Unknown button #665", "Unknown button #666", "Unknown button #667", "Unknown button #668",
|
||||
"Unknown button #669", "Unknown button #670", "Unknown button #671", "Unknown button #672",
|
||||
"Unknown button #673", "Unknown button #674", "Unknown button #675", "Unknown button #676",
|
||||
"Unknown button #677", "Unknown button #678", "Unknown button #679", "Unknown button #680",
|
||||
"Unknown button #681", "Unknown button #682", "Unknown button #683", "Unknown button #684",
|
||||
"Unknown button #685", "Unknown button #686", "Unknown button #687", "Unknown button #688",
|
||||
"Unknown button #689", "Unknown button #690", "Unknown button #691", "Unknown button #692",
|
||||
"Unknown button #693", "Unknown button #694", "Unknown button #695", "Unknown button #696",
|
||||
"Unknown button #697", "Unknown button #698", "Unknown button #699", "Unknown button #700",
|
||||
"Unknown button #701", "Unknown button #702", "Unknown button #703", "Button TRIGGER_HAPPY1",
|
||||
"Button TRIGGER_HAPPY2", "Button TRIGGER_HAPPY3", "Button TRIGGER_HAPPY4", "Button TRIGGER_HAPPY5",
|
||||
"Button TRIGGER_HAPPY6", "Button TRIGGER_HAPPY7", "Button TRIGGER_HAPPY8", "Button TRIGGER_HAPPY9",
|
||||
"Button TRIGGER_HAPPY10", "Button TRIGGER_HAPPY11", "Button TRIGGER_HAPPY12", "Button TRIGGER_HAPPY13",
|
||||
"Button TRIGGER_HAPPY14", "Button TRIGGER_HAPPY15", "Button TRIGGER_HAPPY16", "Button TRIGGER_HAPPY17",
|
||||
"Button TRIGGER_HAPPY18", "Button TRIGGER_HAPPY19", "Button TRIGGER_HAPPY20", "Button TRIGGER_HAPPY21",
|
||||
"Button TRIGGER_HAPPY22", "Button TRIGGER_HAPPY23", "Button TRIGGER_HAPPY24", "Button TRIGGER_HAPPY25",
|
||||
"Button TRIGGER_HAPPY26", "Button TRIGGER_HAPPY27", "Button TRIGGER_HAPPY28", "Button TRIGGER_HAPPY29",
|
||||
"Button TRIGGER_HAPPY30", "Button TRIGGER_HAPPY31", "Button TRIGGER_HAPPY32", "Button TRIGGER_HAPPY33",
|
||||
"Button TRIGGER_HAPPY34", "Button TRIGGER_HAPPY35", "Button TRIGGER_HAPPY36", "Button TRIGGER_HAPPY37",
|
||||
"Button TRIGGER_HAPPY38", "Button TRIGGER_HAPPY39", "Button TRIGGER_HAPPY40", "Unknown button #744",
|
||||
"Unknown button #745", "Unknown button #746", "Unknown button #747", "Unknown button #748",
|
||||
"Unknown button #749", "Unknown button #750", "Unknown button #751", "Unknown button #752",
|
||||
"Unknown button #753", "Unknown button #754", "Unknown button #755", "Unknown button #756",
|
||||
"Unknown button #757", "Unknown button #758", "Unknown button #759", "Unknown button #760",
|
||||
"Unknown button #761", "Unknown button #762", "Unknown button #763", "Unknown button #764",
|
||||
"Unknown button #765", "Unknown button #766", "Unknown button #767"
|
||||
};
|
||||
|
||||
struct event_mapping
|
||||
std::string get_button_name(uint16_t code)
|
||||
{
|
||||
uint16_t joystick;
|
||||
uint32_t tevcode;
|
||||
enum event_type type;
|
||||
uint16_t controlnum;
|
||||
int32_t axis_min;
|
||||
int32_t axis_max;
|
||||
int32_t current_status;
|
||||
uint32_t paired_mapping; //Only hats.
|
||||
class keygroup* group;
|
||||
};
|
||||
|
||||
struct event_mapping dummy_event_mapping = {
|
||||
9999, //Joystick (don't care).
|
||||
99999, //Tyep&Event code (don't care).
|
||||
ET_BUTTON, //Not really.
|
||||
9999, //Control num (don't care).
|
||||
0, //Axis minimum (don't care).
|
||||
0, //Axis maximum (don't care).
|
||||
0, //Current status (don't care).
|
||||
0, //This is not a hat, so don't care about paired mapping.
|
||||
NULL //No associated key group.
|
||||
};
|
||||
|
||||
std::set<keygroup*> keygroups;
|
||||
std::map<uint64_t, struct event_mapping> event_map;
|
||||
std::map<int, uint16_t> joystick_map;
|
||||
std::set<int> joysticks;
|
||||
std::map<uint16_t, std::string> joystick_names;
|
||||
uint16_t connected_joysticks = 0;
|
||||
|
||||
uint16_t get_joystick_number(int fd)
|
||||
{
|
||||
if(joystick_map.count(fd))
|
||||
return joystick_map[fd];
|
||||
if(code <= sizeof(buttonnames)/sizeof(buttonnames[0]) && buttonnames[code])
|
||||
return buttonnames[code];
|
||||
else
|
||||
return (joystick_map[fd] = connected_joysticks++);
|
||||
return (stringfmt() << "Unknown button #" << code).str();
|
||||
}
|
||||
|
||||
uint64_t get_ev_id(uint16_t joystick, uint16_t type, uint16_t evcode)
|
||||
std::string get_axis_name(uint16_t code)
|
||||
{
|
||||
return (static_cast<uint64_t>(joystick) << 32) |
|
||||
(static_cast<uint64_t>(type) << 16) |
|
||||
static_cast<uint64_t>(evcode);
|
||||
};
|
||||
|
||||
uint64_t get_ev_id(uint16_t joystick, uint32_t tevcode)
|
||||
{
|
||||
return (static_cast<uint64_t>(joystick) << 32) |
|
||||
static_cast<uint64_t>(tevcode);
|
||||
};
|
||||
|
||||
void create_button(int fd, uint16_t type, uint16_t evcode, uint16_t buttonnum)
|
||||
{
|
||||
uint16_t joynum = get_joystick_number(fd);
|
||||
std::ostringstream _name;
|
||||
_name << "joystick" << joynum << "button" << buttonnum;
|
||||
std::string name = _name.str();
|
||||
keygroup* grp = new keygroup(name, "joystick", keygroup::KT_KEY);
|
||||
keygroups.insert(grp);
|
||||
struct event_mapping evmap;
|
||||
evmap.joystick = joynum;
|
||||
evmap.tevcode = (static_cast<uint32_t>(type) << 16) | static_cast<uint32_t>(evcode);
|
||||
evmap.type = ET_BUTTON;
|
||||
evmap.controlnum = buttonnum;
|
||||
evmap.axis_min = evmap.axis_max = 0;
|
||||
evmap.current_status = 0;
|
||||
evmap.paired_mapping = 0;
|
||||
evmap.group = grp;
|
||||
event_map[get_ev_id(joynum, evmap.tevcode)] = evmap;
|
||||
}
|
||||
|
||||
void create_axis(int fd, uint16_t type, uint16_t evcode, uint16_t axisnum, int32_t min, int32_t max)
|
||||
{
|
||||
uint16_t joynum = get_joystick_number(fd);
|
||||
std::ostringstream _name;
|
||||
_name << "joystick" << joynum << "axis" << axisnum;
|
||||
std::string name = _name.str();
|
||||
keygroup* grp;
|
||||
if(min < 0)
|
||||
grp = new keygroup(name, "joystick", keygroup::KT_AXIS_PAIR);
|
||||
if(code <= sizeof(axisnames)/sizeof(axisnames[0]) && axisnames[code])
|
||||
return axisnames[code];
|
||||
else
|
||||
grp = new keygroup(name, "joystick", keygroup::KT_PRESSURE_MP);
|
||||
keygroups.insert(grp);
|
||||
struct event_mapping evmap;
|
||||
evmap.joystick = joynum;
|
||||
evmap.tevcode = (static_cast<uint32_t>(type) << 16) | static_cast<uint32_t>(evcode);
|
||||
evmap.type = ET_AXIS;
|
||||
evmap.controlnum = axisnum;
|
||||
evmap.axis_min = min;
|
||||
evmap.axis_max = max;
|
||||
evmap.current_status = 0;
|
||||
evmap.paired_mapping = 0;
|
||||
evmap.group = grp;
|
||||
event_map[get_ev_id(joynum, evmap.tevcode)] = evmap;
|
||||
}
|
||||
|
||||
void create_hat(int fd, uint16_t type, uint16_t evcodeX, uint16_t evcodeY, uint16_t hatnum)
|
||||
{
|
||||
uint16_t joynum = get_joystick_number(fd);
|
||||
std::ostringstream _name;
|
||||
_name << "joystick" << joynum << "hat" << hatnum;
|
||||
std::string name = _name.str();
|
||||
keygroup* grp = new keygroup(name, "joystick", keygroup::KT_HAT);
|
||||
keygroups.insert(grp);
|
||||
struct event_mapping evmap1;
|
||||
evmap1.joystick = joynum;
|
||||
evmap1.tevcode = (static_cast<uint32_t>(type) << 16) | static_cast<uint32_t>(evcodeX);
|
||||
evmap1.type = ET_HAT_X;
|
||||
evmap1.controlnum = hatnum;
|
||||
evmap1.axis_min = -1;
|
||||
evmap1.axis_max = 1;
|
||||
evmap1.current_status = 0;
|
||||
evmap1.group = grp;
|
||||
struct event_mapping evmap2;
|
||||
evmap2.joystick = joynum;
|
||||
evmap2.tevcode = (static_cast<uint32_t>(type) << 16) | static_cast<uint32_t>(evcodeY);
|
||||
evmap2.type = ET_HAT_Y;
|
||||
evmap2.controlnum = hatnum;
|
||||
evmap2.axis_min = -1;
|
||||
evmap1.axis_max = 1;
|
||||
evmap2.current_status = 0;
|
||||
evmap2.group = grp;
|
||||
evmap1.paired_mapping = get_ev_id(joynum, evmap2.tevcode);
|
||||
evmap2.paired_mapping = get_ev_id(joynum, evmap1.tevcode);
|
||||
event_map[get_ev_id(joynum, evmap1.tevcode)] = evmap1;
|
||||
event_map[get_ev_id(joynum, evmap2.tevcode)] = evmap2;
|
||||
}
|
||||
|
||||
struct event_mapping& get_mapping_for(uint16_t joystick, uint16_t type, uint16_t evcode)
|
||||
{
|
||||
uint64_t evid = get_ev_id(joystick, type, evcode);
|
||||
if(event_map.count(evid))
|
||||
return event_map[evid];
|
||||
else
|
||||
return dummy_event_mapping;
|
||||
}
|
||||
|
||||
struct event_mapping& get_mapping_for(uint16_t joystick, uint32_t tevcode)
|
||||
{
|
||||
uint64_t evid = get_ev_id(joystick, tevcode);
|
||||
if(event_map.count(evid))
|
||||
return event_map[evid];
|
||||
else
|
||||
return dummy_event_mapping;
|
||||
}
|
||||
|
||||
struct event_mapping& get_mapping_for_fd(int fd, uint16_t type, uint16_t evcode)
|
||||
{
|
||||
if(joystick_map.count(fd))
|
||||
return get_mapping_for(joystick_map[fd], type, evcode);
|
||||
else
|
||||
return dummy_event_mapping;
|
||||
}
|
||||
|
||||
void update_mapping_for_fd(int fd, uint16_t type, uint16_t evcode, int32_t value)
|
||||
{
|
||||
struct event_mapping& e = get_mapping_for_fd(fd, type, evcode);
|
||||
e.current_status = value;
|
||||
if(!e.group)
|
||||
return; //Dummy.
|
||||
int16_t v = 0;
|
||||
switch(e.type) {
|
||||
case ET_BUTTON:
|
||||
v = (e.current_status != 0);
|
||||
break;
|
||||
case ET_AXIS:
|
||||
v = calibration_correction(e.current_status, e.axis_min, e.axis_max);
|
||||
break;
|
||||
case ET_HAT_X:
|
||||
case ET_HAT_Y: {
|
||||
uint32_t xaxis, yaxis;
|
||||
if(e.type == ET_HAT_X) {
|
||||
xaxis = get_ev_id(e.joystick, e.tevcode);
|
||||
yaxis = e.paired_mapping;
|
||||
} else {
|
||||
yaxis = get_ev_id(e.joystick, e.tevcode);
|
||||
xaxis = e.paired_mapping;
|
||||
}
|
||||
if(event_map[yaxis].current_status < 0)
|
||||
v |= 1;
|
||||
if(event_map[xaxis].current_status > 0)
|
||||
v |= 2;
|
||||
if(event_map[yaxis].current_status > 0)
|
||||
v |= 4;
|
||||
if(event_map[xaxis].current_status < 0)
|
||||
v |= 8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
platform::queue(keypress(modifier_set(), *e.group, v));
|
||||
//e.group->set_position(v, modifier_set());
|
||||
return (stringfmt() << "Unknown axis #" << code).str();
|
||||
}
|
||||
|
||||
bool read_one_input_event(int fd)
|
||||
{
|
||||
short x;
|
||||
struct input_event ev;
|
||||
int r = read(fd, &ev, sizeof(ev));
|
||||
if(r < 0 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
|
@ -241,7 +194,10 @@ namespace
|
|||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
update_mapping_for_fd(fd, ev.type, ev.code, ev.value);
|
||||
if(ev.type == EV_KEY)
|
||||
joystick_report_button(fd, ev.code, ev.value != 0);
|
||||
if(ev.type == EV_ABS)
|
||||
joystick_report_axis(fd, ev.code, ev.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -283,16 +239,16 @@ namespace
|
|||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
joystick_create(fd, namebuffer);
|
||||
for(unsigned i = 0; i <= KEY_MAX; i++) {
|
||||
if(keys[i / div] & (1ULL << (i % div))) {
|
||||
create_button(fd, EV_KEY, i, button_count++);
|
||||
joystick_new_button(fd, i, get_button_name(i));
|
||||
button_count++;
|
||||
}
|
||||
}
|
||||
for(unsigned i = 0; i <= ABS_MAX; i++) {
|
||||
if(axes[i / div] & (1ULL << (i % div))) {
|
||||
if(i < ABS_HAT0X || i > ABS_HAT3Y) {
|
||||
int32_t min;
|
||||
int32_t max;
|
||||
int32_t V[5];
|
||||
if(ioctl(fd, EVIOCGABS(i), V) < 0) {
|
||||
int merrno = errno;
|
||||
|
@ -300,34 +256,19 @@ namespace
|
|||
<< fd << "): " << strerror(merrno) << std::endl;
|
||||
continue;
|
||||
}
|
||||
min = V[1];
|
||||
max = V[2];
|
||||
create_axis(fd, EV_ABS, i, axis_count++, min, max);
|
||||
joystick_new_axis(fd, i, V[1], V[2], get_axis_name(i),
|
||||
(V[1] < 0) ? keygroup::KT_AXIS_PAIR : keygroup::KT_PRESSURE_MP);
|
||||
axis_count++;
|
||||
} else if(i % 2 == 0) {
|
||||
create_hat(fd, EV_ABS, i, i + 1, hat_count++);
|
||||
joystick_new_hat(fd, i, i + 1, 1, get_axis_name(i), get_axis_name(i + 1));
|
||||
hat_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint16_t joynum = get_joystick_number(fd);
|
||||
joystick_names[joynum] = namebuffer;
|
||||
messages << "Found '" << namebuffer << "' (" << button_count << " buttons, " << axis_count
|
||||
<< " axes, " << hat_count << " hats)" << std::endl;
|
||||
joysticks.insert(fd);
|
||||
joystick_message(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
void open_and_probe(const std::string& filename)
|
||||
{
|
||||
int r = open(filename.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
if(r < 0) {
|
||||
return;
|
||||
}
|
||||
if(!probe_joystick(r, filename)) {
|
||||
close(r);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void probe_all_joysticks()
|
||||
{
|
||||
DIR* d = opendir("/dev/input");
|
||||
|
@ -345,56 +286,15 @@ namespace
|
|||
for(size_t i = 5; dentry->d_name[i]; i++)
|
||||
if(!isdigit(static_cast<uint8_t>(dentry->d_name[i])))
|
||||
continue;
|
||||
open_and_probe(std::string("/dev/input/") + dentry->d_name);
|
||||
std::string filename = std::string("/dev/input/") + dentry->d_name;
|
||||
int r = open(filename.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
if(r < 0)
|
||||
continue;
|
||||
if(!probe_joystick(r, filename))
|
||||
close(r);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
std::string get_button_name(uint16_t code)
|
||||
{
|
||||
if(code <= KEY_MAX && buttonnames[code])
|
||||
return buttonnames[code];
|
||||
else {
|
||||
std::ostringstream str;
|
||||
str << "Unknown button #" << code << std::endl;
|
||||
return str.str();
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_axis_name(uint16_t code)
|
||||
{
|
||||
if(code <= ABS_MAX && axisnames[code])
|
||||
return axisnames[code];
|
||||
else {
|
||||
std::ostringstream str;
|
||||
str << "Unknown axis #" << code << std::endl;
|
||||
return str.str();
|
||||
}
|
||||
}
|
||||
|
||||
function_ptr_command<> show_joysticks("show-joysticks", "Show joysticks",
|
||||
"Syntax: show-joysticks\nShow joystick data.\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
for(auto i : joystick_names) {
|
||||
messages << "Joystick #" << i.first << ": " << i.second << std::endl;
|
||||
for(auto j : event_map) {
|
||||
if(j.second.joystick != i.first)
|
||||
continue;
|
||||
if(j.second.type == ET_BUTTON)
|
||||
messages << j.second.group->name() << ": "
|
||||
<< get_button_name(j.second.tevcode & 0xFFFF) << std::endl;
|
||||
if(j.second.type == ET_AXIS)
|
||||
messages << j.second.group->name() << ": "
|
||||
<< get_axis_name(j.second.tevcode & 0xFFFF)
|
||||
<< "[" << j.second.axis_min << "," << j.second.axis_max
|
||||
<< "]" << std::endl;
|
||||
if(j.second.type == ET_HAT_X || j.second.type == ET_HAT_Y)
|
||||
messages << j.second.group->name() << ": "
|
||||
<< get_axis_name(j.second.tevcode & 0xFFFF) << std::endl;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
volatile bool quit_signaled = false;
|
||||
volatile bool quit_ack = false;
|
||||
}
|
||||
|
@ -402,8 +302,6 @@ namespace
|
|||
void joystick_plugin::init() throw()
|
||||
{
|
||||
probe_all_joysticks();
|
||||
evdev_init_buttons(buttonnames);
|
||||
evdev_init_axes(axisnames);
|
||||
quit_ack = quit_signaled = false;
|
||||
}
|
||||
|
||||
|
@ -411,18 +309,7 @@ void joystick_plugin::quit() throw()
|
|||
{
|
||||
quit_signaled = true;
|
||||
while(!quit_ack);
|
||||
for(int fd : joysticks)
|
||||
close(fd);
|
||||
for(auto i : keygroups)
|
||||
delete i;
|
||||
keygroups.clear();
|
||||
joystick_map.clear();
|
||||
joysticks.clear();
|
||||
joystick_names.clear();
|
||||
std::map<uint64_t, struct event_mapping> event_map;
|
||||
std::map<int, uint16_t> joystick_map;
|
||||
std::set<int> joysticks;
|
||||
std::map<uint16_t, std::string> joystick_names;
|
||||
joystick_quit();
|
||||
}
|
||||
|
||||
#define POLL_WAIT 20000
|
||||
|
@ -430,8 +317,9 @@ void joystick_plugin::quit() throw()
|
|||
void joystick_plugin::thread_fn() throw()
|
||||
{
|
||||
while(!quit_signaled) {
|
||||
for(int fd : joysticks)
|
||||
for(auto fd : joystick_set())
|
||||
while(read_one_input_event(fd));
|
||||
joystick_flush();
|
||||
usleep(POLL_WAIT);
|
||||
}
|
||||
quit_ack = true;
|
||||
|
@ -440,6 +328,7 @@ void joystick_plugin::thread_fn() throw()
|
|||
void joystick_plugin::signal() throw()
|
||||
{
|
||||
quit_signaled = true;
|
||||
while(!quit_ack);
|
||||
}
|
||||
|
||||
const char* joystick_plugin::name = "Evdev joystick plugin";
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
name = io.stdin:read("*l");
|
||||
print("extern \"C\" {");
|
||||
print("#include <linux/input.h>");
|
||||
print("}");
|
||||
print("void " .. name .. "(const char** x) {");
|
||||
for line in io.stdin:lines() do
|
||||
a,b = string.match(line, "(%S+)%s+(.*)");
|
||||
print("#ifdef " .. a);
|
||||
print("x[" .. a .. "] = \"" .. b .. "\";");
|
||||
print("#endif");
|
||||
end
|
||||
print("}");
|
|
@ -1,10 +1,10 @@
|
|||
#include "core/command.hpp"
|
||||
#include "core/framerate.hpp"
|
||||
#include "core/joystick.hpp"
|
||||
#include "core/keymapper.hpp"
|
||||
#include "core/window.hpp"
|
||||
#include "library/minmax.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/joyfun.hpp"
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
@ -19,50 +19,17 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
std::set<keygroup*> keygroups;
|
||||
std::map<std::pair<unsigned, unsigned>, keygroup*> buttons;
|
||||
std::map<std::pair<unsigned, unsigned>, keygroup*> axes;
|
||||
std::map<unsigned, keygroup*> hats;
|
||||
std::map<std::pair<unsigned, unsigned>, short> lbuttons;
|
||||
std::map<std::pair<unsigned, unsigned>, short> laxes;
|
||||
std::map<unsigned, short> lhats;
|
||||
std::set<unsigned> joysticks;
|
||||
std::map<unsigned, JOYCAPS> capabilities;
|
||||
volatile bool quit_signaled;
|
||||
volatile bool quit_ack;
|
||||
|
||||
void create_hat(unsigned i, unsigned j = 0)
|
||||
{
|
||||
std::string n = (stringfmt() << "joystick" << i << "hat" << j).str();
|
||||
keygroup* k = new keygroup(n, "joystick", keygroup::KT_HAT);
|
||||
hats[i] = k;
|
||||
const char* buttonnames[] = {"Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7",
|
||||
"Button8", "Button9", "Button10", "Button11", "Button12", "Button13", "Button14", "Button15",
|
||||
"Button16", "Button17", "Button18", "Button19", "Button20", "Button21", "Button22", "Button23",
|
||||
"Button24", "Button25", "Button26", "Button27", "Button28", "Button29", "Button30", "Button31",
|
||||
"Button32"};
|
||||
}
|
||||
|
||||
void create_button(unsigned i, unsigned j)
|
||||
{
|
||||
std::string n = (stringfmt() << "joystick" << i << "button" << j).str();
|
||||
keygroup* k = new keygroup(n, "joystick", keygroup::KT_KEY);
|
||||
buttons[std::make_pair(i, j)] = k;
|
||||
}
|
||||
|
||||
void create_axis(unsigned i, unsigned j, unsigned min, unsigned max)
|
||||
{
|
||||
std::string n = (stringfmt() << "joystick" << i << "axis" << j).str();
|
||||
keygroup* k;
|
||||
k = new keygroup(n, "joystick", keygroup::KT_AXIS_PAIR);
|
||||
axes[std::make_pair(i, j)] = k;
|
||||
}
|
||||
|
||||
void read_axis(unsigned i, unsigned j, unsigned pos, unsigned pmin, unsigned pmax)
|
||||
{
|
||||
auto key = std::make_pair(i, j);
|
||||
if(!axes.count(key))
|
||||
return;
|
||||
if(make_equal(laxes[key], calibration_correction(pos, pmin, pmax)))
|
||||
platform::queue(keypress(modifier_set(), *axes[key], laxes[key]));
|
||||
}
|
||||
|
||||
void init_joysticks()
|
||||
void joystick_plugin::init() throw()
|
||||
{
|
||||
unsigned max_joysticks = joyGetNumDevs();
|
||||
if(!max_joysticks)
|
||||
|
@ -76,89 +43,20 @@ namespace
|
|||
continue; //Not usable.
|
||||
if(joyGetDevCaps(i, &caps, sizeof(caps)) != JOYERR_NOERROR)
|
||||
continue; //Not usable.
|
||||
joysticks.insert(i);
|
||||
capabilities[i] = caps;
|
||||
messages << "Joystick #" << i << ": " << caps.szPname << " (by '" << caps.szOEMVxD << "')"
|
||||
<< std::endl;
|
||||
joystick_create(i, caps.szPname);
|
||||
if(caps.wCaps & JOYCAPS_HASPOV)
|
||||
create_hat(i);
|
||||
joystick_new_hat(i, 0, "POV");
|
||||
for(unsigned j = 0; j < caps.wNumButtons && j < 32; j++)
|
||||
create_button(i, j);
|
||||
unsigned axcount = 2;
|
||||
create_axis(i, 0, caps.wXmin, caps.wXmax);
|
||||
create_axis(i, 1, caps.wYmin, caps.wYmax);
|
||||
if(caps.wCaps & JOYCAPS_HASZ) {
|
||||
create_axis(i, 2, caps.wZmin, caps.wZmax);
|
||||
axcount++;
|
||||
joystick_new_button(i, j, buttonnames[j]);
|
||||
keygroup::type t = keygroup::KT_AXIS_PAIR;
|
||||
joystick_new_axis(i, 0, caps.wXmin, caps.wXmax, "X", t);
|
||||
joystick_new_axis(i, 1, caps.wYmin, caps.wYmax, "Y", t);
|
||||
if(caps.wCaps & JOYCAPS_HASZ) joystick_new_axis(i, 2, caps.wZmin, caps.wZmax, "Z", t);
|
||||
if(caps.wCaps & JOYCAPS_HASR) joystick_new_axis(i, 3, caps.wRmin, caps.wRmax, "Rudder", t);
|
||||
if(caps.wCaps & JOYCAPS_HASU) joystick_new_axis(i, 4, caps.wUmin, caps.wUmax, "U", t);
|
||||
if(caps.wCaps & JOYCAPS_HASV) joystick_new_axis(i, 5, caps.wVmin, caps.wVmax, "V", t);
|
||||
joystick_message(i);
|
||||
}
|
||||
if(caps.wCaps & JOYCAPS_HASR) {
|
||||
create_axis(i, 3, caps.wRmin, caps.wRmax);
|
||||
axcount++;
|
||||
}
|
||||
if(caps.wCaps & JOYCAPS_HASU) {
|
||||
create_axis(i, 4, caps.wUmin, caps.wUmax);
|
||||
axcount++;
|
||||
}
|
||||
if(caps.wCaps & JOYCAPS_HASV) {
|
||||
create_axis(i, 5, caps.wVmin, caps.wVmax);
|
||||
axcount++;
|
||||
}
|
||||
if(caps.wCaps & JOYCAPS_HASPOV)
|
||||
messages << "1 hat, ";
|
||||
messages << axcount << " axes, " << min((int)caps.wNumButtons, 32) << " buttons" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void quit_joysticks()
|
||||
{
|
||||
for(auto i : keygroups)
|
||||
delete i;
|
||||
buttons.clear();
|
||||
axes.clear();
|
||||
hats.clear();
|
||||
keygroups.clear();
|
||||
joysticks.clear();
|
||||
capabilities.clear();
|
||||
}
|
||||
|
||||
void poll_joysticks()
|
||||
{
|
||||
modifier_set mod;
|
||||
for(auto i : capabilities) {
|
||||
unsigned jnum = i.first;
|
||||
JOYINFOEX info;
|
||||
JOYCAPS caps = capabilities[jnum];
|
||||
info.dwSize = sizeof(info);
|
||||
info.dwFlags = JOY_RETURNALL;
|
||||
if(joyGetPosEx(jnum, &info) != JOYERR_NOERROR)
|
||||
continue; //Not usable.
|
||||
if(caps.wCaps & JOYCAPS_HASPOV)
|
||||
if(make_equal(lhats[jnum], angle_to_bitmask(info.dwPOV)))
|
||||
platform::queue(keypress(modifier_set(), *hats[jnum], lhats[jnum]));
|
||||
for(unsigned j = 0; j < caps.wMaxButtons; j++) {
|
||||
//Read buttons
|
||||
auto key = std::make_pair(jnum, j);
|
||||
if(buttons.count(key) && make_equal(lbuttons[key],
|
||||
static_cast<short>((info.dwButtons >> j) & 1)))
|
||||
platform::queue(keypress(modifier_set(), *buttons[key], lbuttons[key]));
|
||||
}
|
||||
read_axis(jnum, 0, info.dwXpos, caps.wXmin, caps.wXmax);
|
||||
read_axis(jnum, 1, info.dwYpos, caps.wYmin, caps.wYmax);
|
||||
if(caps.wCaps & JOYCAPS_HASZ)
|
||||
read_axis(jnum, 2, info.dwZpos, caps.wZmin, caps.wZmax);
|
||||
if(caps.wCaps & JOYCAPS_HASR)
|
||||
read_axis(jnum, 3, info.dwRpos, caps.wRmin, caps.wRmax);
|
||||
if(caps.wCaps & JOYCAPS_HASU)
|
||||
read_axis(jnum, 4, info.dwUpos, caps.wUmin, caps.wUmax);
|
||||
if(caps.wCaps & JOYCAPS_HASV)
|
||||
read_axis(jnum, 5, info.dwVpos, caps.wVmin, caps.wVmax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void joystick_plugin::init() throw()
|
||||
{
|
||||
init_joysticks();
|
||||
quit_ack = quit_signaled = false;
|
||||
}
|
||||
|
||||
|
@ -166,7 +64,7 @@ void joystick_plugin::quit() throw()
|
|||
{
|
||||
quit_signaled = true;
|
||||
while(!quit_ack);
|
||||
quit_joysticks();
|
||||
joystick_quit();
|
||||
}
|
||||
|
||||
#define POLL_WAIT 20000
|
||||
|
@ -174,7 +72,23 @@ void joystick_plugin::quit() throw()
|
|||
void joystick_plugin::thread_fn() throw()
|
||||
{
|
||||
while(!quit_signaled) {
|
||||
poll_joysticks();
|
||||
for(auto i : joystick_set()) {
|
||||
JOYINFOEX info;
|
||||
info.dwSize = sizeof(info);
|
||||
info.dwFlags = JOY_RETURNALL;
|
||||
if(joyGetPosEx(i, &info) != JOYERR_NOERROR)
|
||||
continue; //Not usable.
|
||||
joystick_report_pov(i, 0, info.dwPOV);
|
||||
for(unsigned j = 0; j < 32; j++)
|
||||
joystick_report_button(i, j, (info.dwButtons >> j) & 1);
|
||||
joystick_report_axis(i, 0, info.dwXpos);
|
||||
joystick_report_axis(i, 1, info.dwYpos);
|
||||
joystick_report_axis(i, 2, info.dwZpos);
|
||||
joystick_report_axis(i, 3, info.dwRpos);
|
||||
joystick_report_axis(i, 4, info.dwUpos);
|
||||
joystick_report_axis(i, 5, info.dwVpos);
|
||||
}
|
||||
joystick_flush();
|
||||
usleep(POLL_WAIT);
|
||||
}
|
||||
quit_ack = true;
|
||||
|
@ -183,6 +97,7 @@ void joystick_plugin::thread_fn() throw()
|
|||
void joystick_plugin::signal() throw()
|
||||
{
|
||||
quit_signaled = true;
|
||||
while(!quit_ack);
|
||||
}
|
||||
|
||||
const char* joystick_plugin::name = "Win32mm joystick plugin";
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#include "core/command.hpp"
|
||||
#include "core/framerate.hpp"
|
||||
#include "core/keymapper.hpp"
|
||||
#include "core/joystick.hpp"
|
||||
#include "core/window.hpp"
|
||||
#include "library/minmax.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/joyfun.hpp"
|
||||
#include <wx/timer.h>
|
||||
#include <wx/joystick.h>
|
||||
|
||||
|
@ -21,49 +21,43 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
std::set<keygroup*> keygroups;
|
||||
std::map<std::pair<unsigned, unsigned>, keygroup*> buttons;
|
||||
std::map<std::pair<unsigned, unsigned>, keygroup*> axes;
|
||||
std::map<unsigned, keygroup*> hats;
|
||||
std::map<std::pair<unsigned, unsigned>, short> lbuttons;
|
||||
std::map<std::pair<unsigned, unsigned>, short> laxes;
|
||||
std::map<unsigned, short> lhats;
|
||||
std::map<unsigned, wxJoystick*> joysticks;
|
||||
volatile bool ready = false;
|
||||
volatile bool ready;
|
||||
|
||||
void create_hat(unsigned i, unsigned j = 0)
|
||||
{
|
||||
std::string n = (stringfmt() << "joystick" << i << "hat" << j).str();
|
||||
keygroup* k = new keygroup(n, "joystick", keygroup::KT_HAT);
|
||||
hats[i] = k;
|
||||
}
|
||||
const char* buttonnames[] = {"Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7",
|
||||
"Button8", "Button9", "Button10", "Button11", "Button12", "Button13", "Button14", "Button15",
|
||||
"Button16", "Button17", "Button18", "Button19", "Button20", "Button21", "Button22", "Button23",
|
||||
"Button24", "Button25", "Button26", "Button27", "Button28", "Button29", "Button30", "Button31",
|
||||
"Button32"};
|
||||
|
||||
void create_button(unsigned i, unsigned j)
|
||||
struct joystick_timer : public wxTimer
|
||||
{
|
||||
std::string n = (stringfmt() << "joystick" << i << "button" << j).str();
|
||||
keygroup* k = new keygroup(n, "joystick", keygroup::KT_KEY);
|
||||
buttons[std::make_pair(i, j)] = k;
|
||||
}
|
||||
|
||||
void create_axis(unsigned i, unsigned j, int min, int max)
|
||||
joystick_timer() { start(); }
|
||||
void start() { Start(POLL_WAIT / 1000); }
|
||||
void stop() { Stop(); }
|
||||
void Notify()
|
||||
{
|
||||
messages << "axis #" << j << ": " << min << " " << max << std::endl;
|
||||
std::string n = (stringfmt() << "joystick" << i << "axis" << j).str();
|
||||
keygroup* k;
|
||||
k = new keygroup(n, "joystick", keygroup::KT_AXIS_PAIR);
|
||||
axes[std::make_pair(i, j)] = k;
|
||||
}
|
||||
|
||||
void read_axis(unsigned i, unsigned j, int pos, int pmin, int pmax)
|
||||
{
|
||||
auto key = std::make_pair(i, j);
|
||||
if(!axes.count(key))
|
||||
if(!ready)
|
||||
return;
|
||||
if(make_equal(laxes[key], calibration_correction(pos, pmin, pmax)))
|
||||
platform::queue(keypress(modifier_set(), *axes[key], laxes[key]));
|
||||
for(auto i : joystick_set()) {
|
||||
wxJoystick& j = *reinterpret_cast<wxJoystick*>(i);
|
||||
joystick_report_pov(i, 0, j.GetPOVCTSPosition());
|
||||
uint32_t bmask = j.GetButtonState();
|
||||
for(unsigned j = 0; j < 32; j++)
|
||||
joystick_report_button(i, j, (bmask >> j) & 1);
|
||||
wxPoint xy = j.GetPosition();
|
||||
joystick_report_axis(i, 0, xy.x);
|
||||
joystick_report_axis(i, 1, xy.y);
|
||||
joystick_report_axis(i, 2, j.GetZPosition());
|
||||
joystick_report_axis(i, 3, j.GetRudderPosition());
|
||||
joystick_report_axis(i, 4, j.GetUPosition());
|
||||
joystick_report_axis(i, 5, j.GetVPosition());
|
||||
}
|
||||
joystick_flush();
|
||||
}
|
||||
}* jtimer;
|
||||
}
|
||||
|
||||
void init_joysticks()
|
||||
void joystick_plugin::init() throw()
|
||||
{
|
||||
unsigned max_joysticks = wxJoystick::GetNumberJoysticks();
|
||||
if(!max_joysticks)
|
||||
|
@ -75,104 +69,37 @@ namespace
|
|||
delete joy;
|
||||
continue;
|
||||
}
|
||||
joysticks[i] = joy;
|
||||
messages << "Joystick #" << i << ": " << joy->GetProductName() << std::endl;
|
||||
uint64_t jid = reinterpret_cast<uint64_t>(joy);
|
||||
joystick_create(jid, joy->GetProductName());
|
||||
if(joy->HasPOV())
|
||||
create_hat(i);
|
||||
joystick_new_hat(jid, 0, "POV");
|
||||
for(unsigned j = 0; j < joy->GetNumberButtons() && j < 32; j++)
|
||||
create_button(i, j);
|
||||
unsigned axcount = 2;
|
||||
create_axis(i, 0, joy->GetXMin(), joy->GetXMax());
|
||||
create_axis(i, 1, joy->GetYMin(), joy->GetYMax());
|
||||
if(joy->HasZ()) {
|
||||
create_axis(i, 2, joy->GetZMin(), joy->GetZMax());
|
||||
axcount++;
|
||||
}
|
||||
if(joy->HasRudder()) {
|
||||
create_axis(i, 3, joy->GetRudderMin(), joy->GetRudderMax());
|
||||
axcount++;
|
||||
}
|
||||
if(joy->HasU()) {
|
||||
create_axis(i, 4, joy->GetUMin(), joy->GetUMax());
|
||||
axcount++;
|
||||
}
|
||||
if(joy->HasV()) {
|
||||
create_axis(i, 5, joy->GetVMin(), joy->GetVMax());
|
||||
axcount++;
|
||||
}
|
||||
if(joy->HasPOV())
|
||||
messages << "1 hat, ";
|
||||
messages << axcount << " axes, " << min((int)joy->GetNumberButtons(), 32) << " buttons"
|
||||
<< std::endl;
|
||||
joystick_new_button(jid, j, buttonnames[j]);
|
||||
keygroup::type t = keygroup::KT_AXIS_PAIR;
|
||||
const char* R = "Rudder";
|
||||
joystick_new_axis(jid, 0, joy->GetXMin(), joy->GetXMax(), "X", t);
|
||||
joystick_new_axis(jid, 1, joy->GetYMin(), joy->GetYMax(), "Y", t);
|
||||
if(joy->HasZ()) joystick_new_axis(jid, 2, joy->GetZMin(), joy->GetZMax(), "Z", t);
|
||||
if(joy->HasRudder()) joystick_new_axis(jid, 3, joy->GetRudderMin(), joy->GetRudderMax(), R, t);
|
||||
if(joy->HasU()) joystick_new_axis(jid, 4, joy->GetUMin(), joy->GetUMax(), "U", t);
|
||||
if(joy->HasV()) joystick_new_axis(jid, 5, joy->GetVMin(), joy->GetVMax(), "V", t);
|
||||
joystick_message(jid);
|
||||
}
|
||||
ready = true;
|
||||
}
|
||||
|
||||
void poll_joysticks()
|
||||
{
|
||||
if(!ready)
|
||||
return;
|
||||
modifier_set mod;
|
||||
for(auto i : joysticks) {
|
||||
unsigned jnum = i.first;
|
||||
wxJoystick* joy = i.second;
|
||||
if(joy->HasPOV())
|
||||
if(make_equal(lhats[jnum], angle_to_bitmask(joy->GetPOVCTSPosition())))
|
||||
platform::queue(keypress(modifier_set(), *hats[jnum], lhats[jnum]));
|
||||
uint32_t bmask = joy->GetButtonState();
|
||||
for(unsigned j = 0; j < 32; j++) {
|
||||
//Read buttons
|
||||
auto key = std::make_pair(jnum, j);
|
||||
if(buttons.count(key) && make_equal(lbuttons[key], static_cast<short>((bmask >> j) &
|
||||
1)))
|
||||
platform::queue(keypress(modifier_set(), *buttons[key], lbuttons[key]));
|
||||
}
|
||||
wxPoint xy = joy->GetPosition();
|
||||
read_axis(jnum, 0, xy.x, joy->GetXMin(), joy->GetXMax());
|
||||
read_axis(jnum, 1, xy.y, joy->GetYMin(), joy->GetYMax());
|
||||
if(joy->HasZ())
|
||||
read_axis(jnum, 2, joy->GetZPosition(), joy->GetZMin(), joy->GetZMax());
|
||||
if(joy->HasRudder())
|
||||
read_axis(jnum, 3, joy->GetRudderPosition(), joy->GetRudderMin(), joy->GetRudderMax());
|
||||
if(joy->HasU())
|
||||
read_axis(jnum, 4, joy->GetUPosition(), joy->GetUMin(), joy->GetUMax());
|
||||
if(joy->HasV())
|
||||
read_axis(jnum, 5, joy->GetVPosition(), joy->GetUMin(), joy->GetUMax());
|
||||
}
|
||||
}
|
||||
|
||||
struct joystick_timer : public wxTimer
|
||||
{
|
||||
joystick_timer() { start(); }
|
||||
void start() { Start(POLL_WAIT / 1000); }
|
||||
void stop() { Stop(); }
|
||||
void Notify() { poll_joysticks(); }
|
||||
}* jtimer;
|
||||
}
|
||||
|
||||
void joystick_plugin::init() throw()
|
||||
{
|
||||
init_joysticks();
|
||||
jtimer = new joystick_timer();
|
||||
}
|
||||
|
||||
void joystick_plugin::quit() throw()
|
||||
{
|
||||
if(jtimer)
|
||||
jtimer->stop();
|
||||
delete jtimer;
|
||||
jtimer = NULL;
|
||||
ready = false;
|
||||
for(auto i : joystick_set())
|
||||
delete reinterpret_cast<wxJoystick*>(i);
|
||||
usleep(50000);
|
||||
for(auto i : keygroups)
|
||||
delete i;
|
||||
for(auto i : joysticks)
|
||||
delete i.second;
|
||||
usleep(500000);
|
||||
buttons.clear();
|
||||
axes.clear();
|
||||
hats.clear();
|
||||
keygroups.clear();
|
||||
joysticks.clear();
|
||||
joystick_quit();
|
||||
}
|
||||
|
||||
void joystick_plugin::thread_fn() throw()
|
||||
|
|
Loading…
Add table
Reference in a new issue