make it work with some workaround
[trinked.git] / trinket.c
index ba5fdb3..8f2cdc9 100644 (file)
--- a/trinket.c
+++ b/trinket.c
@@ -7,10 +7,10 @@
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
+ *       notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -105,6 +105,7 @@ dumpBuf(char *msg, uint8_t *buf, int len) {
 
 TrinketErrorCode
 trinketOpen() {
+       TrinketErrorCode        r;
 #ifndef NDEBUG
        int i;
 
@@ -119,7 +120,9 @@ trinketOpen() {
                return ERR_ERROR;
        }
 
-       return trinketPing();
+       if ((r = trinketPing()) != ERR_OK)
+               trinketClose();
+       return r;
 }
 
 void