From 58a113df9678b4502f87e0e91fc01d023a59393d Mon Sep 17 00:00:00 2001 From: Bluebie Date: Wed, 20 Feb 2013 14:22:25 +1100 Subject: commandline: bugfixes for -1 error after erase on OS X - auto recover now works --- commandline/examples/micronucleus.c | 22 ++++++++++++++-------- commandline/library/micronucleus_lib.c | 19 +++++++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) (limited to 'commandline') diff --git a/commandline/examples/micronucleus.c b/commandline/examples/micronucleus.c index e5fc355..7f5fd8c 100644 --- a/commandline/examples/micronucleus.c +++ b/commandline/examples/micronucleus.c @@ -72,11 +72,11 @@ int main(int argc, char **argv) { progress_total_steps = 5; // steps: waiting, connecting, parsing, erasing, writing, (running)? dump_progress = 0; timeout = 0; // no timeout by default - #if defined(WIN) - use_ansi = 0; - #else + //#if defined(WIN) + // use_ansi = 0; + //#else use_ansi = 1; - #endif + //#endif while (arg_pointer < argc) { if (strcmp(argv[arg_pointer], "--run") == 0) { @@ -101,9 +101,9 @@ int main(int argc, char **argv) { puts(" for driving GUIs"); puts(" --run: Ask bootloader to run the program when finished"); puts(" uploading provided program"); - #ifndef WIN + //#ifndef WIN puts(" --no-ansi: Don't use ANSI in terminal output"); - #endif + //#endif puts(" --timeout [integer]: Timeout after waiting specified number of seconds"); puts(" filename: Path to intel hex or raw data file to upload,"); puts(" or \"-\" to read from stdin"); @@ -215,11 +215,13 @@ int main(int argc, char **argv) { printf("> Erasing the memory ...\n"); res = micronucleus_eraseFlash(my_device, printProgress); - if (res == -2) { // erase disconnection bug workaround + if (res == 1) { // 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; + delay(CONNECT_WAIT); + int deciseconds_till_reconnect_notice = 50; // notice after 5 seconds while (my_device == NULL) { delay(100); @@ -282,7 +284,11 @@ static void printProgress(float progress) { printf("{status:\"%s\",step:%d,steps:%d,progress:%f}\n", progress_friendly_name, progress_step, progress_total_steps, progress); } else { if (last_step == progress_step && use_ansi) { - printf("\033[1F\033[2K"); // move cursor to previous line and erase last update in this progress sequence + #ifndef WIN + printf("\033[1F\033[2K"); // move cursor to previous line and erase last update in this progress sequence + #else + printf("\r"); // return carriage to start of line so we can type over existing text + #endif } float total_progress = ((float) progress_step - 1.0f) / (float) progress_total_steps; diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 462190b..9efbc3d 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -96,13 +96,20 @@ int micronucleus_eraseFlash(micronucleus* deviceHandle, micronucleus_callback pr and automatically reconnects prior to uploading the program. To get the the same functionality, we must flag this state (the "-84" error result) by converting the return to -2 for the upper layer. + + On Mac OS a common error is -34 = epipe, but adding it to this list causes: + Assertion failed: (res >= 4), function micronucleus_connect, file library/micronucleus_lib.c, line 63. */ - if (res == -5 || res == -84) - return -2; - if (res != 0) - return -1; - else - return 0; + if (res == -5 || res == -34 || res == -84) { + if (res = -34) { + usb_close(deviceHandle->device); + deviceHandle->device = NULL; + } + + return 1; // recoverable errors + } else { + return res; + } } int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_size, unsigned char* program, micronucleus_callback prog) { -- cgit v1.2.3