// Note: the underlying usb device name may change on enumeration.
// Harcoded for testing only.
#define ACCUSBDEVICE "/dev/bus/usb/001/001" // Rather than gadget name "/dev/usb_accessory"
// This requires root privileges for write permissions to device.
JNIEXPORT jint JNICALL
Java_com_genericminds_usbio_UsbAccessoryIO_nativeReset(JNIEnv* env, jclass cls) {
int result,fd;
result = system("su -c \"chmod -R 777 " ACCUSBDEVICE "\"");
if (result != 0) {
return result;
}
fd = open(ACCUSBDEVICE, O_RDWR);
if (fd < 0) {
return fd;
}
result = ioctl(fd, USBDEVFS_RESET, 0);
close(fd);
if (result < 0) {
return result;
}
return 0;
}