Multi-USB::MissileLauncher for Win32 より
--- usblauncher-0.0.3/ctlmissile.c 2007-01-15 00:11:00.000000000 +0900
+++ ctlmissile.c 2007-05-01 21:34:26.625000000 +0900
@@ -16,6 +16,14 @@
int debug = 0;
+#ifdef WIN32
+#include <windows.h>
+#define msec_sleep(msec) Sleep(msec)
+#else
+#include <unistd.h>
+#define msec_sleep(msec) usleep(msec * 1000)
+#endif
+
/*
* Command to control original M&S USB missile launcher.
*/
@@ -31,9 +39,11 @@
exit(EXIT_FAILURE);
}
+#ifdef LINUX
/* Detach kernel driver (usbhid) from device interface and claim */
usb_detach_kernel_driver_np(launcher, 0);
usb_detach_kernel_driver_np(launcher, 1);
+#endif
ret = usb_set_configuration(launcher, 1);
if (ret < 0) {
@@ -41,11 +51,13 @@
exit(EXIT_FAILURE);
}
+#ifdef LINUX
ret = usb_claim_interface(launcher, 1);
if (ret < 0) {
perror("Unable to claim interface");
exit(EXIT_FAILURE);
}
+#endif
ret = usb_set_altinterface(launcher, 0);
if (ret < 0) {
@@ -149,20 +161,25 @@
exit(EXIT_FAILURE);
}
+#ifdef LINUX
/* Detach kernel driver (usbhid) from device interface and claim */
usb_detach_kernel_driver_np(launcher, 0);
usb_detach_kernel_driver_np(launcher, 1);
+#endif
ret = usb_set_configuration(launcher, 1);
if (ret < 0) {
perror("Unable to set device configuration");
exit(EXIT_FAILURE);
}
+
+#ifdef LINUX
ret = usb_claim_interface(launcher, 0);
if (ret < 0) {
perror("Unable to claim interface");
exit(EXIT_FAILURE);
}
+#endif
memset(data, 0, 8);
if (!strcmp(cmd, "up")) {
@@ -201,11 +218,17 @@
{
struct usb_bus *busses, *bus;
struct usb_device *dev = NULL;
+ int msec = 0;
+ int found_dev = 0;
- if (argc != 2) {
- printf("Usage: ctlmissile [ up | down | left | right | fire ]\n");
+ if (!(argc == 2 || argc == 3)) {
+ printf("Usage: ctlmissile [ up | down | left | right | fire | stop ] [ 3000 ]\n");
exit(EXIT_FAILURE);
}
+ if (argc == 3) {
+ msec = atol(argv[2]);
+ if (msec < 0) msec = 0;
+ }
usb_init();
usb_find_busses();
@@ -223,17 +246,25 @@
if (dev->descriptor.idVendor == 0x1130 &&
dev->descriptor.idProduct == 0x0202) {
send_command_ms(dev, argv[1]);
- break;
+ if (msec > 0) {
+ msec_sleep(msec);
+ send_command_ms(dev, "stop");
+ }
+ found_dev++;
}
if (dev->descriptor.idVendor == 0x1941 &&
dev->descriptor.idProduct == 0x8021) {
send_command_cheeky(dev, argv[1]);
- break;
+ if (msec > 0) {
+ msec_sleep(msec);
+ send_command_cheeky(dev, "stop");
+ }
+ found_dev++;
}
}
}
- if (!dev) {
+ if (found_dev == 0) {
fprintf(stderr, "Unable to find device.\n");
exit(EXIT_FAILURE);
}