From 80e2501285bb6535cb65cf4712ba1d0c540d6f41 Mon Sep 17 00:00:00 2001 From: Bluebie Date: Fri, 30 Nov 2012 10:30:45 +1100 Subject: commandline: pspgeek's usb fail workaround --- commandline/examples/micronucleus.c | 28 ++++++++++++++++++++++++---- commandline/library/micronucleus_lib.c | 4 +++- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'commandline') diff --git a/commandline/examples/micronucleus.c b/commandline/examples/micronucleus.c index af62494..4cab97a 100644 --- a/commandline/examples/micronucleus.c +++ b/commandline/examples/micronucleus.c @@ -179,9 +179,29 @@ int main(int argc, char **argv) { setProgressData("erasing", 4); printf("> Erasing the memory ...\n"); res = micronucleus_eraseFlash(my_device, printProgress); - if (res != 0) { - printf(">> Abort mission! An error has occured ...\n"); - printf(">> Please unplug the device and restart the program. \n"); + + if (res == -2) { // erase disconnection bug workaround + printf(">> Eep! Connection to device lost during erase! Not to worry\n"); + printf(">> This happens on some computers - reconnecting...\n"); + my_device = NULL; + + int deciseconds_till_reconnect_notice = 50; // notice after 5 seconds + while (my_device == NULL) { + delay(100); + my_device = micronucleus_connect(); + deciseconds_till_reconnect_notice -= 1; + + if (deciseconds_till_reconnect_notice == 0) { + printf(">> (!) Automatic reconnection not working. Unplug and reconnect\n"); + printf(" device usb connector, or reset it some other way to continue.\n"); + } + } + + printf(">> Reconnected! Continuing upload sequence...\n"); + + } else if (res != 0) { + printf(">> Abort mission! %d error has occured ...\n", res); + printf(">> Please unplug the device and restart the program.\n"); return EXIT_FAILURE; } printProgress(1.0); @@ -191,7 +211,7 @@ int main(int argc, char **argv) { res = micronucleus_writeFlash(my_device, endAddress, dataBuffer, printProgress); if (res != 0) { printf(">> Abort mission! An error has occured ...\n"); - printf(">> Please unplug the device and restart the program. \n"); + printf(">> Please unplug the device and restart the program.\n"); return EXIT_FAILURE; } diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 561ddce..6f1ac8d 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -89,7 +89,9 @@ int micronucleus_eraseFlash(micronucleus* deviceHandle, micronucleus_callback pr i += 0.01; } - if(res!=0) + if (res == -5) + return -2; + if (res != 0) return -1; else return 0; -- cgit v1.2.3