Added shifting for --ui-axismap
This commit is contained in:
parent
b4d6539e42
commit
9b8584b19e
4 changed files with 173 additions and 13 deletions
63
src/axis_map.cpp
Normal file
63
src/axis_map.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "axis_map.hpp"
|
||||
|
||||
AxisMap::AxisMap() :
|
||||
m_axis_map()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void
|
||||
AxisMap::bind(XboxAxis code, const AxisEvent& event)
|
||||
{
|
||||
m_axis_map[XBOX_BTN_UNKNOWN][code] = event;
|
||||
}
|
||||
|
||||
void
|
||||
AxisMap::bind(XboxButton shift_code, XboxAxis code, const AxisEvent& event)
|
||||
{
|
||||
m_axis_map[shift_code][code] = event;
|
||||
}
|
||||
|
||||
AxisEvent
|
||||
AxisMap::lookup(XboxAxis code) const
|
||||
{
|
||||
return m_axis_map[XBOX_BTN_UNKNOWN][code];
|
||||
}
|
||||
|
||||
AxisEvent
|
||||
AxisMap::lookup(XboxButton shift_code, XboxAxis code) const
|
||||
{
|
||||
return m_axis_map[shift_code][code];
|
||||
}
|
||||
|
||||
void
|
||||
AxisMap::clear()
|
||||
{
|
||||
for(int shift_code = 0; shift_code < XBOX_BTN_MAX; ++shift_code)
|
||||
{
|
||||
for(int code = 0; code < XBOX_AXIS_MAX; ++code)
|
||||
{
|
||||
m_axis_map[shift_code][code] = AxisEvent::invalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* EOF */
|
46
src/axis_map.hpp
Normal file
46
src/axis_map.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_XBOXDRV_AXIS_MAP_HPP
|
||||
#define HEADER_XBOXDRV_AXIS_MAP_HPP
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "axis_event.hpp"
|
||||
#include "xboxmsg.hpp"
|
||||
|
||||
class AxisMap
|
||||
{
|
||||
private:
|
||||
AxisEvent m_axis_map[XBOX_BTN_MAX][XBOX_AXIS_MAX];
|
||||
|
||||
public:
|
||||
AxisMap();
|
||||
|
||||
void bind(XboxAxis code, const AxisEvent& event);
|
||||
void bind(XboxButton shift_code, XboxAxis code, const AxisEvent& event);
|
||||
|
||||
AxisEvent lookup(XboxAxis code) const;
|
||||
AxisEvent lookup(XboxButton shift_code, XboxAxis code) const;
|
||||
|
||||
void clear();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
|
@ -781,21 +781,45 @@ CommandLineParser::print_version() const
|
|||
void
|
||||
CommandLineParser::set_ui_axismap(const std::string& name, const std::string& value)
|
||||
{
|
||||
XboxAxis axis = string2axis(name);
|
||||
AxisEvent event = AxisEvent::from_string(value);
|
||||
|
||||
if (axis != XBOX_AXIS_UNKNOWN)
|
||||
std::string::size_type j = name.find('+');
|
||||
if (j == std::string::npos)
|
||||
{
|
||||
event.set_axis_range(get_axis_min(axis),
|
||||
get_axis_max(axis));
|
||||
XboxAxis axis = string2axis(name);
|
||||
|
||||
std::cout << "set_ui_axismap: " << name << " = " << value << std::endl;
|
||||
if (axis != XBOX_AXIS_UNKNOWN)
|
||||
{
|
||||
event.set_axis_range(get_axis_min(axis),
|
||||
get_axis_max(axis));
|
||||
|
||||
m_options->uinput_config.get_axis_map().bind(axis, event);
|
||||
std::cout << "set_ui_axismap: " << name << " = " << value << std::endl;
|
||||
|
||||
m_options->uinput_config.get_axis_map().bind(axis, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Couldn't convert string \"" + name + "=" + value + "\" to ui-axis-mapping");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Couldn't convert string \"" + name + "=" + value + "\" to ui-axis-mapping");
|
||||
XboxButton shift = string2btn(name.substr(0, j));
|
||||
XboxAxis axis = string2axis(name.substr(j+1));
|
||||
|
||||
if (axis != XBOX_AXIS_UNKNOWN)
|
||||
{
|
||||
event.set_axis_range(get_axis_min(axis),
|
||||
get_axis_max(axis));
|
||||
|
||||
std::cout << "set_ui_axismap: " << name << " = " << value << std::endl;
|
||||
|
||||
m_options->uinput_config.get_axis_map().bind(shift, axis, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Couldn't convert string \"" + name + "=" + value + "\" to ui-axis-mapping");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -562,14 +562,38 @@ uInput::send_rel_repetitive(const UIEvent& code, int value, int repeat_interval)
|
|||
void
|
||||
uInput::send_axis(XboxAxis code, int32_t value)
|
||||
{
|
||||
// FIXME: should be sending updates when the shift button changes,
|
||||
// not just when the axis changed
|
||||
if (axis_state[code] != value)
|
||||
{
|
||||
int old_value = axis_state[code];
|
||||
axis_state[code] = value;
|
||||
|
||||
const AxisEvent& event = cfg.get_axis_map().lookup(code);
|
||||
if (event.is_valid())
|
||||
event.send(*this, old_value, value);
|
||||
bool event_send = false;
|
||||
|
||||
// send all shifted stuff
|
||||
for(int shift = 1; shift < XBOX_BTN_MAX; ++shift)
|
||||
{
|
||||
if (button_state[shift])
|
||||
{
|
||||
const AxisEvent& event = cfg.get_axis_map().lookup(static_cast<XboxButton>(shift), code);
|
||||
if (event.is_valid())
|
||||
{
|
||||
event.send(*this, old_value, value);
|
||||
event_send = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sending regular axis, if no shifted events where send
|
||||
if (!event_send)
|
||||
{
|
||||
const AxisEvent& event = cfg.get_axis_map().lookup(code);
|
||||
if (event.is_valid())
|
||||
{
|
||||
event.send(*this, old_value, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -578,9 +602,12 @@ uInput::add_axis(XboxAxis code)
|
|||
{
|
||||
for(int n = 0; n < cfg.input_mapping_count(); ++n)
|
||||
{
|
||||
const AxisEvent& event = cfg.get_axis_map(n).lookup(code);
|
||||
if (event.is_valid())
|
||||
event.init(*this);
|
||||
for(int shift = 0; shift < XBOX_BTN_MAX; ++shift)
|
||||
{
|
||||
const AxisEvent& event = cfg.get_axis_map(n).lookup(static_cast<XboxButton>(shift), code);
|
||||
if (event.is_valid())
|
||||
event.init(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue