Reads the text file on USB in Host mode and displays on the LCD.

Dependencies:   C12832_lcd USBHost mbed

Fork of USBHostMSD_HelloWorld by Samuel Mokrani

Revision:
9:27174ecbb331
Parent:
4:f8a5c8aa895a
--- 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);