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.
Dependencies: SDFileSystem mbed
Fork of SD_ReadWrite_K64 by
Revision 3:a9c142f24ede, committed 2017-05-24
- Comitter:
- nnoitre
- Date:
- Wed May 24 13:28:51 2017 +0000
- Parent:
- 2:b441f859191d
- Commit message:
- Making the program public
Changed in this revision
| SD.cpp | Show diff for this revision Revisions of this file |
| SD.h | Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b441f859191d -r a9c142f24ede SD.cpp
--- a/SD.cpp Tue May 16 13:36:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-#pragma once
-#include "SD.h"
-#include "SDFileSystem.h"
-#include <string>
-#include <sstream>
-#include <string>
-SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //mosi, miso, sclk, cs
-Serial pc(USBTX, USBRX);
-
-namespace VivesCityGame{
- std::string SD::read(void){
- FILE *fp1 =fopen("/sd/test.json", "r");
- if(fp1==NULL) {
- error("Could not open file for read!\r\n");
- } else {
- printf("Reading from SD card...\r\n");
- while((c=fgetc(fp1)) && c!=EOF) {
- words[n]=c;
- n++;
- }
- }
- fclose(fp1);
- ss << words;
- ss >> s;
- return s;
- }
- void SD::writen(){
- while(pc.readable()) {
- pc.gets(buffer, 2);
- if(buffer=="") {
- printf("Niks doorgestuurd");
- } else {
- strcat(received, buffer);
- ontvangen = 1;
- }
- }
- if(ontvangen){
- ontvangen = 0;
- FILE *fp = fopen("/sd/test.json", "w");; //w overwrite's, a appands to file
- if(fp == NULL) {
- error("Could not open file for write!\r\n");
- }else{
- printf("Writing to SD card...\r\n");
- fprintf(fp, received);
- fclose(fp);
- }
- }
-}
-}
\ No newline at end of file
diff -r b441f859191d -r a9c142f24ede SD.h
--- a/SD.h Tue May 16 13:36:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-#pragma once
-#include "SDFileSystem.h"
-#include <string>
-#include <sstream>
-#include <string>
-
-namespace VivesCityGame{
- class SD{
- public:
- std::string read(void);
- void writen();
- private:
- char words[4096];
- int n,c;
- char buffer[2048];
- char received[8192];
- bool ontvangen;
- stringstream ss;
- string s;
- };
- };
\ No newline at end of file
diff -r b441f859191d -r a9c142f24ede main.cpp
--- a/main.cpp Tue May 16 13:36:53 2017 +0000
+++ b/main.cpp Wed May 24 13:28:51 2017 +0000
@@ -1,10 +1,49 @@
#include "mbed.h"
#include "SDFileSystem.h"
#include <string>
-#include "SD.h"
+
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //mosi, miso, sclk, cs
+Serial pc(USBTX, USBRX);
+char words[4096];
+int n,c;
+char buffer[2048];
+char received[8192];
+bool ontvangen;
int main()
{
while(1) {
- VivesCityGame::SD read();
+ /*//reading
+ FILE *fp1 =fopen("/sd/test.json", "r");
+ if(fp1==NULL) {
+ error("Could not open file for read!\r\n");
+ } else {
+ printf("Reading from SD card...\r\n");
+ while((c=fgetc(fp1)) && c!=EOF) {
+ words[n]=c;
+ n++;
+ }
+ printf(words);
+ }*/
+ //writing
+ while(pc.readable()) {
+ pc.gets(buffer, 2);
+ if(buffer=="") {
+ printf("Niks doorgestuurd");
+ } else {
+ strcat(received, buffer);
+ ontvangen = 1;
+ }
+ }
+ if(ontvangen) {
+ ontvangen = 0;
+ FILE *fp = fopen("/sd/test.json", "w");; //w overwrite's, a appands to file
+ if(fp == NULL) {
+ error("Could not open file for write!\r\n");
+ } else {
+ printf("Writing to SD card...\r\n");
+ fprintf(fp, received);
+ fclose(fp);
+ }
+ }
}
}
\ No newline at end of file
