chiark / gitweb /
hostside: hidraw-ioctl, hiddev-ioctl, kdled-ioctl: build by default
[trains.git] / hostside / neo-usb.c
1 /**/
2
3 int main(void) {
4   usb_init();
5   usb_find_busses();
6   usb_find_devices();
7   struct usb_bus busses= usb_get_busses();
8   struct usb_bus *bus;
9   struct usb_device *dev;
10   for (bus=busses; bus; bus=bus->next) {
11     for (dev=bus->devices; dev; dev=dev->next) {
12       if (dev->descriptor.idVendor != 0x18b ||
13           dev->descriptor.idProduct != 0x123)
14         continue;
15       goto found;
16     }
17   }
18   die("not found");
19
20   assert(dev->bNumConfigurations == 1);
21   assert(dev->config[0].bNumInterfaces == 2);
22   assert(dev->config[0].interface[0].
23
24   usb_dev_handle *dh= usb_open(dev);
25   int r= usb_claim_interface(dh, 0);  assert(r>=0);
26
27   r= usb_set_configuration(dh, dev->config[0].bConfigurationValue);
28   assert(r>=0);
29
30   usb_dev_handle *dh2= usb_open(dev);
31   int r= usb_claim_interface(dh, 1);  assert(r>=0);
32
33   printf("ok\n");
34   char hbuf[100];
35   uint8_t cbuf[ sizeof(hbuf)/2 + 10 ];
36   for (;;) {
37   n:
38     putchar('>');
39     fflush(stdout);
40     if (!fgets(hbuf, sizeof(hbuf), stdin)) break;
41     const char *p= hbuf;
42     uint8_t *o= cbuf;
43     for (;;) {
44       char h3[3];
45       int c= *p++;
46       if (c=='\n') break;
47       if (isspace((unsigned char)c)) continue;
48       if (!c) die("bad line");
49       h3[0]= c;
50       c= *p++;
51       if (!c) die("bad line");
52       h3[1]= c;
53       h3[2]= 0;
54       char *ep;
55       o= strtoul(h3, &ep, 16);
56       if (ep != h3+2) { fprintf(stderr,"bad hex\n"); goto n; }
57     }
58     r= usb_control_msg(dh, 
59
60   usb_control_msg