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