diff --git a/command_line_options.hpp b/command_line_options.hpp index a58ecef..621bb24 100644 --- a/command_line_options.hpp +++ b/command_line_options.hpp @@ -50,6 +50,8 @@ struct CommandLineOptions int deadzone; std::vector<ButtonMapping> button_map; std::vector<AxisMapping> axis_map; + std::vector<AutoFireMapping> autofire_map; + std::vector<RelativeAxisMapping> relative_axis_map; bool square_axis; CommandLineOptions(); diff --git a/xbox360_wireless_controller.cpp b/xbox360_wireless_controller.cpp index 6d4b326..16c29de 100644 --- a/xbox360_wireless_controller.cpp +++ b/xbox360_wireless_controller.cpp @@ -17,6 +17,7 @@ */ #include <usb.h> +#include <errno.h> #include <assert.h> #include <sstream> #include <iostream> diff --git a/xboxdrv.cpp b/xboxdrv.cpp index 270cd1e..b7c78e4 100644 --- a/xboxdrv.cpp +++ b/xboxdrv.cpp @@ -263,6 +263,17 @@ void string2axismap(const std::string& str, std::vector<AxisMapping>& lst) lst.push_back(mapping); } } + +void string2relative_axis_map(const std::string& str, std::vector<RelativeAxisMapping>& lst) +{ + +} + +void string2autofire_map(const std::string& str, std::vector<AutoFireMapping>& lst) +{ + +} + void list_controller() { @@ -442,6 +453,8 @@ void print_command_line_help(int argc, char** argv) std::cout << " -b, --buttonmap MAP Remap the buttons as specified by MAP" << std::endl; std::cout << " -a, --axismap MAP Remap the axis as specified by MAP" << std::endl; std::cout << " --square-axis Cause the diagonals to be reported as (1,1) instead of (0.7, 0.7)\n" << std::endl; + std::cout << " --relative-axis MAP Make an axis emulate a joystick throttle" << std::endl; + std::cout << " --autofire MAP Cause the given buttons to act as autofire" << std::endl; std::cout << std::endl; std::cout << "Report bugs to Ingo Ruhnke <grumbel@gmx.de>" << std::endl; } @@ -699,6 +712,32 @@ void parse_command_line(int argc, char** argv, CommandLineOptions& opts) opts.uinput_config.trigger_as_button = true; } } + else if (strcmp("--autofire", argv[i]) == 0) + { + ++i; + if (i < argc) + { + string2autofire_map(argv[i], opts.autofire_map); + } + else + { + std::cout << "Error: " << argv[i-1] << " expected an argument" << std::endl; + exit(EXIT_FAILURE); + } + } + else if (strcmp("--relative-axis", argv[i]) == 0) + { + ++i; + if (i < argc) + { + string2relative_axis_map(argv[i], opts.relative_axis_map); + } + else + { + std::cout << "Error: " << argv[i-1] << " expected an argument" << std::endl; + exit(EXIT_FAILURE); + } + } else if (strcmp("--square-axis", argv[i]) == 0) { opts.square_axis = true; @@ -934,6 +973,33 @@ void apply_deadzone(XboxGenericMsg& msg, int deadzone) } } +class RelativeAxisModifier +{ +public: + RelativeAxisModifier(const std::vector<RelativeAxisMapping>& relative_axis_map) + { + } + + void update(XboxGenericMsg& msg) + { + } +}; + +class AutoFireModifier +{ +private: + +public: + AutoFireModifier(const std::vector<AutoFireMapping>& autofire_map) + { + + } + + void update(XboxGenericMsg& msg) + { + } +}; + void controller_loop(uInput* uinput, XboxGenericController* controller, CommandLineOptions& opts) { int timeout = 0; // 0 == no timeout @@ -957,31 +1023,37 @@ void controller_loop(uInput* uinput, XboxGenericController* controller, CommandL if (!opts.axis_map.empty()) apply_axis_map(msg, opts.axis_map); + } + else + { + memcpy(&msg, &oldmsg, sizeof(oldmsg)); + } - if (memcmp(&msg, &oldmsg, sizeof(XboxGenericMsg))) - { // Only send a new event out if something has changed, - // this is useful since some controllers send events - // even if nothing has changed, deadzone can cause this - // too - oldmsg = msg; + // Apply modifier - if (!opts.silent) - std::cout << msg << std::endl; + if (memcmp(&msg, &oldmsg, sizeof(XboxGenericMsg))) + { // Only send a new event out if something has changed, + // this is useful since some controllers send events + // even if nothing has changed, deadzone can cause this + // too + oldmsg = msg; - if (uinput) - uinput->send(msg); + if (!opts.silent) + std::cout << msg << std::endl; + + if (uinput) + uinput->send(msg); - if (opts.rumble) + if (opts.rumble) + { + if (opts.gamepad_type == GAMEPAD_XBOX) { - if (opts.gamepad_type == GAMEPAD_XBOX) - { - controller->set_rumble(msg.xbox.lt, msg.xbox.rt); - } - else if (opts.gamepad_type == GAMEPAD_XBOX360 || - opts.gamepad_type == GAMEPAD_XBOX360_WIRELESS) - { - controller->set_rumble(msg.xbox360.lt, msg.xbox360.rt); - } + controller->set_rumble(msg.xbox.lt, msg.xbox.rt); + } + else if (opts.gamepad_type == GAMEPAD_XBOX360 || + opts.gamepad_type == GAMEPAD_XBOX360_WIRELESS) + { + controller->set_rumble(msg.xbox360.lt, msg.xbox360.rt); } } } diff --git a/xboxdrv.hpp b/xboxdrv.hpp index 7cab5ff..92e4058 100644 --- a/xboxdrv.hpp +++ b/xboxdrv.hpp @@ -38,6 +38,16 @@ struct AxisMapping { XboxAxis rhs; bool invert; }; + +struct AutoFireMapping { + XboxButton button; + int frequency; +}; + +struct RelativeAxisMapping { + XboxAxis axis; + int speed; +}; #endif