SNAKE GAME

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
congvu
Date:
Wed Nov 25 04:25:25 2020 +0000
Revision:
0:24041b847eb5
ECE2035 SNAKE GAME;

Who changed what in which revision?

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