Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ELEC350_Project2 SDcard
Revision 8:ee8f65745141, committed 2018-12-19
- Comitter:
- Swabey89
- Date:
- Wed Dec 19 12:02:14 2018 +0000
- Parent:
- 7:393fa8184388
- Child:
- 9:113f4934b907
- Commit message:
- on start, attempt to initialize and set initialized state to false is unable to.
Changed in this revision
| SDCard.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SDCard.hpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SDCard.cpp Mon Dec 17 16:10:40 2018 +0000
+++ b/SDCard.cpp Wed Dec 19 12:02:14 2018 +0000
@@ -8,61 +8,46 @@
//REQUIRES IMPROVEMENTS, SEE ONENOTE
//Initialise the SD card
- if ( sd.init() != 0) {
- printf("Init failed \n");
- lcd.cls();
- lcd.printf("CANNOT INIT SD");
- errorCode(FATAL);
+ if (sd.init() != 0) {
+ pc->printf("WARNING:SD CARD INITIALISATION FAILED\n\r");
+ sd_init = false;
+ //lcd.cls();
+ //lcd.printf("CANNOT INIT SD");
+ //errorCode(FATAL);
}
-
- //Create a filing system for SD Card
- //FATFileSystem fs("sd", &sd);
- fs = new FATFileSystem("sd", &sd);
-
- //Open to WRITE
+ else
+ {
+ //Create a filing system for SD Card
+ fs = new FATFileSystem("sd", &sd);
+ pc->printf("SD CARD INITIALISED\n\r");
- char fileDate[30];
- seconds = time(NULL);
- timeData = localtime(&seconds);
- set_time(mktime(timeData));
- strftime(fileDate, 30, "sd/sampledata/%d_%m_%y.csv", timeData);
+ //Open to WRITE
+ char fileDate[30];
+ seconds = time(NULL);
+ timeData = localtime(&seconds);
+ set_time(mktime(timeData));
+ strftime(fileDate, 30, "sd/log_%d_%m_%y.csv", timeData);
+
+ fp = fopen(fileDate,"a");
+
+ if (fp == NULL)
+ {
+ pc->printf("WARNING: COULD NOT OPEN FILE FOR WRITE\n\r");
+ //lcd.cls();
+ //lcd.printf("CANNOT OPEN FILE\n\n");
+ //errorCode(FATAL);
+ }
+ else
+ {
+ pc->printf("FILE OPEN FOR WRITING\n\r");
+ sd_init = true;
+ }
+ fclose(fp);
+ }
- fp = fopen(fileDate,"a");
- if (fp == NULL) {
- error("Could not open file for write\n");
- lcd.cls();
- lcd.printf("CANNOT OPEN FILE\n\n");
- errorCode(FATAL);
- }
-
- fclose(fp);
-
- //Last message before sampling begins
+ //Last message before sampling begins - probably remove
lcd.cls();
lcd.printf("SYSTEM READY\n\n");
-
-
-
- //move?
- //Press either switch to unmount
- /*
- while ((SW1 == 0) && (SW2 == 0)) {
-
-
- //Write to SD (potentially slow)
- //fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
-
- }
-
- //Close File
- fclose(fp);
-
- //Close down
- sd.deinit();
- printf("Unmounted...\n");
- lcd.cls();
- lcd.printf("Unmounted...\n\n");
- */
}
void SDread(int n)
--- a/SDCard.hpp Mon Dec 17 16:10:40 2018 +0000 +++ b/SDCard.hpp Wed Dec 19 12:02:14 2018 +0000 @@ -6,6 +6,7 @@ #include "serial_terminal.hpp" #include "mbed_events.h" +extern bool sd_init; extern time_t seconds; extern tm* timeData; extern EventQueue SDqueue;
