hello,
starting from the Tutorial "Using the SD library to print the directory of files on SD card" https://www.arduino.cc/en/Tutorial/listfiles (which actually works fine) I woud like to select one of the listed files in order to load it by selecting it. Has already someone found or written a file selection menu for this purpose?
Where will the list of files be displayed, perhaps on the Serial monitor ?
How/where will the user indicate their selected file, again perhaps on the Serial monitor ?
How many files will there be to select from ?
I would like to display it both on the Serial monitor and on a 320x240 or a 480x320 TFT screen.
I am working with ESP8266 and ESP32, so I think from RAM and TFT size a list of up to 64 files would be fine, but surely one could start with less than that (or use a dynamic list of files).
Selection mode would depend on the given menu structure, perhaps by 3 buttons: button up, down, enter, or via Serial monitor by entering a number. I would prefer a stand-allone solution though, tbh.
Let's think about the user interface
The user will need a list of files on the TFT and the list may be longer that a single screen can accommodate. Should the list be presented page by page, say 8 filenames at a time, with the ability to move up and down a page, or should it be possible to scroll up and down by one name at a time ?
Unless a full numeric keypad is available you presumably want to allow the user to highlight the file to be displayed then press an "action" button.
As to reading the filenames to be displayed, the filenames each take a maximum of 14 bytes (8.3 + possible / + terminating zero) and there may be 64 of them which will require 14 * 64 bytes of storage (896 bytes). An ESP8266 or ESP32 has enough memory available to enable the filenames to be held in an array so let's start with that.
Start by changing the listfiles program to declare an array of 64 char pointers as a global variable then instead of printing the filenames as they are read save each of them in the array and increment the array index. Once all of the filenames have been read iterate through the array and print each of them to the Serial monitor
I actually was thinking of a list of Arduino Strings instead of char*, what would you think? Perhaps for nested files in subdirectories a String may cover longer path+file names and might be easier to handle.
As to the numeric pad, I don't have one and actually it would need too much place, but a screen menu with a button-controlled "cursor" would be excellent (or using touch screen features, but that's quite shaky to my experience).
I personally have not the skills to write this thing, that's why I asked for an already existing program which anyone knows, sort of an extended version of the Tutorial "Using the SD library to print the directory of files on SD card"
I actually was thinking of a list of Arduino Strings instead of char*, what would you think?
I think don't do it. You may have plenty of RAM but don't fragment it by using Strings
Perhaps for nested files in subdirectories a String may cover longer path+file names and might be easier to handle.
Subdirectories. An extra complication arises. Have you got a full specification of the requirements ?
A C style string (lowercase s) can be as long as you like withing reason. No need to use Strings (uppercase S)
I personally have not the skills to write this thing, that's why I asked for an already existing program which anyone knows,
Good luck with finding such a thing.
that's why I asked for an available program. But std::string needs more memory than String (CMIIW)
std::string needs more memory than String (CMIIW)
Can you cite a source for this information because it sounds very unlikely
"I actually was thinking of a list of Arduino Strings instead of char*, what would you think?"
If you understand String functions, go with that to develop your project. If you hit a point that Strings can't support, the experts should be able to provide example code to address the issue.
as stated, I actually thought that someone during the last years might have already created something to load files by a menu.
"as stated, I actually thought that someone during the last years might have already created something to load files by a menu."
Use the forum search function in the upper right of this page to search for SD files and similar key words. You will probably find many previous project discussions and code using these devices.
I did already, but failed (looked twice, perhaps am missing something though)
If you understand String functions, go with that to develop your project. If you hit a point that Strings can't support, the experts should be able to provide example code to address the issue.
I think that is bad advice. Getting a long way into a project using Strings then converting it to use strings would not be a sensible plan.
"I did already, but failed (looked twice, perhaps am missing something though)"
Well, within the below 500+ search results, you might find info and code similar to the file handling you desire. What is your concept of a "file menu" and what do you want to do with the file? Just some starting basics.
tbh, in your search link I actually don't see a souce code solution which could be taken and used. As to the features, I already stated what would be wishful in posts #1-#4 - but how it was resolved, that would surely depend on the given solution which the author might have used: If there once existed such a working example, then I simply would gladly look and test.
You are extremely unlikely to find prewritten code that does exactly what you want.
Time to roll up your sleeves and write your own I think
UKHeliBob:
You are extremely unlikely to find prewritten code
that is actually already the result of searching also by the link given by zoomkat.
But as stated, this task is far beyond my skills, thats why I asked the topic opening question.
this task is far beyond my skills
Unless you are prepared to pay for someone to do it for you then you need to have a bash at it yourself, albeit with help here when you are stuck
So, where are you stuck at the moment given the advice that you have already been given ?
I do not even now how to put all the printed filenames (and subdir paths+filenames) into a String list.
Perhaps it would be simpler if one listed just the files of either dir and then expand the subdir when clicked/selected (in a proprietary window frame), but even then the paths+filenames have to be listed correctly for direct access, and move back to upper dir by selecting ".."
I do not even now how to put all the printed filenames (and subdir paths+filenames) into a String list.
If I were you I would forget the directory navigation for now and concentrate on listing and selecting a filename in the root directory. Walk, don't run and don't try to do everything at once. Small steps add up but take it slowly
Do you know what an array of values is ?
If not then do some reading about arrays in C/C++ as your first task
The aim will be to read a filename (you already have code for that), put it into an array then increment the array index to the next position ready for the next filename. None of that may mean anything to you at the moment but reading about arrays should clarify what it means.
We can discuss whether to use Strings or strings later