Added disconnect and renamed usbconnect to usbtool

This commit is contained in:
Ingo Ruhnke 2009-01-16 10:55:24 +01:00
parent db83b2a322
commit b96bc54421
4 changed files with 40 additions and 18 deletions

2
TODO
View file

@ -9,8 +9,6 @@ Pre Release Testing:
Stuff to do before 0.5 release:
===============================
* rename usbattach to usbconnect, add disconnect commands
* guitar doesn't get a guide button?!
* add --detach option that detaches any existing driver

View file

@ -330,9 +330,9 @@ LinuxUinput::update(float delta)
struct uinput_ff_upload upload;
memset(&upload, 0, sizeof(upload));
// *VERY* important, without this you
// break the kernel and have to reboot due
// to dead hanging process
// *VERY* important, without this you break
// the kernel and have to reboot due to dead
// hanging process
upload.request_id = ev.value;
ioctl(fd, UI_BEGIN_FF_UPLOAD, &upload);
@ -354,15 +354,15 @@ LinuxUinput::update(float delta)
struct uinput_ff_erase erase;
memset(&erase, 0, sizeof(erase));
// *VERY* important, without this you
// break the kernel and have to reboot due
// to dead hanging process
// *VERY* important, without this you break
// the kernel and have to reboot due to dead
// hanging process
erase.request_id = ev.value;
ioctl(fd, UI_BEGIN_FF_ERASE, &erase);
std::cout << "FF_ERASE: rumble erase: effect_id = " << erase.effect_id << std::endl;
erase.retval = 0; // FIXME: is this used?
erase.retval = 0;
ioctl(fd, UI_END_FF_ERASE, &erase);
}

View file

@ -6,6 +6,6 @@ env.Program("evtest", ["evtest.c"])
env.Program("usbcat", ["usbcat.cpp"], LIBS = ["usb"])
env.Program("usbdebug", ["usbdebug.cpp"], LIBS = ["usb", "pthread"])
env.Program("evtestplus", ["evtestplus.cpp"])
env.Program("usbattach", ["usbattach.c"])
env.Program("usbtool", ["usbtool.c"])
# EOF #

View file

@ -27,17 +27,38 @@
#include <sys/stat.h>
#include <sys/types.h>
void print_usage(int argc, char** argv)
{
printf("Usage: %s connect /dev/bus/usb/${BUS}/${DEV}\n", argv[0]);
printf(" %s disconnect /dev/bus/usb/${BUS}/${DEV}\n", argv[0]);
printf("Disconnect or reconnect USB devices\n");
}
int main(int argc, char** argv)
{
if (argc != 2)
if (argc != 3)
{
printf("Usage: %s /dev/bus/usb/${BUS}/${DEV}\n", argv[0]);
printf("Reconnect USB devices after they got disconnected\n");
print_usage(argc, argv);
return EXIT_FAILURE;
}
else
{
int fd = open(argv[1], O_RDWR);
int connect;
if (strcmp(argv[1], "connect") == 0)
{
connect = 1;
}
else if (strcmp(argv[1], "disconnect") == 0)
{
connect = 0;
}
else
{
print_usage(argc, argv);
return EXIT_FAILURE;
}
int fd = open(argv[2], O_RDWR);
if (fd < 0)
{
@ -49,20 +70,23 @@ int main(int argc, char** argv)
struct usbdevfs_ioctl command;
command.ifno = 0; // interface number, does it matter?
command.ioctl_code = USBDEVFS_CONNECT;
if (connect)
command.ioctl_code = USBDEVFS_CONNECT;
else
command.ioctl_code = USBDEVFS_DISCONNECT;
command.data = NULL;
int ret = ioctl(fd, USBDEVFS_IOCTL, &command);
if (ret < 0)
{
printf("%s: Could not issue usb connect on %s: %s\n", argv[0], argv[1], strerror(errno));
printf("%s: Could not issue usb %s on %s: %s\n", argv[0], argv[1], argv[2], strerror(errno));
close(fd);
return EXIT_FAILURE;
}
else
{
printf("%s: reconnect of %s successful\n", argv[0], argv[1]);
printf("%s: %s of %s successful\n", argv[0], argv[1], argv[2]);
close(fd);
return EXIT_SUCCESS;
}