Modifications

Sauter à la navigation Sauter à la recherche
1 469 octets ajoutés ,  30 août 2013 à 20:24
aucun résumé de modification
Ligne 127 : Ligne 127 :  
</nowiki>
 
</nowiki>
   −
== Looking for files in a directory ==
+
== Chercher les fichiers dans un répertoire ==
   −
OK now that you've initialized the card, we perform a recursive list of all files found. This is useful for debugging and ALSO shows how you can navigate the file system
+
OK maintenant que la carte est initialisée, nous affichons une liste de tous les fichiers que nous trouvons. C'est utile pour deboguer et vous montre aussi comment naviguer dans le système de fichier.
   −
To start, pass a directory object (like '''root''') to '''lsR()''' which will do the following:
+
Pour commencer, passer un objet répertoire (''directory'' en anglais) tel que '''root''' a la fonction '''lsR()'''.
# Read a file from the directory. The files are read in the order they are copied into the directory, '''not alphabetical order'''!
+
 
# If the directories are the special links "." (current directory) or ".." (upper directory) it ignores them and goes to step 1 again.
+
lsR effectue les opérations suivantes:
# It prints out spaces to create a nicely formatted output. Each level of directory gets 2 spaces
+
# Lire un fichier du répertoire. Les fichiers sont lus dans l'ordre dans lequel ils sont copiés dans le répertoire, '''pas par ordre alphabétique'''!
# It prints out the name of the file in 8.3 format
+
# Si le répertoire à un nom/liens spécial "." (répertoire courant) or ".." (répertoire parent) ignorez les et répéter encore l'opération 1.
# If it is a subdirectory, it makes a new object and opens up the subdirectory. Then it prints out all of the files in that new directory
+
# Il affiche des espaces pour formater correctement les sortie de message. Chaque niveau de répertoire prends deux espaces de plus.
# It continues to step 1 until there are no more files to be read
+
# Affiche le nom du fichier au format 8.3
 +
# S'il s'agit d'un sous répertoire, il crée un nouvel objet et ouvre le sous répertoire. Ensuite, il affiche tous les fichiers de ce nouveau répertoire.
 +
# Il continue à l'étape 1 jusqu'a ce qu'il ne reste plus de fichier à lire
    
  <nowiki>/*
 
  <nowiki>/*
  * list recursively - possible stack overflow if subdirectories too nested
+
  * Affichage récursif - Possiblilité de dépassement de pile (stack overflow)
 +
* s'il y a trop de répertoire imbriqués
 
  */
 
  */
 
void lsR(FatReader &d)
 
void lsR(FatReader &d)
 
{
 
{
   int8_t r;                    // indicates the level of recursion
+
   int8_t r;                    // indique le niveau de récursion
 
    
 
    
   while ((r = d.readDir(dirBuf)) > 0) {    // read the next file in the directory
+
   while ((r = d.readDir(dirBuf)) > 0) {    // Lire le prochain fichier dans le répertoire
     // skip subdirs . and ..
+
     // Ignore les sous répertoires . et ..
 
     if (dirBuf.name[0] == '.')  
 
     if (dirBuf.name[0] == '.')  
 
       continue;
 
       continue;
 
      
 
      
 
     for (uint8_t i = 0; i < dirLevel; i++)  
 
     for (uint8_t i = 0; i < dirLevel; i++)  
       Serial.print(' ');        // this is for prettyprinting, put spaces in front
+
       Serial.print(' ');        // Meilleur affichage, place des espaces devant
     printName(dirBuf);          // print the name of the file we just found
+
     printName(dirBuf);          // Afficher le nom de fichier trouvé
     Serial.println();          // and a new line
+
     Serial.println();          // et un retour à la ligne
 
      
 
      
     if (DIR_IS_SUBDIR(dirBuf)) {  // we will recurse on any direcory
+
     if (DIR_IS_SUBDIR(dirBuf)) {  // Nous allons répéter (récursion) pour chaque sous-répertoire
       FatReader s;                // make a new directory object to hold information
+
       FatReader s;                // Créer un nouvel objet répertoire pour maintenir les informations
       dirLevel += 2;              // indent 2 spaces for future prints
+
       dirLevel += 2;              // indenter de 2 espaces (pour les affichages futurs)
 
       if (s.open(vol, dirBuf))  
 
       if (s.open(vol, dirBuf))  
         lsR(s);                    // list all the files in this directory now!
+
         lsR(s);                    // Afficher tous les fichiers du répertoire. Maintenant!
       dirLevel -=2;                // remove the extra indentation
+
       dirLevel -=2;                // retirer l'indentation ajoutée (quand fini de lister le sous-répertoire)
 
     }
 
     }
 
   }
 
   }
   sdErrorCheck();                  // are we doign OK?
+
   sdErrorCheck();                  // Est-ce que tout est OK?
 
}
 
}
 
</nowiki>
 
</nowiki>
   −
There is also a helper called '''printName''' which prints out the file in a nice format. Files are named in '''8.3''' format, an older and simpler way of addressing files. Its a little less pretty than "Long Name Format" so watch out to see what your files are renamed as. For example "Bird song.wav" may be renamed to "BIRDSONG.WAV" or "BIRDSO~1.WAV" !  
+
Il y a aussi une fonction d'aide nommée '''printName''' qui affiche le nom du fichier (dans un format lisible). les fichiers sont nommés au format  '''8.3''', une vieille façon d'adresser les fichier (mais aussi plus simple). C'est un petit peu moins beau qu'afficher les noms au format long, donc regardez quand même comment vos fichiers sont re-nommés en format court. Par exemple, le fichier "Bird song.wav" pourrait être renommé en "BIRDSONG.WAV" ou "BIRDSO~1.WAV" !  
    
  <nowiki>/*
 
  <nowiki>/*
  * print dir_t name field. The output is 8.3 format, so like SOUND.WAV or FILENAME.DAT
+
  * Affiche le champs name de dir_t. Format de sortie est 8.3, ressemble donc à SOUND.WAV ou FILENAME.DAT
 
  */
 
  */
 
void printName(dir_t &dir)
 
void printName(dir_t &dir)
 
{
 
{
   for (uint8_t i = 0; i < 11; i++) {    // 8.3 format has 8+3 = 11 letters in it
+
   for (uint8_t i = 0; i < 11; i++) {    // format 8.3 a 8+3 = 11 lettres
 
     if (dir.name[i] == ' ')
 
     if (dir.name[i] == ' ')
         continue;        // dont print any spaces in the name
+
         continue;        // N'affiche pas les espaces dans le nom
 
     if (i == 8)  
 
     if (i == 8)  
         Serial.print('.');          // after the 8th letter, place a dot
+
         Serial.print('.');          // placer un point après la 8ieme lettre
     Serial.print(dir.name[i]);      // print the n'th digit
+
     Serial.print(dir.name[i]);      // afficher la lettre à la position n
 
   }
 
   }
 
   if (DIR_IS_SUBDIR(dir))  
 
   if (DIR_IS_SUBDIR(dir))  
     Serial.print('/');      // directories get a / at the end
+
     Serial.print('/');      // Afficher un "/" à la fin quand c'est un répertoire
 
}
 
}
 
</nowiki>
 
</nowiki>
One thing that appears in '''loop()''' is '''dir.rewind()'''. The reason we rewind a directory is that our Arduino code is very simple. It can go through the files in a directory but only 'forward', not backward (FAT format is kinda like that). So if you skipped a file and want to go back, or you've gone through the directory, you will need to call '''rewind()''' to set it back to the beginning!
+
Une des chose qui apparait dans '''loop()''' c'est '''dir.rewind()''' (action de remonter) . La raison pour laquelle nous remontons les répertoires c'est que le code de notre Arduino est très simple. Il peut traverser les fichiers d'un répertoire mais seulement 'vers l'avant' (forward), pas vers l'arrière (le format FAT est un peu comme ca).
   −
== Playing all the files ==
+
Donc, si vous avez raté un fichier ou si vous voulez aller en arrière, ou si vous avez traversé le répertoire, vous devrez appeler '''rewind()''' pour revenir au début du répertoire!
   −
The digital audio player plays all files in the card. To do that it recursively looks in every directory, just like lsR() above so the code looks somewhat similar. The big difference is we call the play() routine to play a file!
+
== Jouer tous les fichiers ==
   −
To start, pass a directory object (like root) to '''lsR()''' which will do the following:
+
Le "digital audio player" joue tous les fichier de la carte. Pour ce faire, il cherche les fichiers dans tous les répertoires de façon récursive (comme le fait lsR() ci-avant). Cela produit un code assez similaire eu point précédent.
# Read a file from the directory. The files are read in the order they are copied into the directory, '''not alphabetical order'''!
+
 
# If the directories are the special links "." (current directory) or ".." (upper directory) it ignores them and goes to step 1 again.
+
La grande différence c'est que nous appelons la fonction play() qui recherche les fichiers à jouer!
# It prints out spaces to create a nicely formatted output. Each level of directory gets 2 spaces
+
 
# It prints out the name of the file in 8.3 format
+
Le fichier est joué à l'aide de wave.play()
# If it is a subdirectory, it makes a new object and opens up the subdirectory. Then it plays all of the wave files in that new directory
+
 
# If it isn't a subdirectory, it will try to play the file by opening it as a Wave object. That requires looking through the file and trying to find a Wave header, etc. If it doesnt succeed it will print out that its not valid and skip to the next file
+
Pour commencer, passez un objet répertoire (tel que root) a '''play()''' effectue les étapes suivantes:
# If the wave file is valid, it will finally start the file by calling '''play()''' on the Wave object
+
# Lit un fichier depuis le répertoire. Les fichier sont lus dans l'ordre dans lequel ils ont étés copiés dans le répertoire, '''pas l'ordre alphabétique'''!
# While the wave sound file is playing, it prints out a dot every 100 ms or so.
+
# Si le répertoire à un nom/lien spécial comme "." (répertoire courant) or ".." (répertoire parent) sont ignorés et on recommence à l'étape 1.
# It continues to step 1 until there are no more files to be read
+
# Il affiche des espace pour créer un format d'affichage plus sympathique. Chaque niveau de répertoire ajoute deux espaces.
 +
# Il affiche le nom du fichier au format 8.3 .
 +
# Si c'est un sous répertoire, il crée un nouvel objet et ouvre le sous répertoire. Ensuite, il joue tous les fichioers wave qu'il y a dans ce nouveau répertoire.
 +
# Si ce n'est pas un sous répertoire, il va essayer de jouer le fichier en ouvrant celui-ci comme un objet Wave. Cela nécessite d'ouvrir le fiochier et d'essayer de trouver l'entête Wave (Wave header), etc. S'il n'y arrive pas, il affiche un message comme quoi le fichier n'est pas valide puis il passe au fichier suivant.
 +
# Si le fichier wave est valide, il commence à le jouer en appelant la fonction '''play()''' de l'objet Wave
 +
# Tant que le fichier wave est jouer, le programme affiche un point toutes les 100 ms.
 +
# Le programme continue à l'étape 1 jusqu'à ce qu'il n'y ait plus de fichier à lire.
    
  <nowiki>/*
 
  <nowiki>/*
  * play recursively - possible stack overflow if subdirectories too nested
+
  * Joue récursivement - Possibilité de dépassement de pile (stack overflow)
 +
* s'il y a trop de répertoire imbriqués
 
  */
 
  */
 
void play(FatReader &dir)
 
void play(FatReader &dir)
 
{
 
{
 
   FatReader file;
 
   FatReader file;
   while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
+
   while (dir.readDir(dirBuf) > 0) {    // lit un à un chaque fichier du répertoire
 
     // skip . and .. directories
 
     // skip . and .. directories
 
     if (dirBuf.name[0] == '.')  
 
     if (dirBuf.name[0] == '.')  
 
       continue;
 
       continue;
 
      
 
      
     Serial.println();            // clear out a new line
+
     Serial.println();            // Affiche une nouvelle ligne
 
      
 
      
 
     for (uint8_t i = 0; i < dirLevel; i++)  
 
     for (uint8_t i = 0; i < dirLevel; i++)  
       Serial.print(' ');      // this is for prettyprinting, put spaces in front
+
       Serial.print(' ');      // amélioration de l'affichage, place des espace à l'avant
   −
     if (!file.open(vol, dirBuf)) {      // open the file in the directory
+
     if (!file.open(vol, dirBuf)) {      // Ouvre le fichier dans le répertoire
       Serial.println("file.open failed");  // something went wrong :(
+
       Serial.println("file.open failed");  // Qlque chose s'est mal passé :(
       while(1);                            // halt
+
       while(1);                            // Arrêter
 
     }
 
     }
 
      
 
      
     if (file.isDir()) {                    // check if we opened a new directory
+
     if (file.isDir()) {                    // Vérifie si c'est un nouveau sous-répertoire
 
       putstring("Subdir: ");
 
       putstring("Subdir: ");
 
       printName(dirBuf);
 
       printName(dirBuf);
       dirLevel += 2;                      // add more spaces
+
       dirLevel += 2;                      // Ajouter plus d'espace
 
       // play files in subdirectory
 
       // play files in subdirectory
       play(file);                        // recursive!
+
       play(file);                        // Récursivité!
 
       dirLevel -= 2;     
 
       dirLevel -= 2;     
 
     }
 
     }
 
     else {
 
     else {
       // Aha! we found a file that isnt a directory
+
       // HaHa! nous avons trouvé un fichier qui n'est pas un répertoire
       putstring("Playing "); printName(dirBuf);       // print it out
+
       putstring("Joue... "); printName(dirBuf); // Afficher le nom du fichier
       if (!wave.create(file)) {           // Figure out, is it a WAV proper?
+
       if (!wave.create(file)) {                 // Est-ce un fichier WAV ?
         putstring(" Not a valid WAV");    // ok skip it
+
         putstring(" fichier WAV invalide");    // non, alors on passe au suivant
 
       } else {
 
       } else {
         Serial.println();                  // Hooray it IS a WAV proper!
+
         Serial.println();                  // Hourra c'est un fichier WAV!
         wave.play();                      // make some noise!
+
         wave.play();                      // Faisons donc un peu de bruit!
 
        
 
        
         while (wave.isplaying) {          // playing occurs in interrupts, so we print dots in realtime
+
         while (wave.isplaying) {          // La reproduction audio utilise les interruption,  
           putstring(".");
+
           putstring(".");                 //    nous affichons donc les points en temps réel
 
           delay(100);
 
           delay(100);
 
         }
 
         }
         sdErrorCheck();                    // everything OK?
+
         sdErrorCheck();                    // Tout est OK?
//        if (wave.errors)Serial.println(wave.errors);    // wave decoding errors
+
//        if (wave.errors)Serial.println(wave.errors);    // Erreur de decodage wave
 
       }
 
       }
 
     }
 
     }
Ligne 254 : Ligne 264 :     
== dap_hc.pde ==
 
== dap_hc.pde ==
Here is the full sketch  
+
Voici le sketch dans son intégralité.
 +
 
 +
Note MCHobby: Les commentaires ont étés traduit dans les notes explicatives ci-dessus. Il ne le sont plus dans ce sketch.
    
  <nowiki>#include <FatReader.h>
 
  <nowiki>#include <FatReader.h>
Ligne 457 : Ligne 469 :  
</nowiki>
 
</nowiki>
   −
{{ADF-Accord}}
+
{{WaveShield-TRAILER}}
 
  −
{{MCH-Accord}}
 
29 917

modifications

Menu de navigation