summaryrefslogtreecommitdiffstats
path: root/commandline
diff options
context:
space:
mode:
authorBluebie <a@creativepony.com>2013-02-20 14:22:25 +1100
committerBluebie <a@creativepony.com>2013-02-20 14:22:25 +1100
commit58a113df9678b4502f87e0e91fc01d023a59393d (patch)
tree2602007f83540f1e6b6ab727be939110250c8d94 /commandline
parent6117fad11dffab29f9d1f71d678d732c453be260 (diff)
downloadmicronucleus-58a113df9678b4502f87e0e91fc01d023a59393d.tar.gz
micronucleus-58a113df9678b4502f87e0e91fc01d023a59393d.tar.bz2
micronucleus-58a113df9678b4502f87e0e91fc01d023a59393d.zip
commandline: bugfixes for -1 error after erase on OS X - auto recover now works
Diffstat (limited to 'commandline')
-rw-r--r--commandline/examples/micronucleus.c22
-rw-r--r--commandline/library/micronucleus_lib.c19
2 files changed, 27 insertions, 14 deletions
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) {