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
Revision 7:d2502a37ebf9, committed 2017-09-09
- Comitter:
- suads
- Date:
- Sat Sep 09 14:33:28 2017 +0000
- Parent:
- 6:8db0d3b02cec
- Commit message:
- jebeee
Changed in this revision
SDFileSystem.cpp | Show annotated file Show diff for this revision Revisions of this file |
SDFileSystem.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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
--- a/SDFileSystem.h Fri Sep 09 19:35:14 2016 +0000 +++ b/SDFileSystem.h Sat Sep 09 14:33:28 2017 +0000 @@ -25,7 +25,8 @@ #include "mbed.h" #include "FATFileSystem.h" #include <stdint.h> - +#include <string> +//#include "SDFileSystem.h" /** Access the filesystem on an SD Card using SPI * * @code @@ -58,6 +59,8 @@ virtual int disk_write(const uint8_t* buffer, uint32_t block_number, uint32_t count); virtual int disk_sync(); virtual uint32_t disk_sectors(); + bool writeSD(char *filename,char *payload); + bool readSD(char *filename,char *SDBuffer); protected: