rtos sd encoder systems

Dependencies:   mbed

Committer:
eembed
Date:
Thu Aug 01 08:00:33 2019 +0000
Revision:
0:5459cdde6298
first commit

Who changed what in which revision?

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