int main(void) { libusb_device **devs; int r; ssize_t cnt; r = libusb_init(NULL); if (r < 0) return r; cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) return (int) cnt; print_devs(devs); libusb_free_device_list(devs, 1); libusb_exit(NULL); return 0; }
int32_t main(void) { libusb_device **devs; int32_t r; ssize_t cnt; r = libusb_init(NULL); if(r < 0) { return r; } printf("Looking for smartreader compatible devices...\n"); cnt = libusb_get_device_list(NULL, &devs); if(cnt < 0) { return (int32_t) cnt; } print_devs(devs); libusb_free_device_list(devs, 1); libusb_exit(NULL); return 0; }
int main(void) { #ifdef USE_LIBUSB_1_0 libusb_device_handle *usbhandle; #else usb_dev_handle *usbhandle; #endif #if 0 libusb_device **devs; int r; ssize_t cnt; r = libusb_init(NULL); if (r < 0) return r; cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) return (int) cnt; print_devs(devs); libusb_free_device_list(devs, 1); libusb_exit(NULL); #endif if(!usbdevice_open(&usbhandle)) { testWrite(usbhandle); usbasp_initialize(usbhandle); } return 0; }
int main(int argc, char *argv[]) { libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices libusb_context *ctx = NULL; //a libusb session libusb_device_handle *dev_handle; int r; size_t cnt; int actual; pthread_t tid; r = libusb_init(&ctx); if (r < 0) { printf("Initialise Error %d\n", r); return 1; } printf("libusb initialised\n"); libusb_set_debug(ctx, 3); // set verbosity level to 3, as suggested in documentation cnt = libusb_get_device_list(ctx, &devs); if (cnt < 0) { printf("Error getting device list %d\n", (int)cnt); return 1; } printf("Found %d USB devices\n", (int)cnt); print_devs(devs); libusb_free_device_list(devs, 1); /* * Initialise ANT */ ANT_init(ctx); printf("*** ANT Initialised\n"); dev_handle = libusb_open_device_with_vid_pid(ctx, 0x17a4, 0x0002); if (dev_handle == NULL) { printf("Cannot open device\n"); return 1; } printf("Device Opened\n"); if (libusb_kernel_driver_active(dev_handle, 0) == 1) { printf("Kernel Driver Active!\n"); if (libusb_detach_kernel_driver(dev_handle, 0) == 0) { printf("Kernel Driver Detached!\n"); } } r = libusb_claim_interface(dev_handle, 0); // claim interface 0 (the first) of device if (r < 0) { printf("Cannot claim interface!\n"); return 1; } printf("Interface claimed!\n"); UCHAR in_buff[ 512 ]; int i; create_c2pm3_libusb_input_handler(dev_handle, &C2PM3_message_callback, in_buff); c2pm3_send_command(CSAFE_CMD_GET_CADENCE, NULL, 0); while(TRUE) { sleep(2); } printf("HUH!!!\n"); libusb_close(dev_handle); libusb_exit(ctx); return (0); #if 0 char str[ 512 ]; BOOL running = FALSE; int size; /* * Get to running state */ while(!running) { size = sprintf(str, "CM\r\n"); res = write(USB, str, size); if (res != size) { printf("Failed to send [CM]\n"); } else { usleep(1000000); res = read(USB, str, 512); if (res < 0) { printf("Failed to read response to [CM]\n"); } else { printf("Response to [CM] == %s\n", str); if (strncmp(str, "RUN", 3) == 0) { running = TRUE; } else { for(i = 0; i < strlen(str); i++) { printf("[0x%02x][%c]\n", str[ i ], str[ i ]); } } } } } int pulse; int cadence; int speed; int distance; int desired_power; int energy; char time_string[ 20 ]; int achieved_power; USHORT cum_pow = 0; struct timespec tp; ULONG last_time; ULONG time; ULONG elapsed; last_time = get_ms(); while(TRUE) { size = sprintf(str, "ST\r\n"); res = write(USB, str, size); if (res != size) { printf("Failed to send [ST]\n"); } else { usleep(250000); res = read(USB, str, 512); if (res < 0) { printf("Failed to read response to [ST]\n"); } else { printf(str); char *pch; pch = strtok(str, "\t"); int field = 0; while(pch != NULL) { switch(field) { case FIELD_PULSE: pulse = atoi(pch); break; case FIELD_CADENCE: cadence = atoi(pch); break; case FIELD_SPEED: speed = atoi(pch); break; case FIELD_DISTANCE: distance = atoi(pch); break; case FIELD_DESIRED_POWER: desired_power = atoi(pch); break; case FIELD_ENERGY: energy = atoi(pch); break; case FIELD_TIME: strcpy(time_string, pch); break; case FIELD_ACHIEVED_POWER: achieved_power = atoi(pch); break; } pch = strtok(NULL, "\t"); field++; } time = get_ms(); elapsed = time - last_time; last_time = time; cum_pow += (achieved_power * elapsed) / 1000; speed_sensor_set_speed(speed * 100); power_sensor_set_params(cum_pow, cadence); } } } close(USB); #endif }
void probe_pci_devs(U32 bus_num) { probe_devs(bus_num, 0); print_devs(); }