diff options
-rw-r--r-- | tools/atmega324u_usbhid/reset.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/tools/atmega324u_usbhid/reset.c b/tools/atmega324u_usbhid/reset.c index 7955b1b..63252e1 100644 --- a/tools/atmega324u_usbhid/reset.c +++ b/tools/atmega324u_usbhid/reset.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <string.h> - +#include <unistd.h> +#include <stdint.h> #include "hid.h" @@ -9,14 +10,42 @@ void sendstr(char * tosend) rawhid_send(0, tosend, strlen(tosend),1000); } +#define NUM_DEVICE_IDS 3 +uint16_t dev_ids[] = {0x0481, 0x0480, 0x0482}; + int main (int argc, char *argv[]) { // C-based example is 16C0:0480:FFAB:0200 - int r = rawhid_open(1, 0x16C0, 0x0481, 0xFFAB, 0x0200); + int r,d,w; + for (d=0; d<NUM_DEVICE_IDS; d++) + { + r = rawhid_open(1, 0x16C0, dev_ids[d], 0xFFAB, 0x0200); + if (r > 0) + break; + } if (r <= 0) { - printf("no rawhid device found\n"); - return -1; + printf("no rawhid device found, already in bootloader ?\n"); + return 0; + } + sendstr("r"); // clear the buffer + + //now wait until device is gone + + for (w=0; w < 12; w++) + { + r = rawhid_open(1, 0x16C0, dev_ids[d], 0xFFAB, 0x0200); + if (r > 0) + { + rawhid_close(r); + sleep(1); + } + else + { + printf("device gone, reboot finished\n"); + sleep(1); + return 0; + } } - sendstr("r"); // clear the buffer - return 0; + printf("device still there, reboot did not work ?\n"); + return -1; } |