xboxdrv-daemon reads list of supported devices from xboxdrv, cleaned up output some more

This commit is contained in:
Ingo Ruhnke 2009-02-21 12:37:34 +01:00
parent 92408e0d00
commit 1ff3476852
5 changed files with 73 additions and 64 deletions

View file

@ -22,6 +22,7 @@
#include <sstream>
#include <iostream>
#include <boost/format.hpp>
#include "command_line_options.hpp"
#include "xboxmsg.hpp"
#include "helper.hpp"
#include "xbox360_controller.hpp"
@ -207,10 +208,13 @@ Xbox360Controller::read(XboxGenericMsg& msg, bool verbose, int timeout)
}
else if (ret == 3 && data[0] == 0x08 && data[1] == 0x03)
{
if (data[2] == 0x00)
std::cout << "Headset: none";
else if (data[2] == 0x02)
std::cout << "Headset: none";
if (!command_line_options->quiet)
{
if (data[2] == 0x00)
std::cout << "Headset: none";
else if (data[2] == 0x02)
std::cout << "Headset: none";
}
}
else if (ret == 20 && data[0] == 0x00 && data[1] == 0x14)
{

View file

@ -387,6 +387,7 @@ void print_command_line_help(int argc, char** argv)
std::cout << " -i, --id N use controller with id N (default: 0)" << std::endl;
std::cout << " -w, --wid N use wireless controller with wid N (default: 0)" << std::endl;
std::cout << " -L, --list-controller list available controllers" << std::endl;
std::cout << " --list-supported-devices list supported devices (used by xboxdrv-daemon.py)" << std::endl;
std::cout << " -R, --test-rumble map rumbling to LT and RT (for testing only)" << std::endl;
std::cout << " --no-uinput do not try to start uinput event dispatching" << std::endl;
std::cout << " --mimic-xpad Causes xboxdrv to use the same axis and button names as the xpad kernel driver" << std::endl;
@ -892,6 +893,19 @@ void parse_command_line(int argc, char** argv, CommandLineOptions& opts)
exit(EXIT_FAILURE);
}
}
else if (strcmp(argv[i], "--list-supported-devices") == 0)
{
for(unsigned int i = 0; i < sizeof(xpad_devices)/sizeof(XPadDevice); ++i)
{
std::cout << boost::format("%s 0x%04x 0x%04x %s\n")
% gamepadtype_to_string(xpad_devices[i].type)
% int(xpad_devices[i].idVendor)
% int(xpad_devices[i].idProduct)
% xpad_devices[i].name;
}
exit(EXIT_FAILURE);
}
else if (strcmp(argv[i], "--list-controller") == 0 ||
strcmp(argv[i], "-L") == 0)
{
@ -1283,12 +1297,15 @@ void on_sigint(int)
{
if (global_exit_xboxdrv)
{
std::cout << "Ctrl-c pressed twice, exiting hard" << std::endl;
if (!command_line_options->quiet)
std::cout << "Ctrl-c pressed twice, exiting hard" << std::endl;
exit(EXIT_SUCCESS);
}
else
{
std::cout << "Shutdown initiated, press Ctrl-c again if nothing is happening" << std::endl;
if (!command_line_options->quiet)
std::cout << "Shutdown initiated, press Ctrl-c again if nothing is happening" << std::endl;
global_exit_xboxdrv = true;
if (global_controller)
global_controller->set_led(0);

View file

@ -16,12 +16,40 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <boost/format.hpp>
#include <iostream>
#include "helper.hpp"
#include "command_line_options.hpp"
#include "xboxmsg.hpp"
std::string gamepadtype_to_string(const GamepadType& type)
{
switch (type)
{
case GAMEPAD_XBOX360:
return "xbox360";
case GAMEPAD_XBOX360_WIRELESS:
return "xbox360-wireless";
case GAMEPAD_XBOX:
return "xbox";
case GAMEPAD_XBOX_MAT:
return "xbox-mat";
case GAMEPAD_XBOX360_GUITAR:
return "xbox360-guitar";
case GAMEPAD_FIRESTORM:
return "firestorm";
default:
assert(!"Unknown gamepad type supplied");
}
}
std::ostream& operator<<(std::ostream& out, const GamepadType& type)
{
switch (type)

View file

@ -250,6 +250,8 @@ XboxButton string2btn(const std::string& str_);
XboxAxis string2axis(const std::string& str_);
std::string btn2string(XboxButton btn);
std::string axis2string(XboxAxis axis);
std::string gamepadtype_to_string(const GamepadType& type);
#endif

View file

@ -27,62 +27,9 @@ import signal
import subprocess
from optparse import OptionParser
# This list is a direct copy of src/xboxmsg.hpp
xboxdrv_device_list = [
( "xbox", 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)" ),
( "xbox", 0x045e, 0x0285, "Microsoft X-Box pad (Japan)" ),
( "xbox", 0x045e, 0x0285, "Microsoft Xbox Controller S" ),
( "xbox", 0x045e, 0x0287, "Microsoft Xbox Controller S" ),
( "xbox", 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)" ),
( "xbox", 0x045e, 0x0289, "Microsoft Xbox Controller S" ),
( "xbox", 0x046d, 0xca84, "Logitech Xbox Cordless Controller" ),
( "xbox", 0x046d, 0xca88, "Logitech Compact Controller for Xbox" ),
( "xbox", 0x05fd, 0x1007, "Mad Catz Controller (unverified)" ),
( "xbox", 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)" ),
( "xbox", 0x0738, 0x4516, "Mad Catz Control Pad" ),
( "xbox", 0x0738, 0x4522, "Mad Catz LumiCON" ),
( "xbox", 0x0738, 0x4526, "Mad Catz Control Pad Pro" ),
( "xbox", 0x0738, 0x4536, "Mad Catz MicroCON" ),
( "xbox", 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller" ),
( "xbox", 0x0c12, 0x8802, "Zeroplus Xbox Controller" ),
( "xbox", 0x0c12, 0x8810, "Zeroplus Xbox Controller" ),
( "xbox", 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*" ),
( "xbox", 0x0e4c, 0x1097, "Radica Gamester Controller" ),
( "xbox", 0x0e4c, 0x2390, "Radica Games Jtech Controller" ),
( "xbox", 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller" ),
( "xbox", 0x0e6f, 0x0005, "Eclipse wireless Controller" ),
( "xbox", 0x0e6f, 0x0006, "Edge wireless Controller" ),
( "xbox", 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor" ),
( "xbox", 0x0f30, 0x0202, "Joytech Advanced Controller" ),
( "xbox", 0x0f30, 0x8888, "BigBen XBMiniPad Controller" ),
( "xbox", 0x102c, 0xff0c, "Joytech Wireless Advanced Controller" ),
( "xbox", 0x044f, 0x0f07, "Thrustmaster, Inc. Controller" ),
( "xbox360", 0x045e, 0x028e, "Microsoft Xbox 360 Controller" ),
( "xbox360", 0x0738, 0x4716, "Mad Catz Xbox 360 Controller" ),
( "xbox360", 0x0738, 0x4726, "Mad Catz Xbox 360 Controller" ),
( "xbox360", 0x0f0d, 0x000d, "Hori Fighting Stick Ex2" ),
( "xbox360", 0x162e, 0xbeef, "Joytech Neo-Se Take2" ),
( "xbox360", 0x046d, 0xc242, "Logitech ChillStream" ),
( "xbox360-guitar", 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer" ),
( "xbox360-guitar", 0x1bad, 0x0002, "Harmonix Guitar for Xbox 360" ),
( "xbox360-guitar", 0x1bad, 0x0003, "Harmonix Drum Kit for Xbox 360" ),
( "xbox360-wireless", 0x045e, 0x0291, "Microsoft Xbox 360 Wireless Controller" ),
( "xbox360-wireless", 0x045e, 0x0719, "Microsoft Xbox 360 Wireless Controller (PC)" ),
( "xbox-mat", 0x0738, 0x4540, "Mad Catz Beat Pad" ),
( "xbox-mat", 0x0738, 0x6040, "Mad Catz Beat Pad Pro" ),
( "xbox-mat", 0x0c12, 0x8809, "RedOctane Xbox Dance Pad" ),
( "xbox-mat", 0x12ab, 0x8809, "Xbox DDR dancepad" ),
( "xbox-mat", 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)" ),
( "xbox360", 0x12ab, 0x0004, "DDR Universe 2 Mat" ),
( "firestorm", 0x044f, 0xb304, "ThrustMaster, Inc. Firestorm Dual Power" ),
]
class DeviceManager:
def __init__(self, xboxdrv="xboxdrv", attach=None, detach=None, xboxdrv_args=[], verbose = False):
def __init__(self, xboxdrv_device_list=[], xboxdrv="xboxdrv", attach=None, detach=None, xboxdrv_args=[], verbose = False):
self.xboxdrv_device_list = xboxdrv_device_list
self.xboxdrv_bin = xboxdrv
self.attach_script = attach
self.detach_script = detach
@ -189,12 +136,12 @@ class DeviceManager:
self.xboxdrv_kill(udi)
def is_xboxdrv_device(self, arg_vendor_id, arg_product_id):
for (type, vendor_id, product_id, name) in xboxdrv_device_list:
for (type, vendor_id, product_id, name) in self.xboxdrv_device_list:
# print arg_vendor_id, vendor_id, arg_product_id, product_id
if arg_vendor_id == vendor_id and arg_product_id == product_id:
return (type, vendor_id, product_id, name)
return None
if __name__ == '__main__':
# parse options
parser = OptionParser(usage = "%prog [OPTIONS] -- [XBOXDRV ARGS]",
@ -210,9 +157,20 @@ if __name__ == '__main__':
help="Be verbose with printed output")
(opts, args) = parser.parse_args()
# Read list of supported devices from xboxdrv
xboxdrv_device_list = []
for i in subprocess.Popen([opts.xboxdrv, '--list-supported-devices'],
stdout=subprocess.PIPE).stdout:
lst = i.rstrip().split(' ', 3)
xboxdrv_device_list.append((lst[0],
int(lst[1], 16),
int(lst[2], 16),
lst[3]))
DBusGMainLoop(set_as_default=True)
mgr = DeviceManager(xboxdrv = opts.xboxdrv, xboxdrv_args = args,
mgr = DeviceManager(xboxdrv_device_list = xboxdrv_device_list,
xboxdrv = opts.xboxdrv, xboxdrv_args = args,
attach = opts.attach, detach = opts.detach,
verbose = opts.verbose)
loop = gobject.MainLoop()