CSE477 / swimate_v2

Dependencies:   Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL

Revision:
22:9350752f5414
diff -r 2fa676f214fe -r 9350752f5414 log_data.cpp.orig
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/log_data.cpp.orig	Sat Jun 07 07:46:38 2014 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+#include "log_data.h"
+#include "SDFileSystem.h"
+#include "helper_3dmath.h"
+#include "debug.h"
+#include "SystemTime.h"
+#include "pins.h"
+
+// SD Card
+SDFileSystem sd(P0_21, P0_22, P1_15, P1_19, "sd"); // MOSI, MISO, SCLK, SSEL SPI1
+
+// DS3231 rtc(I2C_SDA, I2C_SCL);
+
+// Logging vars
+FILE *accelFile;
+FILE *peakFile;
+
+/* Returns true if logging was successfully initialized, false otherwise */
+bool log_init() {
+    PC_PRINTLN("Initializing logging...");
+
+    accelFile = fopen(ACCEL_LOG, "a");
+    if (accelFile == NULL) {
+        PC_PRINTLNF("SD card initialization error: Failed to open %s", ACCEL_LOG);
+        DIE(SD_ERROR_RATE);
+        return false;
+    }
+    
+    peakFile = fopen(PEAK_LOG, "a");
+    if (peakFile == NULL) {
+        PC_PRINTLNF("SD card initialization error: Failed to open %s", SPLIT_LOG);
+        DIE(SD_ERROR_RATE);
+        return false;
+    }
+
+//    fprintf(accelFile, "---- BEGIN NEW DATASET ----\n");
+//    fprintf(peakFile, "---- BEGIN NEW DATASET ----\n");
+    return true;
+}
+
+/* Returns true if data was successfully logged, false otherwise 
+   Used for logging acceleration data */
+bool log_data(int time_ms, VectorInt16 *data) {
+    if (accelFile != NULL) {
+//        fprintf(accelFile, "%d, %d, %d, %d\n", time_ms, data->x, data->y, data->z);
+        fwrite(&time_ms, sizeof(int), 1, accelFile);
+        fwrite(data, sizeof(VectorInt16), 1, accelFile);
+        return true;
+    }
+    
+    return false;
+}
+
+/* Returns true if data was successfully logged, false otherwise 
+   Used for logging split times */
+bool log_data(int time_ms, int split) {
+    if (peakFile != NULL) {
+//        fprintf(peakFile, "%d, %d\n", time_ms, split);
+        fwrite( (void*) &time_ms, sizeof(int), 1, peakFile);
+        fwrite( (void*) &split, sizeof(int), 1, peakFile);
+        return true;
+    }
+    
+    return false;
+}
+
+/* Returns true if logging was successfully closed, false otherwise */
+bool log_close() {
+//    if (accelFile != NULL && splitFile != NULL)
+//        return ( (fclose(accelFile) == 0) && (fclose(splitFile) == 0) );
+    
+    fclose(accelFile);
+    fclose(peakFile);
+    
+    return true;
+}
\ No newline at end of file