Christian Lerche
/
EA_DoorPlayer
EA BaseBoard, playing wav, PC see\'s SD-card through USB port.
ChaNFS/FATDirHandle.cpp@0:fef366d2ed20, 2011-11-22 (annotated)
- Committer:
- Lerche
- Date:
- Tue Nov 22 05:45:58 2011 +0000
- Revision:
- 0:fef366d2ed20
Thanks to those who provided EA_WavPlayer and USB_MSC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lerche | 0:fef366d2ed20 | 1 | /* mbed Microcontroller Library - FATDirHandle |
Lerche | 0:fef366d2ed20 | 2 | * Copyright (c) 2008, sford |
Lerche | 0:fef366d2ed20 | 3 | */ |
Lerche | 0:fef366d2ed20 | 4 | |
Lerche | 0:fef366d2ed20 | 5 | #include <stdio.h> |
Lerche | 0:fef366d2ed20 | 6 | #include <stdlib.h> |
Lerche | 0:fef366d2ed20 | 7 | #include <string.h> |
Lerche | 0:fef366d2ed20 | 8 | #include "ff.h" |
Lerche | 0:fef366d2ed20 | 9 | #include "FATDirHandle.h" |
Lerche | 0:fef366d2ed20 | 10 | #include "FATFileSystem.h" |
Lerche | 0:fef366d2ed20 | 11 | |
Lerche | 0:fef366d2ed20 | 12 | namespace mbed { |
Lerche | 0:fef366d2ed20 | 13 | |
Lerche | 0:fef366d2ed20 | 14 | FATDirHandle::FATDirHandle(const DIR_t &the_dir) { |
Lerche | 0:fef366d2ed20 | 15 | dir = the_dir; |
Lerche | 0:fef366d2ed20 | 16 | } |
Lerche | 0:fef366d2ed20 | 17 | |
Lerche | 0:fef366d2ed20 | 18 | int FATDirHandle::closedir() { |
Lerche | 0:fef366d2ed20 | 19 | delete this; |
Lerche | 0:fef366d2ed20 | 20 | return 0; |
Lerche | 0:fef366d2ed20 | 21 | } |
Lerche | 0:fef366d2ed20 | 22 | |
Lerche | 0:fef366d2ed20 | 23 | struct dirent *FATDirHandle::readdir() { |
Lerche | 0:fef366d2ed20 | 24 | FILINFO finfo; |
Lerche | 0:fef366d2ed20 | 25 | #if _USE_LFN |
Lerche | 0:fef366d2ed20 | 26 | static char lfn[_MAX_LFN * (_LFN_UNICODE ? 2 : 1) + 1]; |
Lerche | 0:fef366d2ed20 | 27 | finfo.lfname = lfn; |
Lerche | 0:fef366d2ed20 | 28 | finfo.lfsize = sizeof(lfn); |
Lerche | 0:fef366d2ed20 | 29 | #endif |
Lerche | 0:fef366d2ed20 | 30 | FRESULT res = f_readdir(&dir, &finfo); |
Lerche | 0:fef366d2ed20 | 31 | if(res != 0 || finfo.fname[0]==0) { |
Lerche | 0:fef366d2ed20 | 32 | return NULL; |
Lerche | 0:fef366d2ed20 | 33 | } else { |
Lerche | 0:fef366d2ed20 | 34 | char* fn; |
Lerche | 0:fef366d2ed20 | 35 | int stringSize = 0; |
Lerche | 0:fef366d2ed20 | 36 | #if _USE_LFN |
Lerche | 0:fef366d2ed20 | 37 | fn = *finfo.lfname ? finfo.lfname : finfo.fname; |
Lerche | 0:fef366d2ed20 | 38 | stringSize = finfo.lfsize; |
Lerche | 0:fef366d2ed20 | 39 | #else |
Lerche | 0:fef366d2ed20 | 40 | fn = fno.fname; |
Lerche | 0:fef366d2ed20 | 41 | stringSize = sizeof(finfo.fname); |
Lerche | 0:fef366d2ed20 | 42 | #endif |
Lerche | 0:fef366d2ed20 | 43 | memcpy(cur_entry.d_name, fn, stringSize); |
Lerche | 0:fef366d2ed20 | 44 | return &cur_entry; |
Lerche | 0:fef366d2ed20 | 45 | } |
Lerche | 0:fef366d2ed20 | 46 | } |
Lerche | 0:fef366d2ed20 | 47 | |
Lerche | 0:fef366d2ed20 | 48 | void FATDirHandle::rewinddir() { |
Lerche | 0:fef366d2ed20 | 49 | dir.index = 0; |
Lerche | 0:fef366d2ed20 | 50 | } |
Lerche | 0:fef366d2ed20 | 51 | |
Lerche | 0:fef366d2ed20 | 52 | off_t FATDirHandle::telldir() { |
Lerche | 0:fef366d2ed20 | 53 | return dir.index; |
Lerche | 0:fef366d2ed20 | 54 | } |
Lerche | 0:fef366d2ed20 | 55 | |
Lerche | 0:fef366d2ed20 | 56 | void FATDirHandle::seekdir(off_t location) { |
Lerche | 0:fef366d2ed20 | 57 | dir.index = location; |
Lerche | 0:fef366d2ed20 | 58 | } |
Lerche | 0:fef366d2ed20 | 59 | |
Lerche | 0:fef366d2ed20 | 60 | } |
Lerche | 0:fef366d2ed20 | 61 |