Lua: New function input.raw, which gives data for all buttons
This commit is contained in:
parent
7b9a9590c1
commit
af655f14f3
5 changed files with 135 additions and 2 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <stdexcept>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include "misc.hpp"
|
||||
|
||||
|
@ -203,7 +204,11 @@ public:
|
|||
/**
|
||||
* Hat.
|
||||
*/
|
||||
KT_HAT
|
||||
KT_HAT,
|
||||
/**
|
||||
* Mouse axis (this is not a real axis!).
|
||||
*/
|
||||
KT_MOUSE
|
||||
};
|
||||
/**
|
||||
* Create a new key group.
|
||||
|
@ -252,6 +257,7 @@ public:
|
|||
* For KT_KEY, value is zero/nonzero.
|
||||
* For KT_PRESSURE_* and KT_AXIS_PAIR*, value is -32768...32767.
|
||||
* For KT_HAT, 1 is up, 2 is right, 4 is down, 8 is left (may be ORed).
|
||||
* For KT_MOUSE, value is -32768...32767.
|
||||
*
|
||||
* parameter pos: New position.
|
||||
* parameter modifiers: The modifier set that was pressed during the change.
|
||||
|
@ -288,6 +294,10 @@ public:
|
|||
* Type
|
||||
*/
|
||||
enum type ktype;
|
||||
/**
|
||||
* Last known raw value.
|
||||
*/
|
||||
short last_rawval;
|
||||
/**
|
||||
* Calibration left.
|
||||
*/
|
||||
|
@ -309,9 +319,14 @@ public:
|
|||
* Get parameters.
|
||||
*/
|
||||
struct parameters get_parameters();
|
||||
/**
|
||||
* Get all key parameters.
|
||||
*/
|
||||
static std::map<std::string, struct parameters> get_all_parameters();
|
||||
private:
|
||||
unsigned state;
|
||||
enum type ktype;
|
||||
short last_rawval;
|
||||
short cal_left;
|
||||
short cal_center;
|
||||
short cal_right;
|
||||
|
|
39
manual.lyx
39
manual.lyx
|
@ -2432,6 +2432,45 @@ Execute reset.
|
|||
Only available with subframe flag false.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
input.raw()
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Returns table of tables of all available keys and axes.
|
||||
The first table is indexed by key name (platform-dependent!), and the inner
|
||||
table has the following fields:
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
last_rawval: Last reported raw value for control.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
ktype: Type of key (disabled, key, mouse, axis, axis-inverse, hat, pressure-m0,
|
||||
pressure-mp, pressure-0m, pressure-0p, pressure-pm, pressure-p0).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
cal_left: Minimum calibration value.
|
||||
Only meaningful with axis and pressure types.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
cal_center: Center calibration value.
|
||||
Only meaningful with axis and pressure types.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
cal_right: Maximum calibration value.
|
||||
Only meaningful with axis and pressure types.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
cal_tolerance: Dead zone tolerance.
|
||||
Only meaningful with axis and pressure types.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsection
|
||||
Table hostmemory
|
||||
\end_layout
|
||||
|
|
24
manual.txt
24
manual.txt
|
@ -1190,6 +1190,30 @@ Execute reset. If cycles is greater than zero, do delayed reset.
|
|||
|
||||
• Only available with subframe flag false.
|
||||
|
||||
8.4.4 input.raw()
|
||||
|
||||
Returns table of tables of all available keys and axes. The first
|
||||
table is indexed by key name (platform-dependent!), and the inner
|
||||
table has the following fields:
|
||||
|
||||
• last_rawval: Last reported raw value for control.
|
||||
|
||||
• ktype: Type of key (disabled, key, mouse, axis, axis-inverse,
|
||||
hat, pressure-m0, pressure-mp, pressure-0m, pressure-0p,
|
||||
pressure-pm, pressure-p0).
|
||||
|
||||
• cal_left: Minimum calibration value. Only meaningful with axis
|
||||
and pressure types.
|
||||
|
||||
• cal_center: Center calibration value. Only meaningful with axis
|
||||
and pressure types.
|
||||
|
||||
• cal_right: Maximum calibration value. Only meaningful with axis
|
||||
and pressure types.
|
||||
|
||||
• cal_tolerance: Dead zone tolerance. Only meaningful with axis
|
||||
and pressure types.
|
||||
|
||||
8.5 Table hostmemory
|
||||
|
||||
Host memory handling (extra memory saved to savestates). Host
|
||||
|
|
|
@ -285,15 +285,24 @@ struct keygroup::parameters keygroup::get_parameters()
|
|||
p.cal_center = cal_center;
|
||||
p.cal_right = cal_right;
|
||||
p.cal_tolerance = cal_tolerance;
|
||||
p.last_rawval = last_rawval;
|
||||
return p;
|
||||
}
|
||||
|
||||
std::map<std::string, struct keygroup::parameters> keygroup::get_all_parameters()
|
||||
{
|
||||
std::map<std::string, struct parameters> ret;
|
||||
for(auto i : keygroups())
|
||||
ret[i.first] = i.second->get_parameters();
|
||||
return ret;
|
||||
}
|
||||
|
||||
keygroup::keygroup(const std::string& name, enum type t) throw(std::bad_alloc)
|
||||
{
|
||||
keygroups()[keyname = name] = this;
|
||||
ktype = t;
|
||||
state = 0;
|
||||
last_rawval = 0;
|
||||
cal_left = -32768;
|
||||
cal_center = 0;
|
||||
cal_right = 32767;
|
||||
|
@ -348,7 +357,7 @@ void keygroup::change_calibration(short left, short center, short right, double
|
|||
|
||||
double keygroup::compensate(short value)
|
||||
{
|
||||
if(ktype == KT_HAT || ktype == KT_KEY || ktype == KT_DISABLED)
|
||||
if(ktype == KT_HAT || ktype == KT_KEY || ktype == KT_DISABLED || ktype == KT_MOUSE)
|
||||
return value; //These can't be calibrated.
|
||||
if(value <= cal_left)
|
||||
return -1.0;
|
||||
|
@ -366,6 +375,7 @@ double keygroup::compensate2(double value)
|
|||
{
|
||||
switch(ktype) {
|
||||
case KT_DISABLED:
|
||||
case KT_MOUSE:
|
||||
return 0; //Always neutral.
|
||||
case KT_KEY:
|
||||
case KT_HAT:
|
||||
|
@ -391,12 +401,14 @@ double keygroup::compensate2(double value)
|
|||
|
||||
void keygroup::set_position(short pos, const modifier_set& modifiers) throw()
|
||||
{
|
||||
last_rawval = pos;
|
||||
double x = compensate2(compensate(pos));
|
||||
unsigned tmp;
|
||||
bool left, right, up, down;
|
||||
bool oleft, oright, oup, odown;
|
||||
switch(ktype) {
|
||||
case KT_DISABLED:
|
||||
case KT_MOUSE:
|
||||
return;
|
||||
case KT_KEY:
|
||||
case KT_PRESSURE_0M:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "core/keymapper.hpp"
|
||||
#include "core/lua-int.hpp"
|
||||
|
||||
namespace
|
||||
|
@ -38,4 +39,46 @@ namespace
|
|||
lua_input_controllerdata->delay(std::make_pair(hi, lo));
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun iraw("input.raw", [](lua_State* LS, const std::string& fname) -> int {
|
||||
auto s = keygroup::get_all_parameters();
|
||||
lua_newtable(LS);
|
||||
for(auto i : s) {
|
||||
lua_pushstring(LS, i.first.c_str());
|
||||
lua_newtable(LS);
|
||||
lua_pushstring(LS, "last_rawval");
|
||||
lua_pushnumber(LS, i.second.last_rawval);
|
||||
lua_settable(LS, -3);
|
||||
lua_pushstring(LS, "cal_left");
|
||||
lua_pushnumber(LS, i.second.cal_left);
|
||||
lua_settable(LS, -3);
|
||||
lua_pushstring(LS, "cal_center");
|
||||
lua_pushnumber(LS, i.second.cal_center);
|
||||
lua_settable(LS, -3);
|
||||
lua_pushstring(LS, "cal_right");
|
||||
lua_pushnumber(LS, i.second.cal_right);
|
||||
lua_settable(LS, -3);
|
||||
lua_pushstring(LS, "cal_tolerance");
|
||||
lua_pushnumber(LS, i.second.cal_tolerance);
|
||||
lua_settable(LS, -3);
|
||||
lua_pushstring(LS, "ktype");
|
||||
switch(i.second.ktype) {
|
||||
case keygroup::KT_DISABLED: lua_pushstring(LS, "disabled"); break;
|
||||
case keygroup::KT_KEY: lua_pushstring(LS, "key"); break;
|
||||
case keygroup::KT_AXIS_PAIR: lua_pushstring(LS, "axis"); break;
|
||||
case keygroup::KT_AXIS_PAIR_INVERSE: lua_pushstring(LS, "axis-inverse"); break;
|
||||
case keygroup::KT_HAT: lua_pushstring(LS, "hat"); break;
|
||||
case keygroup::KT_MOUSE: lua_pushstring(LS, "mouse"); break;
|
||||
case keygroup::KT_PRESSURE_PM: lua_pushstring(LS, "pressure-pm"); break;
|
||||
case keygroup::KT_PRESSURE_P0: lua_pushstring(LS, "pressure-p0"); break;
|
||||
case keygroup::KT_PRESSURE_0M: lua_pushstring(LS, "pressure-0m"); break;
|
||||
case keygroup::KT_PRESSURE_0P: lua_pushstring(LS, "pressure-0p"); break;
|
||||
case keygroup::KT_PRESSURE_M0: lua_pushstring(LS, "pressure-m0"); break;
|
||||
case keygroup::KT_PRESSURE_MP: lua_pushstring(LS, "pressure-mp"); break;
|
||||
};
|
||||
lua_settable(LS, -3);
|
||||
lua_settable(LS, -3);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue