opendir - Reading and selecting files using dirent.h in C -


I am new to programming microcontrollers, and I have a problem.

I am trying to make a device that runs music from USB, I can read from the USB, but I have no idea how to choose a certain file. I am using dirent .

My code is still:

  while (true) {USBHostMSD msd ("usb"); // Setup PWM hardware for a Class D-style audio output PWMout.period (1.0 / 400000.0); // Wait until connecting to a USB device (! Msd.connect ()) {Thread :: wait (500); } FILE * wave_file; Lcd.cls (); Lcd.locate (0.3); DIR * Dyer; Struct dirent * ent; Int i = 0; Int stevilo_datotek = 0; Dir = opendir ("/ usb /"); If (dir! = Null) {while (at = reddir (dir) = = null) {lcd.printf ("% s \ n", att-> d_nn [0]); }}  

Now this code shows on USB how do I navigate through files on USB using the buttons on the device? I want to know that there is a way to assign a certain number of fixed songs to which I can navigate. I've read dirent.h for the file for so long, and I do not know where dirent saves the file order (if it does).

You can confuse the purpose of dirent.h. In short, it can be difficult to see the forest for trees.

You can note the information in a data structure (like array or a list) (at-> D_NA, note that there is an indicator for an array of anti-> D_NA characters, which is often called 'string ', Then use that straight with the code, which detects the press the button press to move the index up or down (in a more or less index) index, make sure that your Index range or the arm of your structure It does not go away). Or you can make that code where your loop waits on a button press and reads only the name of the file (using seekdir to move backwards)

UPDATE (comment response ): Keep in mind that file systems are tree structures like:

  / (root) + --- dir1 - ------------- ------------- + - dir1.1 ---- dir2 (empty) - file1.1 ---- dir3 - --- dir3.1 + --- file3.1 - --- file1 ---- file3.2 ---- file2  

You have to decide how to handle it, are you just a Going to support the directory (by putting all your music files in one place), allowing them to navigate, or just search for the files you know how to play?

There is no insured command for files (or sub-directories) and some system files can be added or deleted at any time.

Here is a pretty easy-to-remember example of listing directories:

  four * names [400]; // Create space for 400 names int ix; Ix = 0; If (dir! = Null) {while (at = reddir (dir) = = null) {lcd.printf ("% s \ n", att-> d_nn [0]); // Assign memory to store name names [ix] = (four *) molk (Stellen (et-> D_NA)); Copy the name from // directory entry strcpy (name [ix], ent-> d_name) from // strlen string.h to // malloc stdlib.h; // strcpy string.h to ix ++; If (ix> = 400) {// do something because your array is not large}}}  

Now your name is in 'array' and they can know the values ​​by index ' Ix-1 'is your last name, 0 is your first name. Press your button to increase / decrease the index in your name array that identifies the name you want. Keep in mind that some of them may have directory names instead of file names.

This is definitely the brain, you want to allocate the array instead of using fixed value (actually you have to cross the 'name' array in the calling function, you have to do it) " Safe "versions of Streakpy (memory overflow to help prevent corruption), etc. But it should give you an idea of ​​how you can keep the name in memory.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -