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