【发布时间】:2014-10-28 15:52:08
【问题描述】:
我是微控制器编程的新手,但遇到了问题。
我正在尝试制作一个播放 USB 音乐的设备。我可以从 USB 读取,但我不知道如何选择某个文件。我正在使用dirent。
到目前为止我的代码:
while (true) {
USBHostMSD msd("usb");
//setup PWM hardware for a Class D style audio output
PWMout.period(1.0/400000.0);
// wait until connected to a USB device
while(!msd.connect()) {
Thread::wait(500);
}
FILE *wave_file;
lcd.cls();
lcd.locate(0,3);
DIR *dir;
struct dirent *ent;
int i=0;
int stevilo_datotek =0;
dir = opendir ("/usb/");
if (dir != NULL)
{
while ((ent = readdir (dir)) != NULL)
{
lcd.printf ("%s\n", ent->d_name[0]);
}
}
现在此代码显示 USB 上的内容。如何使用设备上的按钮浏览 USB 上的文件?我想知道是否有办法为某首歌曲分配一个特定编号,以便我可以导航。我研究dirent.h 文件很久了,我找不到dirent 保存文件顺序的位置(如果有的话)。
【问题讨论】:
标签: c opendir readdir dirent.h