SD card functionality
Dependents: ELEC350_Project2 SDcard
Diff: SDCard.cpp
- Revision:
- 3:c6e5dd2faa22
- Parent:
- 2:9a5eea2adbf8
- Child:
- 4:dc767b5f917b
diff -r 9a5eea2adbf8 -r c6e5dd2faa22 SDCard.cpp --- a/SDCard.cpp Thu Nov 08 21:29:38 2018 +0000 +++ b/SDCard.cpp Fri Nov 09 17:56:55 2018 +0000 @@ -1,5 +1,7 @@ #include "SDCard.hpp" + + void SDcard(void) { @@ -18,7 +20,7 @@ FATFileSystem fs("sd", &sd); //Open to WRITE - FILE* fp = fopen("/sd/test.csv","a"); + FILE* fp = fopen("/sd/newtest.csv","a"); if (fp == NULL) { error("Could not open file for write\n"); lcd.cls(); @@ -26,29 +28,23 @@ errorCode(FATAL); } + fclose(fp); + //Last message before sampling begins lcd.cls(); lcd.printf("READY\n\n"); + + //move? //Press either switch to unmount + /* while ((SW1 == 0) && (SW2 == 0)) { - //Base loop delay - wait(1.0); - - //Read environmental sensors - double temp = sensor.getTemperature(); - double pressure = sensor.getPressure(); - - //Write new data to LCD (not fast!) - lcd.cls(); - lcd.printf("Temp Pressure\n"); - lcd.printf("%6.1f ",temp); - lcd.printf("%.2f\n",pressure); - + //Write to SD (potentially slow) //fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure); + } //Close File @@ -59,21 +55,35 @@ printf("Unmounted...\n"); lcd.cls(); lcd.printf("Unmounted...\n\n"); + */ } void SDread(int n) { + //Read n samples from the SD card if (n == -1) puts("Received command to read all"); else printf("Received command to read %d\n", n); } void SDdelete(int n) { + //Delete n samples from the SD card if (n == -1) puts("Received command to delete all"); else printf("Received command to delete %d\n", n); } +void SDaddSample(double temp, double pressure) +{ + //Add the sampled data to the SD card + + FILE* fp = fopen("/sd/newtest.csv","a"); + fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure); + fclose(fp); + puts("SAMPLE ADDED TO SD CARD"); +} + void SDalive(void) { + //Signal that the SD thread is still alive //puts("SD THREAD ALIVE\n"); } \ No newline at end of file