/**************************************************************************** This file contains the top-level functions, which should be used almost exclusively by application programs. ****************************************************************************/ #include #include #include "legoctl.h" int lct_find_bricks(lct_brick_list_t * bricks, unsigned int flags) { int count = 0; LCT_SET_COUNT(bricks,0); if (flags & LCT_PROBE_DEV_NXT) count += lct_find_nxt_bricks(bricks); if (flags & LCT_PROBE_DEV_RCX) count += lct_find_rcx_bricks(bricks); LCT_SET_COUNT(bricks, count); return count; } int lct_find_nxt_bricks(lct_brick_list_t * bricks) { int count = 0; count += lct_find_nxt_usb(bricks); count += lct_find_nxt_bluetooth(bricks); LCT_SET_COUNT(bricks, count); return count; } int lct_find_nxt_usb(lct_brick_list_t * bricks) { struct usb_bus *busses, *bus; struct usb_device *dev; int count = 0, bus_num = 0, dev_num = 0; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus != NULL; bus = bus->next, ++bus_num) { for (dev = bus->devices; dev != NULL; dev = dev->next, ++dev_num) { if (dev->descriptor.idVendor == LCT_VENDOR_LEGO && dev->descriptor.idProduct == LCT_PRODUCT_NXT) { printf("Found NXT on USB bus %d, dev %d.\n", bus_num, dev_num); if ( usb_device_info(dev) == 0 ) { lct_init_brick(&bricks->bricks[count],LCT_NXT); NXT_SET_USB_DEV(&(bricks->bricks[count].nxt),dev); ++count; } } } } LCT_SET_COUNT(bricks, count); return count; } int lct_find_nxt_bluetooth(lct_brick_list_t *bricks) { LCT_SET_COUNT(bricks, 0); return 0; } int lct_find_rcx_bricks(lct_brick_list_t *bricks) { int count = 0; LCT_SET_COUNT(bricks,count); return count; }