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