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.
Fork of SDFileSystem by
Diff: SDFileSystem.cpp
- Revision:
- 7:d2502a37ebf9
- Parent:
- 4:3f40cbfe801c
diff -r 8db0d3b02cec -r d2502a37ebf9 SDFileSystem.cpp
--- a/SDFileSystem.cpp Fri Sep 09 19:35:14 2016 +0000
+++ b/SDFileSystem.cpp Sat Sep 09 14:33:28 2017 +0000
@@ -495,4 +495,58 @@
return 0;
};
return blocks;
+}
+
+bool SDFileSystem::writeSD(char *filename,char *payload)
+{
+ char result[9];
+ FILE *fp = fopen(filename, "a");
+ if(fp == NULL) {
+ printf("Could not open file for write\n");
+ return 0;
+ }
+ fprintf(fp, payload);
+ fclose(fp);
+ printf("Text written to the SD-CARD\n");
+ return true;
+}
+bool SDFileSystem::readSD(char *filename,char *SDBuffer)
+{
+ char buffer[9];
+ FILE *fp = fopen(filename, "r");
+ FILE *fp2 = fopen("/sd/mydir3/temp.txt", "w");
+ if(fp == NULL|fp2 == NULL)
+ {
+ printf("Could not open file for read\n");
+ return false;
+ }
+ int counter=0;
+ while(fgets(buffer,9,fp)!=NULL)
+ {
+ if (counter == 0)
+ {
+ for (int i=0;i<9;i++)
+ SDBuffer[i]=buffer[i];
+ }
+ else
+ {
+ //printf("temp %s",buffer);
+ //if(SDBuffer[0]!='\n')
+ fprintf(fp2, buffer);
+ }
+ ++counter;
+ }
+ fclose(fp);
+ fclose(fp2);
+ fp2=fopen("/sd/mydir3/temp.txt", "r");
+ fp= fopen(filename, "w");
+ while(fgets(buffer,9,fp2)!=NULL)
+ {
+ fprintf(fp, buffer);
+ }
+ fclose(fp);
+ fclose(fp2);
+ fp2=fopen ("/sd/mydir3/temp.txt", "w");
+ fclose(fp2);
+ return 0;
}
\ No newline at end of file
