Nicola d'Ambrosio / Mbed 2 deprecated f4_def

Dependencies:   SDFileSystem1 mbed

Fork of SDFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
NdA994
Date:
Mon Nov 20 22:18:10 2017 +0000
Parent:
1:e4d7342be507
Commit message:
Libreria per scrittura su Sd completa. Ho eseguito dei test per vedere se l'accelerometro reggeva la scrittura ed hanno dato esiti positivi.

Changed in this revision

LettoreSD.cpp Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
lettoreSD.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
setting.h Show annotated file Show diff for this revision Revisions of this file
diff -r e4d7342be507 -r f59bd5312559 LettoreSD.cpp
diff -r e4d7342be507 -r f59bd5312559 SDFileSystem.lib
--- a/SDFileSystem.lib	Tue May 16 05:18:55 2017 +0000
+++ b/SDFileSystem.lib	Mon Nov 20 22:18:10 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
+https://os.mbed.com/teams/Unina_corse/code/SDFileSystem1/#cfed551cc1a2
diff -r e4d7342be507 -r f59bd5312559 lettoreSD.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lettoreSD.h	Mon Nov 20 22:18:10 2017 +0000
@@ -0,0 +1,52 @@
+#ifndef __LETTORESD__
+#define __LETTORESD__
+
+#include "SDFileSystem.h"
+
+int nFile = 1;
+ 
+SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, A2, "sd");
+FILE *fp;
+char buffer[4100];
+int nCounter = 0;
+
+void initFile(){
+    mkdir("/sd/mydir", 0777);
+}
+    
+    
+FILE * aperturaFile(){
+    char destinazione[14];
+    char path[21]="/sd/mydir/";
+    sprintf(destinazione, "%d", nFile); 
+    strcat(destinazione, ".txt");
+    strcat(path, destinazione);
+    fp = fopen(path, "w");
+    if(fp == NULL){
+        error("Could not open file for write\n");
+    }
+    return fp;
+}
+    
+void chiusuraFile(){
+    fclose(fp);
+    nFile++;
+    buffer[0] = 0;
+    nCounter = 0;
+}
+
+void stampaFile(char* stringa){
+    if(nCounter == 99){
+        fprintf(fp, "%s", buffer);
+        nCounter = 0;
+        buffer[0] = 0;
+        printf("sono qua <---------\n\r");
+    }
+    else{
+        printf("sono qua\n\r");
+        nCounter++;
+        strcat(buffer, stringa);
+    }
+}
+
+#endif
\ No newline at end of file
diff -r e4d7342be507 -r f59bd5312559 main.cpp
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Mon Nov 20 22:18:10 2017 +0000
@@ -1,19 +1,22 @@
 #include "mbed.h"
-#include "SDFileSystem.h"
- 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
- 
+#include "setting.h"
+#include "lettoreSD.h"
+
+
 int main() {
-    printf("Hello World!\n");   
- 
-    mkdir("/sd/mydir", 0777);
+    init();
+    printf("Hello World!\n\r");
+    initFile();  
+    aperturaFile();
+    for(int i=0; i<1000; i++){
+        stampaFile("A1xxxxoooooggggggeeeeeeerrrryyyyynhgrgr#2\r\n");
+    }
+    chiusuraFile(); 
+    aperturaFile();
+    for(int i=0; i<1000; i++){
+        stampaFile("A1xxxxoooooggggggeeeeeeerrrryyyyynhgrgr#2\r\n");
+    }
+    chiusuraFile(); 
+    printf("Goodbye World!\n\r");
     
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "Hello fun SD Card World!");
-    fclose(fp); 
- 
-    printf("Goodbye World!\n");
 }
diff -r e4d7342be507 -r f59bd5312559 setting.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setting.h	Mon Nov 20 22:18:10 2017 +0000
@@ -0,0 +1,18 @@
+#ifndef __SETTING__
+#define __SETTING__
+
+#include "mbed.h"
+
+#include "lettoreSD.h"
+
+Serial pc(USBTX, USBRX);
+
+void init(){
+    pc.baud(921600);    
+}
+
+
+
+
+
+#endif
\ No newline at end of file