Hey there,
i am working on a sd card file browser menu using the m2tklib file_select example (fileselectbox · olikraus/m2tklib Wiki · GitHub)
I have a 12x2 LCD display using the LiquidChrystal Library.
my File structure on the SD Card is the following
3.TXT
TESTDATEI1.TXT
DATEI1.TXT
ORDNER1
INGO.TXT
THOMAS.TXT
INA.TXT
ORDNER2
RALF.TXT
EMPTY (also a folder)
My Problem is that when i go into one of the folders and then go back to parent directory, every entry above the folder I was in disappeared. To clear things up i made a short video clip to show what i mean.
This is my actual CODE for the menu
/*=========================================================================*/
/* forward declarations */
M2_EXTERN_ALIGN(top_el_start);
/*=========================================================================*/
/* M2tk lib start */
M2tk m2 (&top_el_start, NULL, m2_eh_6bs, m2_gh_nlc);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FILE MENU TEST ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define FS_EXTRA_MENUES 1
/* helper variables for the strlist element */
uint8_t fs_m2tk_first = 0;
uint8_t fs_m2tk_cnt = 0;
/* show selected file */
const char *fs_show_file_label_cb(m2_rom_void_p element) {
return mas_GetFilename();
}
M2_LABEL(el_show_file_label, NULL, "Selected file:");
M2_LABELFN(el_show_filename, NULL, fs_show_file_label_cb);
M2_ROOT(el_show_file_ok, NULL, "ok", &top_el_start);
M2_LIST(list_show_file) = {&el_show_filename};
M2_VLIST(el_show_file_Vlist, NULL, list_show_file);
M2_ALIGN(top_el_show_file, "-0|2E0", &el_show_file_Vlist);
/* callback procedure for the file selection dialog */
const char *fs_strlist_getstr(uint8_t idx, uint8_t msg) {
if (msg == M2_STRLIST_MSG_GET_STR) {
/* Check for the extra button: Return string for this extra button */
if ( idx == 0 )
return "..";
/* Not the extra button: Return file/directory name */
mas_GetDirEntry(idx - FS_EXTRA_MENUES);
return mas_GetFilename();
} else if ( msg == M2_STRLIST_MSG_GET_EXTENDED_STR ) {
/* Check for the extra button: Return icon for this extra button */
if ( idx == 0 )
return "a"; /* arrow left of the m2icon font */
/* Not the extra button: Return file or directory icon */
mas_GetDirEntry(idx - FS_EXTRA_MENUES);
if ( mas_IsDir() )
return "A"; /* folder icon of the m2icon font */
return "B"; /* file icon of the m2icon font */
} else if ( msg == M2_STRLIST_MSG_SELECT ) {
/* Check for the extra button: Execute button action */
if ( idx == 0 ) {
if ( mas_GetPath()[0] == '\0' ) {
idx = 0;
m2_SetRoot(&top_el_start); /* go back to previous menu */
} else {
mas_ChDirUp();
m2_SetRoot(m2_GetRoot()); /* reset menu to first element, send NEW_DIALOG and force recount */
}
/* Not the extra button: Goto subdir or return (with selected file) */
} else {
mas_GetDirEntry(idx - FS_EXTRA_MENUES);
if ( mas_IsDir() ) {
mas_ChDir(mas_GetFilename());
m2_SetRoot(m2_GetRoot()); /* reset menu to first element, send NEW_DIALOG and force recount */
} else {
/* File has been selected. Here: Show the file to the user */
m2_SetRoot(&top_el_show_file);
}
}
} else if ( msg == M2_STRLIST_MSG_NEW_DIALOG ) {
/* (re-) calculate number of entries, limit no of entries to 250 */
if ( mas_GetDirEntryCnt() < 250-FS_EXTRA_MENUES )
fs_m2tk_cnt = mas_GetDirEntryCnt()+FS_EXTRA_MENUES;
else
fs_m2tk_cnt = 250;
}
return NULL;
}
M2_STRLIST(el_fs_strlist, "l2e0w9", &fs_m2tk_first, &fs_m2tk_cnt, fs_strlist_getstr);
M2_SPACE(el_fs_space, "W1h1");
M2_VSB(el_fs_strlist_vsb, "l2w5r1", &fs_m2tk_first, &fs_m2tk_cnt);
M2_LIST(list_fs_strlist) = { &el_fs_strlist, &el_fs_space, &el_fs_strlist_vsb };
M2_HLIST(el_top_fs, NULL, list_fs_strlist);
/*=========================================================================*/
/* a simple main menu for the file select */
M2_ROOT(el_start, NULL, "Sel", &el_top_fs);
M2_ALIGN(top_el_start, "-0|2E0", &el_start);
/*=========================================================================*/
Can anyone help me out please? I dont know how to solve that problem.
best regards,
Flo
PROBLEM SOLVED
I now used SdFat instead of the SD library. If you also want to do this you have to change two things to make it work:
in the file Arduino/libraries/m2tklib/utility/mas_sdfat.cpp in line 129
//mas_sdfat_file.getFilename(buf); // this is the old one
mas_sdfat_file.getName(buf,13);
and the init function for the sdfat object in the arduino setup() function is
//sdfat.init(SPI_HALF_SPEED,53); // this is wrong and it is written here : https://github.com/olikraus/m2tklib/wiki/mas
sdfat.begin(53, SPI_HALF_SPEED
I hope this can help someone.