Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystemCpp
usbMemory.cpp
- Committer:
- suupen
- Date:
- 2016-12-12
- Revision:
- 7:a6b950d25e29
- Parent:
- 6:d407fe3e0c97
- Child:
- 8:6e23bf867e38
File content as of revision 7:a6b950d25e29:
#include "mbed.h"
#include "MSCFileSystem.h"
//#include <stat.h>
#include "string.h"
/*
**************************************************************************************************************
* PRINT CONFIGURATION
**************************************************************************************************************
*/
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(...) printf(__VA_ARGS__)
#else
#define DEBUG_PRINT(...)
#endif // DEBUG
#define FSNAME "msc"
MSCFileSystem msc(FSNAME);
FILE *fp;
char fileName[20];
char buffer[50];
void usbMemoryInitialize(void)
{
msc.disk_initialize();
}
/** File check
* @para fileNumber : This number get filename 0,1:first 2: second ...
* @para *fileName : get filename
* @para *fileNumberMax : .prn file number
* @return
* false: non file true: file exists
*/
int32_t fileDetect(int32_t fileNumber, char *fileName, int32_t *fileNumberMax)
{
uint32_t numMax = 0;
int32_t ans = false;
DIR *d;
struct dirent *p;
d = opendir("/" FSNAME);
// directory check
if ( d != NULL ) {
while ( (p = readdir(d)) != NULL ) {
if(NULL != strstr(p->d_name, ".prn")) {
numMax++;
if(numMax == fileNumber) {
strcpy(fileName, p->d_name);
}
DEBUG_PRINT("detect = %s\n",fileName);
ans = true;
}
}
*fileNumberMax = numMax;
}
return ans;
}
int32_t fileSelect(char *fileName, uint32_t *numberLine)
{
uint32_t numMax = 0;
int32_t ans = false;
DIR *d;
struct dirent *p;
d = opendir("/" FSNAME);
// file check
sprintf(buffer,"/msc/%s",fileName);
fp = fopen( buffer, "r");
if ( fp != NULL ) {
char buf[256];
while ( NULL != fgets(buf, sizeof(buf), fp) ) {
DEBUG_PRINT("%s", buf);
numMax++;
}
*numberLine = numMax;
fclose(fp);
ans = true;
} else {
// Don't file open
// nothing
}
return ans;
}
uint32_t fileOneLineRead(char *fileName, char *data, uint32_t dataNumber, uint32_t numberLine)
{
// static FILE *fp;
int32_t ans = false;
#define bufferNumber 100
char buffer[bufferNumber];
sprintf(buffer,"/msc/%s",fileName);
fp = fopen( buffer, "r");
if ( fp != NULL ) {
for(uint32_t i = 0; i < numberLine; i++) {
fgets(buffer, sizeof(buffer), fp);
}
if(NULL != fgets(data, dataNumber, fp)) {
DEBUG_PRINT("line = %s\r\n", data);
fclose(fp);
ans = true;
} else {
// nothing
}
} else {
// Don't file open
// nothing
}
return ans;
}