summaryrefslogtreecommitdiffstats
path: root/commandline/library
diff options
context:
space:
mode:
authorMichael Copland <mjbcopland@gmail.com>2016-06-22 13:36:18 +0100
committerMichael Copland <mjbcopland@gmail.com>2016-06-22 13:36:18 +0100
commit71b74d37409b17a2d431933cd4c5e96cb986d0f7 (patch)
tree825ce7950ef11344c9335296761e57277f30da9d /commandline/library
parente56d09dee240be7e8b25fc5687ba86893dc91a27 (diff)
downloadmicronucleus-71b74d37409b17a2d431933cd4c5e96cb986d0f7.tar.gz
micronucleus-71b74d37409b17a2d431933cd4c5e96cb986d0f7.tar.bz2
micronucleus-71b74d37409b17a2d431933cd4c5e96cb986d0f7.zip
Properly close and deinitialize the USB connection
Diffstat (limited to 'commandline/library')
-rw-r--r--commandline/library/micronucleus_lib.c13
-rw-r--r--commandline/library/micronucleus_lib.h6
2 files changed, 13 insertions, 6 deletions
diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c
index 58ed10a..6cddb7c 100644
--- a/commandline/library/micronucleus_lib.c
+++ b/commandline/library/micronucleus_lib.c
@@ -148,17 +148,12 @@ int micronucleus_eraseFlash(micronucleus* deviceHandle, micronucleus_callback pr
is disconnecting and reconnecting. Under Windows, micronucleus can see this
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.
+ converting the return to 1 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 == -34 || res == -84) {
- if (res == -34) {
- libusb_close(deviceHandle->device);
- deviceHandle->device = NULL;
- }
-
return 1; // recoverable errors
} else {
return res;
@@ -319,3 +314,9 @@ int micronucleus_startApp(micronucleus* deviceHandle) {
else
return 0;
}
+
+void micronucleus_disconnect(micronucleus* deviceHandle) {
+ libusb_close(deviceHandle->device);
+ libusb_exit(NULL);
+ free(deviceHandle);
+}
diff --git a/commandline/library/micronucleus_lib.h b/commandline/library/micronucleus_lib.h
index 9e1e0f6..ce31f97 100644
--- a/commandline/library/micronucleus_lib.h
+++ b/commandline/library/micronucleus_lib.h
@@ -107,4 +107,10 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_len
int micronucleus_startApp(micronucleus* deviceHandle);
/*******************************************************************************/
+/********************************************************************************
+* Disconnects from the device and deinitializes libusb
+********************************************************************************/
+void micronucleus_disconnect(micronucleus* deviceHandle);
+/*******************************************************************************/
+
#endif