![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dsfa
Dependencies: dsf SDFileSystem TextLCD mbed stepper_moter
Fork of my_example_Nucleo_Ex05_SD_zhangyuxiang2 by
SDRead/SDRead.cpp@4:c88bf297ee75, 2018-05-08 (annotated)
- Committer:
- brainliang
- Date:
- Tue May 08 01:50:44 2018 +0000
- Revision:
- 4:c88bf297ee75
sdfa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brainliang | 4:c88bf297ee75 | 1 | #include "SDRead.h" |
brainliang | 4:c88bf297ee75 | 2 | |
brainliang | 4:c88bf297ee75 | 3 | SDRead::SDRead(PinName mosi,PinName miso,PinName sclk,PinName cs,const char *name):SDFileSystem(mosi,miso,sclk,cs,name) |
brainliang | 4:c88bf297ee75 | 4 | {} |
brainliang | 4:c88bf297ee75 | 5 | bool SDRead:: Get_FileDir() |
brainliang | 4:c88bf297ee75 | 6 | { |
brainliang | 4:c88bf297ee75 | 7 | this -> mount(); |
brainliang | 4:c88bf297ee75 | 8 | DirHandle *dh = opendir("/sd/"); |
brainliang | 4:c88bf297ee75 | 9 | if(!dh){ |
brainliang | 4:c88bf297ee75 | 10 | return false; |
brainliang | 4:c88bf297ee75 | 11 | } |
brainliang | 4:c88bf297ee75 | 12 | dirent *entry; |
brainliang | 4:c88bf297ee75 | 13 | for(;;) |
brainliang | 4:c88bf297ee75 | 14 | { |
brainliang | 4:c88bf297ee75 | 15 | entry = dh -> readdir(); |
brainliang | 4:c88bf297ee75 | 16 | if(!entry) |
brainliang | 4:c88bf297ee75 | 17 | {break;} |
brainliang | 4:c88bf297ee75 | 18 | string dir_name = entry -> d_name; |
brainliang | 4:c88bf297ee75 | 19 | if(dir_name == "System Volume Information") |
brainliang | 4:c88bf297ee75 | 20 | continue; |
brainliang | 4:c88bf297ee75 | 21 | File_dir.push_back(dir_name); |
brainliang | 4:c88bf297ee75 | 22 | } |
brainliang | 4:c88bf297ee75 | 23 | dh -> closedir(); |
brainliang | 4:c88bf297ee75 | 24 | return true; |
brainliang | 4:c88bf297ee75 | 25 | } |
brainliang | 4:c88bf297ee75 | 26 | bool SDRead::Read_File(const char* FileName) |
brainliang | 4:c88bf297ee75 | 27 | { |
brainliang | 4:c88bf297ee75 | 28 | FILE *fp1 = fopen(FileName,"r"); |
brainliang | 4:c88bf297ee75 | 29 | if(fp1 == NULL) |
brainliang | 4:c88bf297ee75 | 30 | { |
brainliang | 4:c88bf297ee75 | 31 | return false; |
brainliang | 4:c88bf297ee75 | 32 | } |
brainliang | 4:c88bf297ee75 | 33 | char buf[200]; |
brainliang | 4:c88bf297ee75 | 34 | while(fgets(buf,sizeof(buf),fp1) != NULL) |
brainliang | 4:c88bf297ee75 | 35 | { |
brainliang | 4:c88bf297ee75 | 36 | string info = buf; |
brainliang | 4:c88bf297ee75 | 37 | Info.push_back(info); |
brainliang | 4:c88bf297ee75 | 38 | } |
brainliang | 4:c88bf297ee75 | 39 | return true; |
brainliang | 4:c88bf297ee75 | 40 | } |