Vizic Technologies
/
ListContents_SG2
List File Contents on a microSD card Demo, FAT16/FAT32 - MBED + SmartGPU2 board
main.cpp@0:83fce1a82d67, 2013-07-10 (annotated)
- Committer:
- emmanuelchio
- Date:
- Wed Jul 10 03:34:16 2013 +0000
- Revision:
- 0:83fce1a82d67
- Child:
- 1:dee5e71f05bd
List File Contents of microSD card Demo - MBED + SmartGPU2 board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emmanuelchio | 0:83fce1a82d67 | 1 | /**************************************************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 2 | /*SMARTGPU2 intelligent embedded graphics processor unit |
emmanuelchio | 0:83fce1a82d67 | 3 | those examples are for use the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset |
emmanuelchio | 0:83fce1a82d67 | 4 | Board: |
emmanuelchio | 0:83fce1a82d67 | 5 | http://vizictechnologies.com/#/smart-gpu-2/4577779046 |
emmanuelchio | 0:83fce1a82d67 | 6 | |
emmanuelchio | 0:83fce1a82d67 | 7 | www.vizictechnologies.com |
emmanuelchio | 0:83fce1a82d67 | 8 | Vizic Technologies copyright 2013 */ |
emmanuelchio | 0:83fce1a82d67 | 9 | /**************************************************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 10 | /**************************************************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 11 | |
emmanuelchio | 0:83fce1a82d67 | 12 | /******************************************************** |
emmanuelchio | 0:83fce1a82d67 | 13 | This simple sketch does the next: |
emmanuelchio | 0:83fce1a82d67 | 14 | 1.- list the dirs and files |
emmanuelchio | 0:83fce1a82d67 | 15 | 2.- print the number of dirs and files |
emmanuelchio | 0:83fce1a82d67 | 16 | 3.- print the names while they fit |
emmanuelchio | 0:83fce1a82d67 | 17 | ********************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 18 | |
emmanuelchio | 0:83fce1a82d67 | 19 | #include "mbed.h" |
emmanuelchio | 0:83fce1a82d67 | 20 | #include "SMARTGPU2.h" |
emmanuelchio | 0:83fce1a82d67 | 21 | |
emmanuelchio | 0:83fce1a82d67 | 22 | SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd" |
emmanuelchio | 0:83fce1a82d67 | 23 | |
emmanuelchio | 0:83fce1a82d67 | 24 | FILERESULT res; //create the variable that will store all SMARTGPU2 commands responses |
emmanuelchio | 0:83fce1a82d67 | 25 | |
emmanuelchio | 0:83fce1a82d67 | 26 | unsigned int row=10; |
emmanuelchio | 0:83fce1a82d67 | 27 | |
emmanuelchio | 0:83fce1a82d67 | 28 | //function that loops forever on error |
emmanuelchio | 0:83fce1a82d67 | 29 | void die(unsigned char response){ //if the response is different than OK, print and loop forever |
emmanuelchio | 0:83fce1a82d67 | 30 | NUMBEROFBYTES charsPrint; |
emmanuelchio | 0:83fce1a82d67 | 31 | if(response!=F_OK){ |
emmanuelchio | 0:83fce1a82d67 | 32 | lcd.string(10,row,319,239,"Error on microSD... forever loop@",&charsPrint); |
emmanuelchio | 0:83fce1a82d67 | 33 | while(1); |
emmanuelchio | 0:83fce1a82d67 | 34 | } |
emmanuelchio | 0:83fce1a82d67 | 35 | } |
emmanuelchio | 0:83fce1a82d67 | 36 | |
emmanuelchio | 0:83fce1a82d67 | 37 | /***************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 38 | /***************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 39 | void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board |
emmanuelchio | 0:83fce1a82d67 | 40 | lcd.reset(); //physically reset SMARTGPU2 |
emmanuelchio | 0:83fce1a82d67 | 41 | lcd.start(); //initialize the SMARTGPU2 processor |
emmanuelchio | 0:83fce1a82d67 | 42 | } |
emmanuelchio | 0:83fce1a82d67 | 43 | |
emmanuelchio | 0:83fce1a82d67 | 44 | /***************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 45 | /***************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 46 | /***************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 47 | /***************************************************/ |
emmanuelchio | 0:83fce1a82d67 | 48 | int main() { |
emmanuelchio | 0:83fce1a82d67 | 49 | char buffer[100]={0}; |
emmanuelchio | 0:83fce1a82d67 | 50 | unsigned int dirs=0, files=0, i=0; |
emmanuelchio | 0:83fce1a82d67 | 51 | NUMBEROFBYTES charsPrinted; |
emmanuelchio | 0:83fce1a82d67 | 52 | |
emmanuelchio | 0:83fce1a82d67 | 53 | initializeSmartGPU2(); //Init communication with SmartGPU2 board |
emmanuelchio | 0:83fce1a82d67 | 54 | |
emmanuelchio | 0:83fce1a82d67 | 55 | //strings config |
emmanuelchio | 0:83fce1a82d67 | 56 | lcd.setTextColour(GREEN); |
emmanuelchio | 0:83fce1a82d67 | 57 | lcd.setTextSize(FONT1); |
emmanuelchio | 0:83fce1a82d67 | 58 | |
emmanuelchio | 0:83fce1a82d67 | 59 | lcd.string(10,row,319,239,"List dirs, files + print names demo!",&charsPrinted); row+=20; |
emmanuelchio | 0:83fce1a82d67 | 60 | lcd.setTextSize(FONT0); |
emmanuelchio | 0:83fce1a82d67 | 61 | lcd.string(10,row,319,239,"List Dirs and Files...",&charsPrinted); row+=15; |
emmanuelchio | 0:83fce1a82d67 | 62 | res=lcd.SDFgetList(&dirs,&files); //obtain dirs and files |
emmanuelchio | 0:83fce1a82d67 | 63 | die(res); |
emmanuelchio | 0:83fce1a82d67 | 64 | lcd.string(10,row,319,239,"Dirs:",&charsPrinted); |
emmanuelchio | 0:83fce1a82d67 | 65 | lcd.printNumber(40,row,dirs); //print the obtained directories |
emmanuelchio | 0:83fce1a82d67 | 66 | lcd.string(70,row,319,239,"Files:",&charsPrinted); |
emmanuelchio | 0:83fce1a82d67 | 67 | lcd.printNumber(105,row,files); //print the obtained files |
emmanuelchio | 0:83fce1a82d67 | 68 | row+=15; |
emmanuelchio | 0:83fce1a82d67 | 69 | |
emmanuelchio | 0:83fce1a82d67 | 70 | //print dir names |
emmanuelchio | 0:83fce1a82d67 | 71 | lcd.string(10,row,319,239,"Dir Names--------------------",&charsPrinted); row+=12; |
emmanuelchio | 0:83fce1a82d67 | 72 | for(i=0;i<dirs;i++){ |
emmanuelchio | 0:83fce1a82d67 | 73 | res=lcd.SDFgetDirName(i,buffer); //get Dir number i name in buffer |
emmanuelchio | 0:83fce1a82d67 | 74 | die(res); |
emmanuelchio | 0:83fce1a82d67 | 75 | lcd.string(10,row,319,239,buffer,&charsPrinted); row+=12; //print the name if fit |
emmanuelchio | 0:83fce1a82d67 | 76 | } |
emmanuelchio | 0:83fce1a82d67 | 77 | row+=10; |
emmanuelchio | 0:83fce1a82d67 | 78 | //print file names |
emmanuelchio | 0:83fce1a82d67 | 79 | lcd.string(10,row,319,239,"File Names--------------------",&charsPrinted); row+=12; |
emmanuelchio | 0:83fce1a82d67 | 80 | for(i=0;i<files;i++){ |
emmanuelchio | 0:83fce1a82d67 | 81 | res=lcd.SDFgetFileName(i,buffer); //get Dir number i name in buffer |
emmanuelchio | 0:83fce1a82d67 | 82 | die(res); |
emmanuelchio | 0:83fce1a82d67 | 83 | lcd.string(10,row,319,239,buffer,&charsPrinted); row+=12; //print the name if fit |
emmanuelchio | 0:83fce1a82d67 | 84 | } |
emmanuelchio | 0:83fce1a82d67 | 85 | |
emmanuelchio | 0:83fce1a82d67 | 86 | while(1); //loop forever |
emmanuelchio | 0:83fce1a82d67 | 87 | } |