Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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