Reads the text file on USB in Host mode and displays on the LCD.
Dependencies: C12832_lcd USBHost mbed
Fork of USBHostMSD_HelloWorld by
Revision 9:27174ecbb331, committed 2014-03-13
- Comitter:
- bhakti08
- Date:
- Thu Mar 13 01:43:01 2014 +0000
- Parent:
- 8:758190c6c455
- Commit message:
- Reading a text file on USB and displaying on LCD
Changed in this revision
C12832_lcd.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 758190c6c455 -r 27174ecbb331 C12832_lcd.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Thu Mar 13 01:43:01 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dreschpe/code/C12832_lcd/#468cdccff7af
diff -r 758190c6c455 -r 27174ecbb331 main.cpp --- a/main.cpp Thu Mar 14 14:23:42 2013 +0000 +++ b/main.cpp Thu Mar 13 01:43:01 2014 +0000 @@ -1,48 +1,79 @@ #include "mbed.h" #include "USBHostMSD.h" +#include "C12832_lcd.h" +#include <stdlib.h> DigitalOut led(LED1); +DigitalOut file_open(LED2); +DigitalOut file_write(LED3); +C12832_LCD lcd; +Serial pc(USBTX,USBRX); void msd_task(void const *) { - + lcd.cls(); USBHostMSD msd("usb"); - int i = 0; - - while(1) { + char data[100]; + char data_write; + lcd.cls(); // try to connect a MSD device while(!msd.connect()) { Thread::wait(500); } + lcd.cls(); + lcd.printf("Device Detected!\n"); + wait (1); + lcd.cls(); + lcd.locate(0,0); // in a loop, append a file // if the device is disconnected, we try to connect it again - while(1) { // append a file - FILE * fp = fopen("/usb/test1.txt", "a"); + FILE * fp = fopen("/usb/test1.txt", "r"); + //FILE *fp_out = fopen("/usb/out_file.txt","w"); if (fp != NULL) { - fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++); - printf("Goodbye World!\r\n"); + file_open = 1; + lcd.cls(); + while (!feof(fp)) + { + fscanf(fp,"%s",data); + lcd.printf("%s",data); + + } + wait(2); fclose(fp); } else { - printf("FILE == NULL\r\n"); + lcd.cls(); + lcd.printf("File not found\n"); } + /*if(fp_out != NULL) + { + + if (pc.readable()) + { + file_write = 1; + pc.scanf("%c",&data_write); + fprintf(fp_out,"%c ",data_write); + + } + }*/ + Thread::wait(500); // if device disconnected, try to connect again if (!msd.connected()) - break; - } + lcd.printf("Connect device"); - } + } int main() { Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); + pc.baud(9600); while(1) { led=!led; Thread::wait(500);