avec dfu

Fork of Utils by POTLESS

Revision:
2:5af7a1fb1903
Parent:
1:a937433a95c8
Child:
3:01677db45b2a
--- a/Utils.cpp	Thu Feb 08 12:14:52 2018 +0000
+++ b/Utils.cpp	Mon Feb 12 07:22:14 2018 +0000
@@ -2,7 +2,7 @@
 #include "Utils.h"
 
 SDBlockDevice bd(SD_MOSI, SD_MISO, SD_SCK, SD_CS);
-FATFileSystem fs("fs");
+FATFileSystem Root("Root");
 
 void return_error(int ret_val)
 {
@@ -24,7 +24,7 @@
 {
 
     char filename[20];
-    sprintf(filename, "/fs/%s.txt", File_Name);
+    sprintf(filename, "/Root/%s.txt", File_Name);
 
     FILE* fd = fopen(filename, "w");
     errno_error(fd);
@@ -43,7 +43,7 @@
     int i = 0;
 
     char filename[20];
-    sprintf(filename, "/fs/%s.txt", File_Name);
+    sprintf(filename, "/Root/%s.txt", File_Name);
 
     printf("  \n  Récupération de %s...\r\n", filename);
 
@@ -68,12 +68,13 @@
 }
 
 
-void UTILS::Write_SD_File(string To_Store, char* File_Name)
+void UTILS::Write_SD_File(char* To_Store, char* File_Name)
 {
-    char filename[20];
-    sprintf(filename, "/fs/%s", File_Name);
-
+    char filename[50];
+    sprintf(filename, "/Root/%s", (string)File_Name);
+    
     FILE* fd = fopen(filename, "a");
+    
     errno_error(fd);
     fprintf(fd, "%s\r\n", To_Store);
     fclose(fd);
@@ -81,10 +82,11 @@
     //printf("  Sauvegarde OK\r\n\r\n");
 }
 
-void UTILS::Read_SD_File(string File_Name)
+void UTILS::Read_SD_File(char* File_Name)
 {
     char filename[20];
-    sprintf(filename, "/fs/%s", File_Name);
+    sprintf(filename, "/Root/%s", File_Name);
+    
     FILE* fd = fopen(filename, "r");
     errno_error(fd);
 
@@ -98,12 +100,12 @@
     fclose(fd);
 }
 
-void UTILS::Delete_SD_File(string File_Name)
+void UTILS::Delete_SD_File(char* File_Name)
 {
     char filename[20];
-    sprintf(filename, "/fs/%s", File_Name);
+    sprintf(filename, "/Root/%s", File_Name);
     int error = 0;
-    error = fs.remove(filename);
+    error = Root.remove(filename);
     return_error(error);
 
     printf("Fichier effacé.\n");
@@ -112,12 +114,12 @@
 void UTILS::Rename_SD_File(string Old_File_Name, string New_File_Name)
 {
     char Oldfilename[20];
-    sprintf(Oldfilename, "/fs/%s", Old_File_Name);
+    sprintf(Oldfilename, "/Root/%s", Old_File_Name);
     char Newfilename[20];
-    sprintf(Newfilename, "/fs/%s", New_File_Name);
+    sprintf(Newfilename, "/Root/%s", New_File_Name);
 
     int error = 0;
-    error = fs.rename(Oldfilename, Newfilename);
+    error = Root.rename(Oldfilename, Newfilename);
     return_error(error);
 
     printf("Fichier renommé.\n");
@@ -126,9 +128,9 @@
 void UTILS::Mount_SD()
 {
     //Montage carte SD
-    printf("  Montage carte SD \"/fs\". \r\n\r\n");
+    printf("  Montage carte SD \"/Root\". \r\n\r\n");
     int error = 0;
-    error = fs.mount(&bd);
+    error = Root.mount(&bd);
     return_error(error);
     if (error > 0) {
         //On re format s'il n'y a as de file system...normalement une seul fois...
@@ -140,9 +142,9 @@
 void UTILS::UnMount_SD()
 {
     //Montage carte SD
-    printf("  Demontage carte SD \"/fs\". \r\n\r\n");
+    printf("  Demontage carte SD \"/Root\". \r\n\r\n");
     int error = 0;
-    error = fs.unmount();
+    error = Root.unmount();
     return_error(error);
 }
 
@@ -151,7 +153,30 @@
     //Formatage carte SD
     printf("  Formatage carte SD\r\n\r\n");
     int error = 0;
-    error = fs.format(&bd);
+    error = Root.format(&bd);
+    return_error(error);
+}
+
+void UTILS::DIR_SD(char* Dir_Name)
+{
+    int error = 0;
+    printf("Ouverture du répertoire %s\r\n.", Dir_Name);
+    char Dirname[20];
+    sprintf(Dirname, "/Root/%s", Dir_Name);
+    
+    DIR* dir = opendir(Dirname);
+    //errno_error(fd);
+
+    struct dirent* de;
+    printf("Fichier du répertoire :\r\n");
+    while((de = readdir(dir)) != NULL)
+    {
+    printf("  %s\r\n", &(de->d_name)[0]);
+    //wait_ms(100);
+  }
+
+    printf("Fermeture du répertoire. ");
+    error = closedir(dir);
     return_error(error);
 }