temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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