Move joystick axis manipulation from SDL to keymapper code
Joystick axis manipulation isn't really platform-dependent, so move it from SDL platform code to keymapper code. Additionally, add command to show all axes and parameters.
This commit is contained in:
parent
bdd0a17bef
commit
3517ba2eee
4 changed files with 346 additions and 113 deletions
|
@ -1530,43 +1530,6 @@ namespace
|
|||
messagebuffer_first_show = messagebuffer_next_seq - maxmessages;
|
||||
window::notify_screen_update(true);
|
||||
});
|
||||
|
||||
function_ptr_command<tokensplitter&> joystickmode("axismode", "Set joystick axis mode",
|
||||
"Syntax: axismode joystick<num>axis<axis> <mode>\nSet joystick axis mode.\n",
|
||||
[](tokensplitter& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
std::string axis = t;
|
||||
std::string mode = t;
|
||||
unsigned i = 0;
|
||||
if(mode == "" || t)
|
||||
throw std::runtime_error("Expected exactly 2 parameters");
|
||||
keygroup* tomod = NULL;
|
||||
for(auto i = joyaxis.begin(); i != joyaxis.end(); ++i)
|
||||
if(i->second->name() == axis)
|
||||
tomod = i->second;
|
||||
if(!tomod)
|
||||
throw std::runtime_error("Invalid axis");
|
||||
if(mode == "axis")
|
||||
tomod->change_type(keygroup::KT_AXIS_PAIR);
|
||||
else if(mode == "axis_inverse")
|
||||
tomod->change_type(keygroup::KT_AXIS_PAIR_INVERSE);
|
||||
else if(mode == "pressure_0m")
|
||||
tomod->change_type(keygroup::KT_PRESSURE_0M);
|
||||
else if(mode == "pressure_0p")
|
||||
tomod->change_type(keygroup::KT_PRESSURE_0P);
|
||||
else if(mode == "pressure_m0")
|
||||
tomod->change_type(keygroup::KT_PRESSURE_M0);
|
||||
else if(mode == "pressure_mp")
|
||||
tomod->change_type(keygroup::KT_PRESSURE_MP);
|
||||
else if(mode == "pressure_p0")
|
||||
tomod->change_type(keygroup::KT_PRESSURE_P0);
|
||||
else if(mode == "pressure_pm")
|
||||
tomod->change_type(keygroup::KT_PRESSURE_PM);
|
||||
else if(mode == "disabled")
|
||||
tomod->change_type(keygroup::KT_DISABLED);
|
||||
else
|
||||
throw std::runtime_error("Bad axis mode");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void window::wait_usec(uint64_t usec) throw(std::bad_alloc)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "keymapper.hpp"
|
||||
#include <stdexcept>
|
||||
#include "window.hpp"
|
||||
#include "lua.hpp"
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
@ -251,6 +252,17 @@ std::string keygroup::name() throw(std::bad_alloc)
|
|||
return keyname;
|
||||
}
|
||||
|
||||
struct keygroup::parameters keygroup::get_parameters()
|
||||
{
|
||||
parameters p;
|
||||
p.ktype = ktype;
|
||||
p.cal_left = cal_left;
|
||||
p.cal_center = cal_center;
|
||||
p.cal_right = cal_right;
|
||||
p.cal_tolerance = cal_tolerance;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
keygroup::keygroup(const std::string& name, enum type t) throw(std::bad_alloc)
|
||||
{
|
||||
|
@ -452,6 +464,153 @@ void keygroup::set_exclusive_key_listener(key_listener* l) throw()
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
function_ptr_command<tokensplitter&> set_axis("set-axis", "Set mode of Joystick axis",
|
||||
"Syntax: set-axis <axis> <options>...\nKnown options: disabled, axis, axis-inverse, pressure0-\n"
|
||||
"pressure0+, pressure-0, pressure-+, pressure+0, pressure+-\nminus=<val>, zero=<val>, plus=<val>\n"
|
||||
"tolerance=<val>\n",
|
||||
[](tokensplitter& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
struct keygroup::parameters p;
|
||||
std::string axis = t;
|
||||
if(axis == "")
|
||||
throw std::runtime_error("Axis name required");
|
||||
if(!keygroups().count(axis))
|
||||
throw std::runtime_error("Unknown axis name");
|
||||
p = keygroups()[axis]->get_parameters();
|
||||
switch(p.ktype) {
|
||||
case keygroup::KT_DISABLED:
|
||||
case keygroup::KT_AXIS_PAIR:
|
||||
case keygroup::KT_AXIS_PAIR_INVERSE:
|
||||
case keygroup::KT_PRESSURE_0M:
|
||||
case keygroup::KT_PRESSURE_0P:
|
||||
case keygroup::KT_PRESSURE_M0:
|
||||
case keygroup::KT_PRESSURE_MP:
|
||||
case keygroup::KT_PRESSURE_P0:
|
||||
case keygroup::KT_PRESSURE_PM:
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Not an axis");
|
||||
}
|
||||
bool found_axismode = false;
|
||||
bool found_minus = false;
|
||||
bool found_zero = false;
|
||||
bool found_plus = false;
|
||||
bool found_tolerance = false;
|
||||
while(!!t) {
|
||||
std::string spec = t;
|
||||
if(spec == "disabled") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_DISABLED;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "axis") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_AXIS_PAIR;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "axis-inverse") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_AXIS_PAIR_INVERSE;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "pressure0-") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_PRESSURE_0M;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "pressure0+") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_PRESSURE_0P;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "pressure-0") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_PRESSURE_M0;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "pressure-+") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_PRESSURE_MP;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "pressure+0") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_PRESSURE_P0;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec == "pressure+-") {
|
||||
if(!found_axismode)
|
||||
p.ktype = keygroup::KT_PRESSURE_PM;
|
||||
else
|
||||
throw std::runtime_error("Conflicting axis modes");
|
||||
found_axismode = true;
|
||||
} else if(spec.substr(0, 6) == "minus=") {
|
||||
if(!found_minus)
|
||||
p.cal_left = parse_value<int16_t>(spec.substr(6));
|
||||
else
|
||||
throw std::runtime_error("Conflicting minus value");
|
||||
found_minus = true;
|
||||
} else if(spec.substr(0, 5) == "zero=") {
|
||||
if(!found_zero)
|
||||
p.cal_center = parse_value<int16_t>(spec.substr(5));
|
||||
else
|
||||
throw std::runtime_error("Conflicting zero value");
|
||||
found_zero = true;
|
||||
} else if(spec.substr(0, 5) == "plus=") {
|
||||
if(!found_plus)
|
||||
p.cal_right = parse_value<int16_t>(spec.substr(5));
|
||||
else
|
||||
throw std::runtime_error("Conflicting plus value");
|
||||
found_plus = true;
|
||||
} else if(spec.substr(0, 10) == "tolerance=") {
|
||||
if(!found_tolerance) {
|
||||
p.cal_tolerance = parse_value<double>(spec.substr(10));
|
||||
if(p.cal_tolerance <= 0 || p.cal_tolerance > 1)
|
||||
throw std::runtime_error("Tolerance out of range");
|
||||
} else
|
||||
throw std::runtime_error("Conflicting tolerance value");
|
||||
found_tolerance = true;
|
||||
} else
|
||||
throw std::runtime_error("Unknown axis modifier");
|
||||
}
|
||||
if(found_axismode)
|
||||
keygroups()[axis]->change_type(p.ktype);
|
||||
keygroups()[axis]->change_calibration(p.cal_left, p.cal_center, p.cal_right, p.cal_tolerance);
|
||||
});
|
||||
|
||||
function_ptr_command<> set_axismode("show-axes", "Show all joystick axes",
|
||||
"Syntax: show-axes\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
for(auto i = keygroups().begin(); i != keygroups().end(); ++i) {
|
||||
keygroup::parameters p = i->second->get_parameters();
|
||||
std::string type = "";
|
||||
switch(p.ktype) {
|
||||
case keygroup::KT_DISABLED: type = "disabled"; break;
|
||||
case keygroup::KT_AXIS_PAIR: type = "axis"; break;
|
||||
case keygroup::KT_AXIS_PAIR_INVERSE: type = "axis-inverse"; break;
|
||||
case keygroup::KT_PRESSURE_0M: type = "pressure0-"; break;
|
||||
case keygroup::KT_PRESSURE_0P: type = "pressure0+"; break;
|
||||
case keygroup::KT_PRESSURE_M0: type = "pressure-0"; break;
|
||||
case keygroup::KT_PRESSURE_MP: type = "pressure-+"; break;
|
||||
case keygroup::KT_PRESSURE_P0: type = "pressure+0"; break;
|
||||
case keygroup::KT_PRESSURE_PM: type = "pressure+-"; break;
|
||||
default: continue;
|
||||
}
|
||||
window::out() << i->first << " " << type << " -:" << p.cal_left << " 0:"
|
||||
<< p.cal_center << " +:" << p.cal_right << " t:" << p.cal_tolerance
|
||||
<< std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
struct triple
|
||||
{
|
||||
triple(const std::string& _a, const std::string& _b, const std::string& _c)
|
||||
|
|
|
@ -280,6 +280,37 @@ public:
|
|||
* parameter l: The new exclusive key listener or NULL if exclusive key listener is to be removed.
|
||||
*/
|
||||
static void set_exclusive_key_listener(key_listener* l) throw();
|
||||
|
||||
/**
|
||||
* Key group parameters.
|
||||
*/
|
||||
struct parameters
|
||||
{
|
||||
/**
|
||||
* Type
|
||||
*/
|
||||
enum type ktype;
|
||||
/**
|
||||
* Calibration left.
|
||||
*/
|
||||
short cal_left;
|
||||
/**
|
||||
* Calibration center.
|
||||
*/
|
||||
short cal_center;
|
||||
/**
|
||||
* Calibration right.
|
||||
*/
|
||||
short cal_right;
|
||||
/**
|
||||
* Calibration tolerance.
|
||||
*/
|
||||
double cal_tolerance;
|
||||
};
|
||||
/**
|
||||
* Get parameters.
|
||||
*/
|
||||
struct parameters get_parameters();
|
||||
private:
|
||||
unsigned state;
|
||||
enum type ktype;
|
||||
|
|
232
manual.lyx
232
manual.lyx
|
@ -620,7 +620,7 @@ Read value of setting <setting>
|
|||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
print-settings
|
||||
show-settings
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
|
@ -676,8 +676,77 @@ unbind-key [<mod>/<modmask>] <key>
|
|||
Unbind command from <key> (with specified <mod> and <modmask>).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
set-axis <axis> [disabled | axis | axis-inverse | pressure0- | pressure0+
|
||||
| pressure-0 | pressure-+ | pressure+0 | pressure+-] [minus=<val>] [zero=<val>]
|
||||
[plus=<val>] [tolerance=<val>]
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Set axis parameters for axis <axis>.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
disabled: Disable axis
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
axis: Normal axis
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
axis-inverse: Inverse axis
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure0-: Pressure sensitive.
|
||||
Released at 0, pressed at -.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure0+: Pressure sensitive.
|
||||
Released at 0, pressed at +.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure-0: Pressure sensitive.
|
||||
Released at -, pressed at 0.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure-+: Pressure sensitive.
|
||||
Released at -, pressed at +.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure+0: Pressure sensitive.
|
||||
Released at +, pressed at 0.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure+-: Pressure sensitive.
|
||||
Released at +, pressed at -.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
minus=<val>: Calibration at extreme minus position (-32768-32767)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
zero=<val>: Calibration at neutral position (-32768-32767)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
plus=<val>: Calibration at extreme plus position (-32768-32767)
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
tolerance=<value>: Center band tolerance (0<x<1).
|
||||
The smaller the value, the more sensitive the control is.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
print-keybindings
|
||||
show-bindings
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
|
@ -728,7 +797,7 @@ Clear alias expansion for <command>.
|
|||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
print-aliases
|
||||
show-aliases
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
|
@ -1411,79 +1480,6 @@ scroll-down
|
|||
Scroll messages window forward one screenful.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
axismode <axis> <mode>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Set joystick axis mode.
|
||||
<axis> is of form
|
||||
\begin_inset Quotes eld
|
||||
\end_inset
|
||||
|
||||
joystick<num>axis<axis>
|
||||
\begin_inset Quotes erd
|
||||
\end_inset
|
||||
|
||||
, e.g.
|
||||
|
||||
\begin_inset Quotes eld
|
||||
\end_inset
|
||||
|
||||
joystick0axis5
|
||||
\begin_inset Quotes erd
|
||||
\end_inset
|
||||
|
||||
.
|
||||
Mode is one of:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
axis: Normal axis mode
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
axis_inverse: Inverse axis mode.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure_0m: Pressure sensitive.
|
||||
Released at 0, pressed at full negative.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure_0p: Pressure sensitive.
|
||||
Released at 0, pressed at full positive.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure_m0: Pressure sensitive.
|
||||
Released at full negative, pressed at 0.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure_mp: Pressure sensitive.
|
||||
Released at full negative, pressed at full positive.
|
||||
E.g.
|
||||
XBox360 Pad axes 2 and 5.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure_p0: Pressure sensitive.
|
||||
Released at full positive, pressed at 0.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
pressure_pm: Pressure sensitive.
|
||||
Released at full positive, pressed at full negative.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
disabled: Disable the axis.
|
||||
On PS3 controller, axes 8-19 should be disabled since those controls are
|
||||
digital buttons as well.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Settings
|
||||
\end_layout
|
||||
|
@ -3503,6 +3499,90 @@ Do 'mkvmerge -o final.mkv tmpdump_video.mkv tmpdump.ogg'.
|
|||
Now final.mkv contains quick'n'dirty encode.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Axis configurations for some gamepad types:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
XBox360 controller:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Axes 2 and 5 (joystick<n>axis2 and joystick<n>axis5) should be set to pressure-+.
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis2 pressure-+
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis5 pressure-+
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
PS3
|
||||
\begin_inset Quotes eld
|
||||
\end_inset
|
||||
|
||||
sixaxis
|
||||
\begin_inset Quotes erd
|
||||
\end_inset
|
||||
|
||||
controller:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Axes 8-19 should be disabled.
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis8 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis9 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis10 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis11 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis12 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis13 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis14 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis15 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis16 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis17 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis18 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout LyX-Code
|
||||
set-axis joystick0axis19 disabled
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Errata:
|
||||
\end_layout
|
||||
|
|
Loading…
Add table
Reference in a new issue