From d031b581a0ccc8d36ca49c473dae1a9312f55b95 Mon Sep 17 00:00:00 2001
From: Stanley Huang <stanleyhuangyc@gmail.com>
Date: Mon, 21 Apr 2014 20:31:31 +0800
Subject: Fix blocking issue when no SD card is present

---
 unologger/datalogger.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'unologger')

diff --git a/unologger/datalogger.h b/unologger/datalogger.h
index 850900f..8009a80 100644
--- a/unologger/datalogger.h
+++ b/unologger/datalogger.h
@@ -175,6 +175,7 @@ public:
 #endif
 #endif
 #if ENABLE_DATA_LOG
+        if (!sdfile) return;
 #if LOG_FORMAT == FORMAT_BIN
         sdfile.write((uint8_t*)&ld, 12);
         dataSize += 12;
@@ -207,6 +208,7 @@ public:
 #endif
 #endif
 #if ENABLE_DATA_LOG
+        if (!sdfile) return;
 #if LOG_FORMAT == FORMAT_BIN
         sdfile.write((uint8_t*)&ld, 12);
         dataSize += 12;
@@ -241,6 +243,7 @@ public:
 #endif
 #endif
 #if ENABLE_DATA_LOG
+        if (!sdfile) return;
 #if LOG_FORMAT == FORMAT_BIN
         sdfile.write((uint8_t*)&ld, 16);
         dataSize += 16;
@@ -277,6 +280,7 @@ public:
 #endif
 #endif
 #if ENABLE_DATA_LOG
+        if (!sdfile) return;
 #if LOG_FORMAT == FORMAT_BIN
         sdfile.write((uint8_t*)&ld, 16);
         dataSize += 16;
@@ -315,6 +319,7 @@ public:
 #endif
 #endif
 #if ENABLE_DATA_LOG
+        if (!sdfile) return;
 #if LOG_FORMAT == FORMAT_BIN
         sdfile.write((uint8_t*)&ld, 20);
         dataSize += 20;
@@ -375,7 +380,7 @@ public:
     }
     void flushFile()
     {
-        sdfile.flush();
+        if (sdfile) sdfile.flush();
     }
 #endif
     uint32_t dataTime;
-- 
cgit v1.2.3