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