Senior Design: Sound Monitor / 4951

Dependencies:   LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile

Revision:
4:e1ec41710eb4
Parent:
3:7edb43f86069
Child:
5:2ee2c7546568
--- a/main.cpp	Sat Dec 12 21:43:03 2015 +0000
+++ b/main.cpp	Sat Dec 12 22:06:19 2015 +0000
@@ -6,6 +6,7 @@
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 #include "arm_math.h" 
+#include "SDFileSystem.h"
 #define num 128
 //AnalogIn ain1(PC_6);
 //AnalogIn ain2(PC_7);
@@ -13,7 +14,6 @@
 //AnalogIn ain4(PC_9);
 //AnalogIn ain5(PB_15);
 
-
 DigitalIn ain1(PC_9);
 DigitalIn ain2(PB_15);
 DigitalIn ain3(PC_7);
@@ -71,6 +71,7 @@
 
 //SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
 SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc
+SDFileSystem sd(PB_5, PB_4, PB_3, PC_11, "sd"); // mosi, miso, sclk, cs
 
 int main()
 {    
@@ -329,18 +330,46 @@
             TFT.set_font((unsigned char*) Arial24x23);
             TFT.locate(20,20);
             printf("     Log");
-            int row=50;
-            for(int abc=0; abc<20; abc++) 
-            {   TFT.set_font((unsigned char*) Arial12x12);
-                TFT.locate(10,row+10*abc);
-                printf("[%i]", abc+1);
-                TFT.locate(60,row+10*abc);
-                printf("%f", mse+abc);
-            }
+            //int row=50;
+//            for(int abc=0; abc<20; abc++) 
+//            {   TFT.set_font((unsigned char*) Arial12x12);
+//                TFT.locate(10,row+10*abc);
+//                printf("[%i]", abc+1);
+//                TFT.locate(60,row+10*abc);
+//                printf("%f", mse+abc);
+//            }
             TFT.set_font((unsigned char*) Arial12x12);
             TFT.locate(165,270);
             printf("Return"); 
             TFT.rect(150,265,220,285,Green); 
+            
+            //Configure CRC, large frames, and write validation for SD Card
+            sd.crc(true);
+            sd.large_frames(true);
+            sd.write_validation(true);
+            
+            //Try to mount the SD card
+            TFT.locate(10,50);
+            TFT.printf("Mounting SD card...");
+            TFT.locate(10,60);
+            if (sd.mount() != 0) {
+                TFT.printf("failed!");
+            } else {
+                TFT.printf("mounted successfully!\r\n");
+            
+                // write event to log
+                TFT.locate(10,70);
+                FILE *fp = fopen("/sd/event_log.txt", "a");
+                if (fp != NULL) {
+                    fprintf(fp, "eureka!\r\n");
+                    fclose(fp);
+                    TFT.printf("success!\n");
+                } else {
+                    TFT.printf("failed!\n");
+                }
+                sd.unmount();
+            }
+    
             ps = ain3.read(); 
             if (ps==1)  {wait(0.5); TFT.cls();  stage=0;}
         }