Taking picture and uploading to sd card

Dependencies:   Ethernet_Camera_LS_Y201_SDcard SDFileSystem mbed

Fork of VC0706_jins by Albin Sebastian

Committer:
Dxmanas
Date:
Thu Feb 08 06:26:22 2018 +0000
Revision:
6:ffdac31f6106
Parent:
2:f2d70f552a3e
xzcvdv

Who changed what in which revision?

UserRevisionLine numberNew contents of line
azsymaivan 0:fbb29d9ea96b 1 #ifndef filelib
azsymaivan 0:fbb29d9ea96b 2 #define filelib
azsymaivan 0:fbb29d9ea96b 3
azsymaivan 0:fbb29d9ea96b 4 #include "mbed.h"
azsymaivan 0:fbb29d9ea96b 5 #include <time.h>
azsymaivan 0:fbb29d9ea96b 6 #include <ff.h> //found in lib SDFileSystem->FATFileSystem/ChaN
azsymaivan 0:fbb29d9ea96b 7 #include "SDFileSystem.h"
azsymaivan 0:fbb29d9ea96b 8
azsymaivan 0:fbb29d9ea96b 9
azsymaivan 0:fbb29d9ea96b 10 /*
azsymaivan 0:fbb29d9ea96b 11 typedef enum {
azsymaivan 0:fbb29d9ea96b 12 FR_OK = 0, // (0) Succeeded
azsymaivan 0:fbb29d9ea96b 13 FR_DISK_ERR, // (1) A hard error occurred in the low level disk I/O layer
azsymaivan 0:fbb29d9ea96b 14 FR_INT_ERR, // (2) Assertion failed
azsymaivan 0:fbb29d9ea96b 15 FR_NOT_READY, // (3) The physical drive cannot work
azsymaivan 0:fbb29d9ea96b 16 FR_NO_FILE, // (4) Could not find the file
azsymaivan 0:fbb29d9ea96b 17 FR_NO_PATH, // (5) Could not find the path
azsymaivan 0:fbb29d9ea96b 18 FR_INVALID_NAME, // (6) The path name format is invalid
azsymaivan 0:fbb29d9ea96b 19 FR_DENIED, // (7) Access denied due to prohibited access or directory full
azsymaivan 0:fbb29d9ea96b 20 FR_EXIST, // (8) Access denied due to prohibited access
azsymaivan 0:fbb29d9ea96b 21 FR_INVALID_OBJECT, // (9) The file/directory object is invalid
azsymaivan 0:fbb29d9ea96b 22 FR_WRITE_PROTECTED, // (10) The physical drive is write protected
azsymaivan 0:fbb29d9ea96b 23 FR_INVALID_DRIVE, // (11) The logical drive number is invalid
azsymaivan 0:fbb29d9ea96b 24 FR_NOT_ENABLED, // (12) The volume has no work area
azsymaivan 0:fbb29d9ea96b 25 FR_NO_FILESYSTEM, // (13) There is no valid FAT volume
azsymaivan 0:fbb29d9ea96b 26 FR_MKFS_ABORTED, // (14) The f_mkfs() aborted due to any parameter error
azsymaivan 0:fbb29d9ea96b 27 FR_TIMEOUT, // (15) Could not get a grant to access the volume within defined period
azsymaivan 0:fbb29d9ea96b 28 FR_LOCKED, // (16) The operation is rejected according to the file sharing policy
azsymaivan 0:fbb29d9ea96b 29 FR_NOT_ENOUGH_CORE, // (17) LFN working buffer could not be allocated
azsymaivan 0:fbb29d9ea96b 30 FR_TOO_MANY_OPEN_FILES, // (18) Number of open files > _FS_SHARE
azsymaivan 0:fbb29d9ea96b 31 FR_INVALID_PARAMETER // (19) Given parameter is invalid
azsymaivan 0:fbb29d9ea96b 32 } FRESULT;
azsymaivan 0:fbb29d9ea96b 33
azsymaivan 0:fbb29d9ea96b 34 */
azsymaivan 0:fbb29d9ea96b 35 /*
azsymaivan 0:fbb29d9ea96b 36 mode_t values in octal
azsymaivan 0:fbb29d9ea96b 37 S_IFREG 0100000
azsymaivan 0:fbb29d9ea96b 38 S_IFDIR 040000
azsymaivan 0:fbb29d9ea96b 39 S_IRUSR 0400 read permission, owner
azsymaivan 0:fbb29d9ea96b 40 S_IWUSR 0200 write permission, owner
azsymaivan 0:fbb29d9ea96b 41 S_IXUSR 0100 execute/search permission, owner
azsymaivan 0:fbb29d9ea96b 42 S_IRGRP 040 read permission, group
azsymaivan 0:fbb29d9ea96b 43 S_IWGRP 020 write permission, group
azsymaivan 0:fbb29d9ea96b 44 S_IXGRP 010 execute/search permission, group
azsymaivan 0:fbb29d9ea96b 45 S_IROTH 04 read permission, others
azsymaivan 0:fbb29d9ea96b 46 S_IWOTH 02 write permission, others
azsymaivan 0:fbb29d9ea96b 47 S_IXOTH 01 execute/search permission, others
azsymaivan 0:fbb29d9ea96b 48 */
azsymaivan 0:fbb29d9ea96b 49 struct sMystat {
azsymaivan 0:fbb29d9ea96b 50 // dev_t st_dev; /* ID of device containing file */
azsymaivan 0:fbb29d9ea96b 51 // ino_t st_ino; /* inode number */
azsymaivan 0:fbb29d9ea96b 52 mode_t st_mode; /* protection */
azsymaivan 0:fbb29d9ea96b 53 // nlink_t st_nlink; /* number of hard links */
azsymaivan 0:fbb29d9ea96b 54 // uid_t st_uid; /* user ID of owner */
azsymaivan 0:fbb29d9ea96b 55 // gid_t st_gid; /* group ID of owner */
azsymaivan 0:fbb29d9ea96b 56 // dev_t st_rdev; /* device ID (if special file) */
azsymaivan 0:fbb29d9ea96b 57 // off_t st_size; /* total size, in bytes */
azsymaivan 0:fbb29d9ea96b 58 DWORD st_size; /* total size, in bytes */
azsymaivan 0:fbb29d9ea96b 59 // blksize_t st_blksize; /* blocksize for file system I/O */
azsymaivan 0:fbb29d9ea96b 60 // blkcnt_t st_blocks; /* number of 512B blocks allocated */
azsymaivan 0:fbb29d9ea96b 61 // time_t st_atime; /* time of last access */
azsymaivan 0:fbb29d9ea96b 62 time_t st_mtime; /* time of last modification */
azsymaivan 0:fbb29d9ea96b 63 // time_t st_ctime; /* time of last status change */
azsymaivan 0:fbb29d9ea96b 64 };
azsymaivan 0:fbb29d9ea96b 65
azsymaivan 0:fbb29d9ea96b 66 sMystat myStatBuf; //store info for file
azsymaivan 0:fbb29d9ea96b 67 FILINFO finfo; //global file info struct see ff.h
azsymaivan 0:fbb29d9ea96b 68 FATFS_DIR dinfo; //global directoty info struct see ff.h
azsymaivan 0:fbb29d9ea96b 69
azsymaivan 0:fbb29d9ea96b 70 FRESULT get_fileInfo(const char *path) //use finfo for get result fields
azsymaivan 0:fbb29d9ea96b 71 {
azsymaivan 0:fbb29d9ea96b 72 FRESULT res = f_stat(path,&finfo); /* Get file status */
azsymaivan 0:fbb29d9ea96b 73 if (EnDebugMSG)
azsymaivan 0:fbb29d9ea96b 74 if (res)
WizLeo 2:f2d70f552a3e 75 printf("\r\n-->get_fileInfo:%s ,res=%d ,Not Found!",path,res);
azsymaivan 0:fbb29d9ea96b 76 else
WizLeo 2:f2d70f552a3e 77 printf("\r\n-->get_fileInfo:%s ,res=%d ,Found!",path,res);
azsymaivan 0:fbb29d9ea96b 78 return res;
azsymaivan 0:fbb29d9ea96b 79 }
azsymaivan 0:fbb29d9ea96b 80
azsymaivan 0:fbb29d9ea96b 81 FRESULT get_dirInfo(const char *path)
azsymaivan 0:fbb29d9ea96b 82 {
azsymaivan 0:fbb29d9ea96b 83 FRESULT res= f_opendir (&dinfo,path); /* FR_OK(0): successful, !=0: error code */
azsymaivan 0:fbb29d9ea96b 84 if (EnDebugMSG)
azsymaivan 0:fbb29d9ea96b 85 if (res)
WizLeo 2:f2d70f552a3e 86 printf("\r\n-->get_dirInfo :%s res=%d ,This is Not Directory!",path,res);
azsymaivan 0:fbb29d9ea96b 87 else
WizLeo 2:f2d70f552a3e 88 printf("\r\n-->get_dirInfo :%s res=%d ,This is Directory!",path,res);
azsymaivan 0:fbb29d9ea96b 89 return res;
azsymaivan 0:fbb29d9ea96b 90 }
azsymaivan 0:fbb29d9ea96b 91
azsymaivan 0:fbb29d9ea96b 92 FRESULT Mystat(const char *path, struct sMystat *buf)
azsymaivan 0:fbb29d9ea96b 93 {
azsymaivan 0:fbb29d9ea96b 94 FRESULT res = f_stat(path,&finfo); /* Get file status */
azsymaivan 0:fbb29d9ea96b 95 if (res == FR_OK) {
azsymaivan 0:fbb29d9ea96b 96 buf->st_size = finfo.fsize;
azsymaivan 0:fbb29d9ea96b 97 buf->st_mtime = finfo.ftime; //fdate;
azsymaivan 0:fbb29d9ea96b 98 buf->st_mode = 4; //?
azsymaivan 0:fbb29d9ea96b 99 }
azsymaivan 0:fbb29d9ea96b 100 if (EnDebugMSG)
WizLeo 2:f2d70f552a3e 101 printf("\r\n--Mystat Path:%s ,filesize:%14lld ,res=%d",path, buf->st_size, res);
azsymaivan 0:fbb29d9ea96b 102 return res;
azsymaivan 0:fbb29d9ea96b 103 }
azsymaivan 0:fbb29d9ea96b 104
azsymaivan 0:fbb29d9ea96b 105
azsymaivan 0:fbb29d9ea96b 106 static char* get_mime_type( char* filename )
azsymaivan 0:fbb29d9ea96b 107 {
azsymaivan 0:fbb29d9ea96b 108 char* extension;
azsymaivan 0:fbb29d9ea96b 109 extension = strrchr( filename, '.' ); //get string after last .
azsymaivan 0:fbb29d9ea96b 110 if (EnDebugMSG)
WizLeo 2:f2d70f552a3e 111 printf("\r\n-->get_mime_tipe filename:%s, extension:%s",filename, extension);
azsymaivan 0:fbb29d9ea96b 112 if (extension !=NULL) {
azsymaivan 0:fbb29d9ea96b 113 if (strcasecmp(extension,".htm")==0 || strcasecmp(extension,".html") ==0)
azsymaivan 0:fbb29d9ea96b 114 return "text/html; charset=iso-8859-1";
azsymaivan 0:fbb29d9ea96b 115 if (strcasecmp(extension,".png")==0)
azsymaivan 0:fbb29d9ea96b 116 return "image/png";
azsymaivan 0:fbb29d9ea96b 117 if (strcasecmp(extension,".css")==0)
azsymaivan 0:fbb29d9ea96b 118 return "text/css";
azsymaivan 0:fbb29d9ea96b 119 if (strcasecmp(extension,".gif")==0)
azsymaivan 0:fbb29d9ea96b 120 return "image/gif";
azsymaivan 0:fbb29d9ea96b 121 if (strcasecmp(extension,".jpg")==0 || strcasecmp(extension,".jpeg" )==0)
azsymaivan 0:fbb29d9ea96b 122 return "image/jpeg";
azsymaivan 0:fbb29d9ea96b 123 }
azsymaivan 0:fbb29d9ea96b 124 return "text/plain; charset=iso-8859-1";
azsymaivan 0:fbb29d9ea96b 125 }
azsymaivan 0:fbb29d9ea96b 126
azsymaivan 0:fbb29d9ea96b 127 #endif