
Mbed project to control a hoverboard
Dependencies: mbed wave_player Servo 4DGL-uLCD-SE LSM9DS1_Library_cal HC_SR04_Ultrasonic_Library
SDFileSystem/FATFileSystem/FATDirHandle.cpp@0:808403b99108, 2020-04-28 (annotated)
- Committer:
- msafwan3
- Date:
- Tue Apr 28 20:15:24 2020 +0000
- Revision:
- 0:808403b99108
project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
msafwan3 | 0:808403b99108 | 1 | /* mbed Microcontroller Library |
msafwan3 | 0:808403b99108 | 2 | * Copyright (c) 2006-2012 ARM Limited |
msafwan3 | 0:808403b99108 | 3 | * |
msafwan3 | 0:808403b99108 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
msafwan3 | 0:808403b99108 | 5 | * of this software and associated documentation files (the "Software"), to deal |
msafwan3 | 0:808403b99108 | 6 | * in the Software without restriction, including without limitation the rights |
msafwan3 | 0:808403b99108 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
msafwan3 | 0:808403b99108 | 8 | * copies of the Software, and to permit persons to whom the Software is |
msafwan3 | 0:808403b99108 | 9 | * furnished to do so, subject to the following conditions: |
msafwan3 | 0:808403b99108 | 10 | * |
msafwan3 | 0:808403b99108 | 11 | * The above copyright notice and this permission notice shall be included in |
msafwan3 | 0:808403b99108 | 12 | * all copies or substantial portions of the Software. |
msafwan3 | 0:808403b99108 | 13 | * |
msafwan3 | 0:808403b99108 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
msafwan3 | 0:808403b99108 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
msafwan3 | 0:808403b99108 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
msafwan3 | 0:808403b99108 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
msafwan3 | 0:808403b99108 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
msafwan3 | 0:808403b99108 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
msafwan3 | 0:808403b99108 | 20 | * SOFTWARE. |
msafwan3 | 0:808403b99108 | 21 | */ |
msafwan3 | 0:808403b99108 | 22 | #include <string.h> |
msafwan3 | 0:808403b99108 | 23 | #include "ff.h" |
msafwan3 | 0:808403b99108 | 24 | #include "FATDirHandle.h" |
msafwan3 | 0:808403b99108 | 25 | |
msafwan3 | 0:808403b99108 | 26 | using namespace mbed; |
msafwan3 | 0:808403b99108 | 27 | |
msafwan3 | 0:808403b99108 | 28 | FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) { |
msafwan3 | 0:808403b99108 | 29 | dir = the_dir; |
msafwan3 | 0:808403b99108 | 30 | } |
msafwan3 | 0:808403b99108 | 31 | |
msafwan3 | 0:808403b99108 | 32 | int FATDirHandle::closedir() { |
msafwan3 | 0:808403b99108 | 33 | delete this; |
msafwan3 | 0:808403b99108 | 34 | return 0; |
msafwan3 | 0:808403b99108 | 35 | } |
msafwan3 | 0:808403b99108 | 36 | |
msafwan3 | 0:808403b99108 | 37 | struct dirent *FATDirHandle::readdir() { |
msafwan3 | 0:808403b99108 | 38 | FILINFO finfo; |
msafwan3 | 0:808403b99108 | 39 | |
msafwan3 | 0:808403b99108 | 40 | #if _USE_LFN |
msafwan3 | 0:808403b99108 | 41 | finfo.lfname = cur_entry.d_name; |
msafwan3 | 0:808403b99108 | 42 | finfo.lfsize = sizeof(cur_entry.d_name); |
msafwan3 | 0:808403b99108 | 43 | #endif // _USE_LFN |
msafwan3 | 0:808403b99108 | 44 | |
msafwan3 | 0:808403b99108 | 45 | FRESULT res = f_readdir(&dir, &finfo); |
msafwan3 | 0:808403b99108 | 46 | |
msafwan3 | 0:808403b99108 | 47 | #if _USE_LFN |
msafwan3 | 0:808403b99108 | 48 | if(res != 0 || finfo.fname[0]==0) { |
msafwan3 | 0:808403b99108 | 49 | return NULL; |
msafwan3 | 0:808403b99108 | 50 | } else { |
msafwan3 | 0:808403b99108 | 51 | if(cur_entry.d_name[0]==0) { |
msafwan3 | 0:808403b99108 | 52 | // No long filename so use short filename. |
msafwan3 | 0:808403b99108 | 53 | memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); |
msafwan3 | 0:808403b99108 | 54 | } |
msafwan3 | 0:808403b99108 | 55 | return &cur_entry; |
msafwan3 | 0:808403b99108 | 56 | } |
msafwan3 | 0:808403b99108 | 57 | #else |
msafwan3 | 0:808403b99108 | 58 | if(res != 0 || finfo.fname[0]==0) { |
msafwan3 | 0:808403b99108 | 59 | return NULL; |
msafwan3 | 0:808403b99108 | 60 | } else { |
msafwan3 | 0:808403b99108 | 61 | memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); |
msafwan3 | 0:808403b99108 | 62 | return &cur_entry; |
msafwan3 | 0:808403b99108 | 63 | } |
msafwan3 | 0:808403b99108 | 64 | #endif /* _USE_LFN */ |
msafwan3 | 0:808403b99108 | 65 | } |
msafwan3 | 0:808403b99108 | 66 | |
msafwan3 | 0:808403b99108 | 67 | void FATDirHandle::rewinddir() { |
msafwan3 | 0:808403b99108 | 68 | dir.index = 0; |
msafwan3 | 0:808403b99108 | 69 | } |
msafwan3 | 0:808403b99108 | 70 | |
msafwan3 | 0:808403b99108 | 71 | off_t FATDirHandle::telldir() { |
msafwan3 | 0:808403b99108 | 72 | return dir.index; |
msafwan3 | 0:808403b99108 | 73 | } |
msafwan3 | 0:808403b99108 | 74 | |
msafwan3 | 0:808403b99108 | 75 | void FATDirHandle::seekdir(off_t location) { |
msafwan3 | 0:808403b99108 | 76 | dir.index = location; |
msafwan3 | 0:808403b99108 | 77 | } |
msafwan3 | 0:808403b99108 | 78 |