Los Putacos / Mbed OS WearableDevice_Nucleo_New

Dependencies:   MPU9250_SPI

Fork of WearableDevice_Nucleo by Los Putacos

Revision:
19:0a3ae902722e
Parent:
18:7f9c2b8541e1
Child:
20:197c69b38adf
diff -r 7f9c2b8541e1 -r 0a3ae902722e main.cpp
--- a/main.cpp	Wed Oct 18 12:51:31 2017 +0000
+++ b/main.cpp	Wed Oct 18 15:27:31 2017 +0000
@@ -25,6 +25,7 @@
 #include "MPU9250.h"
 
 #include "XBeeLib.h"
+#include "SDFileSystem.h"
 //-----------------------------------------------------------------
 
 //-----------------------------------------------------------------
@@ -97,12 +98,14 @@
 
 /** Callback function, invoked at packet reception */
 static void receive_cb(const RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len)
-{    
+{
     for (int i = 0; i < len; i++)
         PC.printf("%c", data[i]);
-        
+
     PC.printf("\r\n");
 }
+// Create an SDFileSystem object
+SDFileSystem SD(SD_MOSI, SD_MISO, SD_CLK, SD_CS, "SD");
 
 //-----------------------------------------------------------------
 int main()
@@ -113,15 +116,45 @@
 
     XBeeZB XBee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 115200);
     XBee.init();
-    
+
     /* Register callbacks */
     XBee.register_receive_cb(&receive_cb);
+    time_stamp.start(); // Start Timer
 
+    // Mount the filesystem
+    SD.mount();
+
+    if (SD.card_present())
+        PC.printf("Good");
+    else
+        PC.printf("Meh");
 
     // Reading the analog input (Microphone)
     // array = micro.read_u16();
 
-    time_stamp.start(); // Start timer
+    // Performing Write Test
+    PC.printf("\nWriting to SD card...");
+    FILE *fp = fopen("sdtest.txt", "w");
+    if (fp != NULL) {
+        fclose(fp);
+        PC.printf(" Success!\n");
+    } else {
+        PC.printf(" Failed!\n");
+    }
+
+    // Performing Read Test
+    PC.printf("Reading from SD card...");
+    fp = fopen("/sd/sdtest.txt", "r");
+    if (fp != NULL) {
+        char c = fgetc(fp);
+        if (c == 'W')
+            PC.printf(" Success!\n");
+        else
+            PC.printf("Incorrect Character! (%c)!\n", c);
+        fclose(fp);
+    } else {
+        PC.printf(" Failed!\n");
+    }
 
     led1 = 1;
     while (true) {
@@ -133,5 +166,8 @@
             PC.printf("send_data_broadcast() failed with error %d\n", (int)txStatus);
         }
     }
+
+    // Unmount the Filesystem
+    SD.unmount();
 }
 //-----------------------------------------------------------------
\ No newline at end of file