diff --git a/examples/calibrate.macro b/examples/calibrate.macro new file mode 100644 index 0000000..62763c0 --- /dev/null +++ b/examples/calibrate.macro @@ -0,0 +1,31 @@ +# Simple Macro that automate calibration in old DOS games + +send ABS_X 0 +send ABS_Y 0 +wait 500 +send JS_0 1 +wait 200 +send JS_0 0 + +send ABS_X -32768 +send ABS_Y -32768 +wait 500 +send JS_0 1 +wait 200 +send JS_0 0 + +send ABS_X 32767 +send ABS_Y 32767 +wait 500 +send JS_0 1 +wait 200 +send JS_0 0 + +send ABS_X 0 +send ABS_Y 0 +wait 500 +send JS_0 1 +wait 500 +send JS_0 0 + +# EOF # diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 2a6723d..eb33bf5 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -712,13 +712,11 @@ CommandLineParser::parse_args(int argc, char** argv, Options* options) break; case OPTION_UI_AXISMAP: - process_name_value_string(opt.argument, boost::bind(&UInputOptions::set_ui_axismap, - boost::ref(opts.get_controller_options().uinput), _1, _2)); + process_name_value_string(opt.argument, boost::bind(&CommandLineParser::set_ui_axismap, this, _1, _2)); break; case OPTION_UI_BUTTONMAP: - process_name_value_string(opt.argument, boost::bind(&UInputOptions::set_ui_buttonmap, - boost::ref(opts.get_controller_options().uinput), _1, _2)); + process_name_value_string(opt.argument, boost::bind(&CommandLineParser::set_ui_buttonmap, this, _1, _2)); break; case OPTION_MOUSE: @@ -1022,13 +1020,135 @@ CommandLineParser::set_device_name(const std::string& name, const std::string& v void CommandLineParser::set_ui_buttonmap(const std::string& name, const std::string& value) { - m_options->get_controller_options().uinput.set_ui_buttonmap(name, value); + set_ui_buttonmap(m_options->get_controller_options().uinput.get_btn_map(), + name, value); +} + +void +CommandLineParser::set_ui_buttonmap(ButtonMap& btn_map, const std::string& name, const std::string& value) +{ + ButtonEventPtr event; + + XboxButton shift = XBOX_BTN_UNKNOWN; + XboxButton btn = XBOX_BTN_UNKNOWN; + std::vector filters; + + typedef boost::tokenizer > tokenizer; + tokenizer tokens(name, boost::char_separator("^", "", boost::keep_empty_tokens)); + int idx = 0; + for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx) + { + switch(idx) + { + case 0: // shift+key portion + { + std::string::size_type j = t->find('+'); + if (j == std::string::npos) + { + shift = XBOX_BTN_UNKNOWN; + btn = string2btn(*t); + } + else + { + shift = string2btn(t->substr(0, j)); + btn = string2btn(t->substr(j+1)); + } + + if (value.empty()) + { // if no rhs value is given, add filters to the current binding + event = btn_map.lookup(shift, btn); + } + else + { + event = ButtonEvent::from_string(value); + if (event) + { + btn_map.bind(shift, btn, event); + } + } + } + break; + + default: + { // filter + if (event) + { + event->add_filter(ButtonFilter::from_string(*t)); + } + } + break; + } + } } void CommandLineParser::set_ui_axismap(const std::string& name, const std::string& value) { - m_options->get_controller_options().uinput.set_ui_axismap(name, value); + set_ui_axismap(m_options->get_controller_options().uinput.get_axis_map(), + name, value); +} + +void +CommandLineParser::set_ui_axismap(AxisMap& axis_map, const std::string& name, const std::string& value) +{ + AxisEventPtr event; + + XboxButton shift = XBOX_BTN_UNKNOWN; + XboxAxis axis = XBOX_AXIS_UNKNOWN; + std::vector filters; + + typedef boost::tokenizer > tokenizer; + tokenizer tokens(name, boost::char_separator("^", "", boost::keep_empty_tokens)); + int idx = 0; + for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx) + { + switch(idx) + { + case 0: // shift+key portion + { + std::string::size_type j = t->find('+'); + if (j == std::string::npos) + { + shift = XBOX_BTN_UNKNOWN; + axis = string2axis(*t); + } + else + { + shift = string2btn(t->substr(0, j)); + axis = string2axis(t->substr(j+1)); + } + + if (value.empty()) + { // if no rhs value is given, add filters to the current binding + event = axis_map.lookup(shift, axis); + } + else + { + event = AxisEvent::from_string(value); + if (event) + { + if (axis != XBOX_AXIS_UNKNOWN) + { + event->set_axis_range(get_axis_min(axis), + get_axis_max(axis)); + } + + axis_map.bind(shift, axis, event); + } + } + } + break; + + default: + { // filter + if (event) + { + event->add_filter(AxisFilter::from_string(*t)); + } + } + break; + } + } } void @@ -1193,15 +1313,15 @@ CommandLineParser::read_alt_config_file(const std::string& filename) void CommandLineParser::set_ui_buttonmap_n(int controller, int config, const std::string& name, const std::string& value) { - m_options->controller_slots[controller].get_options(config) - .uinput.set_ui_buttonmap(name, value); + set_ui_buttonmap(m_options->controller_slots[controller].get_options(config).uinput.get_btn_map(), + name, value); } void CommandLineParser::set_ui_axismap_n(int controller, int config, const std::string& name, const std::string& value) { - m_options->controller_slots[controller].get_options(config) - .uinput.set_ui_axismap(name, value); + set_ui_axismap(m_options->controller_slots[controller].get_options(config).uinput.get_axis_map(), + name, value); } void diff --git a/src/command_line_options.hpp b/src/command_line_options.hpp index a0ea0ee..5c3a55f 100644 --- a/src/command_line_options.hpp +++ b/src/command_line_options.hpp @@ -25,6 +25,8 @@ class Options; class Xboxdrv; +class ButtonMap; +class AxisMap; class CommandLineParser { @@ -47,7 +49,9 @@ private: void set_device_name(const std::string& name, const std::string& value); void set_device_usbid(const std::string& name, const std::string& value); + void set_ui_buttonmap(ButtonMap& btn_map, const std::string& name, const std::string& value); void set_ui_buttonmap(const std::string& name, const std::string& value); + void set_ui_axismap(AxisMap& axis_map, const std::string& name, const std::string& value); void set_ui_axismap(const std::string& name, const std::string& value); void set_modifier(const std::string& name, const std::string& value); diff --git a/src/uinput_options.cpp b/src/uinput_options.cpp index 404fcde..4726f92 100644 --- a/src/uinput_options.cpp +++ b/src/uinput_options.cpp @@ -209,126 +209,6 @@ UInputOptions::dpad_only() get_axis_map().bind(XBOX_AXIS_DPAD_Y, AxisEvent::create_abs(DEVICEID_AUTO, ABS_Y, -1, 1, 0, 0)); } -void -UInputOptions::set_ui_axismap(const std::string& name, const std::string& value) -{ - AxisEventPtr event; - - XboxButton shift = XBOX_BTN_UNKNOWN; - XboxAxis axis = XBOX_AXIS_UNKNOWN; - std::vector filters; - - typedef boost::tokenizer > tokenizer; - tokenizer tokens(name, boost::char_separator("^", "", boost::keep_empty_tokens)); - int idx = 0; - for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx) - { - switch(idx) - { - case 0: // shift+key portion - { - std::string::size_type j = t->find('+'); - if (j == std::string::npos) - { - shift = XBOX_BTN_UNKNOWN; - axis = string2axis(*t); - } - else - { - shift = string2btn(t->substr(0, j)); - axis = string2axis(t->substr(j+1)); - } - - if (value.empty()) - { // if no rhs value is given, add filters to the current binding - event = get_axis_map().lookup(shift, axis); - } - else - { - event = AxisEvent::from_string(value); - if (event) - { - if (axis != XBOX_AXIS_UNKNOWN) - { - event->set_axis_range(get_axis_min(axis), - get_axis_max(axis)); - } - - get_axis_map().bind(shift, axis, event); - } - } - } - break; - - default: - { // filter - if (event) - { - event->add_filter(AxisFilter::from_string(*t)); - } - } - break; - } - } -} - -void -UInputOptions::set_ui_buttonmap(const std::string& name, const std::string& value) -{ - ButtonEventPtr event; - - XboxButton shift = XBOX_BTN_UNKNOWN; - XboxButton btn = XBOX_BTN_UNKNOWN; - std::vector filters; - - typedef boost::tokenizer > tokenizer; - tokenizer tokens(name, boost::char_separator("^", "", boost::keep_empty_tokens)); - int idx = 0; - for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx) - { - switch(idx) - { - case 0: // shift+key portion - { - std::string::size_type j = t->find('+'); - if (j == std::string::npos) - { - shift = XBOX_BTN_UNKNOWN; - btn = string2btn(*t); - } - else - { - shift = string2btn(t->substr(0, j)); - btn = string2btn(t->substr(j+1)); - } - - if (value.empty()) - { // if no rhs value is given, add filters to the current binding - event = get_btn_map().lookup(shift, btn); - } - else - { - event = ButtonEvent::from_string(value); - if (event) - { - get_btn_map().bind(shift, btn, event); - } - } - } - break; - - default: - { // filter - if (event) - { - event->add_filter(ButtonFilter::from_string(*t)); - } - } - break; - } - } -} - void UInputOptions::guitar() { diff --git a/src/uinput_options.hpp b/src/uinput_options.hpp index bbf6c6d..fc2c665 100644 --- a/src/uinput_options.hpp +++ b/src/uinput_options.hpp @@ -44,9 +44,6 @@ public: void dpad_as_button(); void dpad_only(); - - void set_ui_buttonmap(const std::string& name, const std::string& value); - void set_ui_axismap(const std::string& name, const std::string& value); /** @}*/ /** \addtogroup access Access Functions