button
Dependencies: BMI160 SDFileSystem USBDevice max32630fthr
Fork of MPSMAX by
files.cpp
00001 #include "files.h" 00002 00003 #if (MBED_MAJOR_VERSION == 2) 00004 #include "SDFileSystem.h" 00005 #elif (MBED_MAJOR_VERSION == 5) 00006 #include "SDBlockDevice.h" 00007 #include "FATFileSystem.h" 00008 #endif 00009 00010 #if (MBED_MAJOR_VERSION == 2) 00011 SDFileSystem sd(D11, D12, D13, D10, "fs"); // do,di,clk,cs 00012 #elif (MBED_MAJOR_VERSION == 5) 00013 //SDBlockDevice sd(D11, D12, D13, D10, 8000000); 00014 SDBlockDevice sd(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS, 8000000); // For MAX32630FTHR 00015 FATFileSystem fs("fs"); 00016 #endif 00017 00018 00019 int totaFunctionlFiles = 0; 00020 int functionFileNumber = 1; 00021 int functionActive = 0; 00022 extern int functionPosition = 0; 00023 Function ffunc; 00024 00025 int initSDCard(){ 00026 #if (MBED_MAJOR_VERSION == 5) 00027 /* Init SD CARD reader */ 00028 sd.init(); 00029 fs.mount(&sd); 00030 #endif 00031 FILE* fp = fopen("/fs/mydata.txt", "a"); 00032 if (fp != 0) { 00033 pc.printf("writing something\n\r\n"); 00034 fprintf(fp,"writing something\n\r\n"); 00035 } else { 00036 pc.printf("ERROR\r\n"); 00037 } 00038 fclose(fp); 00039 return 0; 00040 } 00041 00042 int readFileNames(){ 00043 DIR *d; 00044 struct dirent *p; 00045 00046 d = opendir("/fs/functions"); 00047 if (d != NULL) { 00048 while ((p = readdir(d)) != NULL) { 00049 // printf(" - %s\n", p->d_name); 00050 totaFunctionlFiles++; 00051 } 00052 } else { 00053 printf("Could not open directory!\n"); 00054 } 00055 closedir(d); 00056 printf("Total files = %d\n", totaFunctionlFiles); 00057 return 0; 00058 } 00059 00060 int navFunctionFiles(int direction){ 00061 00062 if(direction == DIR_UP){ 00063 if(functionFileNumber < totaFunctionlFiles){ 00064 functionFileNumber++; 00065 }else{ 00066 functionFileNumber = 1; 00067 } 00068 printf("UP: %d\n", functionFileNumber); 00069 }else{ 00070 if(functionFileNumber > 1){ 00071 functionFileNumber--; 00072 }else{ 00073 functionFileNumber = totaFunctionlFiles; 00074 } 00075 printf("DOWN: %d\n", functionFileNumber); 00076 } 00077 return 0; 00078 } 00079 00080 int openFunctionFile(int inpFile){ 00081 char fileLoc [40]; 00082 sprintf (fileLoc, "/fs/functions/function%d.txt", inpFile); 00083 printf ("[%s] is location %d file number\n", fileLoc, inpFile); 00084 00085 FILE* fp = fopen(fileLoc, "r"); 00086 ffunc.pos=0; 00087 while (fscanf(fp, "%d,%d", &ffunc.x[ffunc.pos], &ffunc.t[ffunc.pos]) != EOF){ 00088 ffunc.pos++; 00089 } 00090 00091 fclose(fp); 00092 functionActive = 1; 00093 functionPosition = 0; 00094 printFunctionData(); 00095 return 0; 00096 } 00097 00098 void printFunctionData(){ 00099 printf ("total: %d\n", ffunc.pos); 00100 for(int i=0; i<ffunc.pos; i++ ){ 00101 printf ("%d, %d\n", ffunc.x[i], ffunc.t[i]); 00102 } 00103 } 00104
Generated on Wed Jul 13 2022 14:08:26 by 1.7.2