This program is for transferring all contents of SD card to any flash drive like pen drive. After importing this program, you will see 3 FATFileSystem libraries, one in main folder, one in SDFileSystem folder and one in USBHost folder. Delete two libraries, which are in SDFileSystem folder and USBHost folder. But don't delete the FATFileSystem library, which are in main folder.

Dependencies:   FATFileSystem SDFileSystem TextLCD USBHost mbed

Files at this revision

API Documentation at this revision

Comitter:
vinit
Date:
Sun Jun 30 22:51:00 2013 +0000
Commit message:
This Program is for transferring all contents of SD card to any FLASH drive.

Changed in this revision

FATFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
USBHost.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 5838d8c4432a FATFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FATFileSystem.lib	Sun Jun 30 22:51:00 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/va009039/code/FATFileSystem/#86638c0f65b0
diff -r 000000000000 -r 5838d8c4432a SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sun Jun 30 22:51:00 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
diff -r 000000000000 -r 5838d8c4432a TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sun Jun 30 22:51:00 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/wim/code/TextLCD/#e0da005a777f
diff -r 000000000000 -r 5838d8c4432a USBHost.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHost.lib	Sun Jun 30 22:51:00 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/USBHost/#7671b6a8c363
diff -r 000000000000 -r 5838d8c4432a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jun 30 22:51:00 2013 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "USBHostMSD.h"
+#include "TextLCD.h"
+#include "SDFileSystem.h"
+
+DigitalOut led(LED1);
+
+TextLCD lcd(p19, p20, p27, p28, p29, p30, TextLCD::LCD20x2); // rs, e, d4-d7
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+//USBHostMSD msd("usb");
+
+void listdir(void);
+void FileCopy(char *, char *);
+void copyallusb(void);
+
+void listdir(void) {
+    DIR *d;
+    struct dirent *p;
+
+    d = opendir("/sd");
+    if (d != NULL) {
+        while ((p = readdir(d)) != NULL) {
+            lcd.cls();
+            lcd.printf(" - %s\r\n", p->d_name);
+        }
+    } else {
+        lcd.cls();
+        lcd.printf("opening failed, try again\n");
+    }
+    closedir(d);
+}
+
+void FileCopy(char *fsrc , char *ftrgt) { 
+    FILE *fs = fopen(fsrc, "rb");
+    if(fs == NULL) {
+        lcd.cls();
+        lcd.printf("couldn't open sd\n");
+    }
+    FILE *ft = fopen(ftrgt, "wb");
+    if(ft == NULL) {
+        lcd.cls();
+        lcd.printf("couldn't open usb\n");
+    }
+    while(1) {
+    int ch = fgetc(fs);
+    if(ch == EOF)
+    break;
+    else
+    fputc(ch, ft);
+    }
+    fclose(fs);
+    fclose(ft); 
+}
+
+void copyallusb(void) {
+    USBHostMSD msd("usb");
+           
+    // try to connect a MSD device
+    while(!msd.connect()) {
+        wait_ms(500);
+        lcd.cls();
+        lcd.printf("connecting to USB");
+     }
+
+    char srstrgt[128];
+    char filesrs[128];
+    char filetrgt[128];
+    DIR *d;
+    struct dirent *p;
+
+    d = opendir("/sd/");
+    if (d != NULL) {
+        lcd.cls();
+        lcd.printf("copy starting\n");
+        while ((p = readdir(d)) != NULL) {
+            sprintf(srstrgt, "%s", p->d_name);
+            sprintf(filesrs, "/sd/%s", srstrgt);
+            sprintf(filetrgt, "/usb/%s", srstrgt);
+            lcd.cls();
+            lcd.printf("copying-\n");
+            lcd.printf("%s\n", srstrgt);
+            FileCopy(filesrs, filetrgt);
+        }
+        lcd.cls();
+        lcd.printf("File copy done!\n");
+    } else {
+        lcd.printf("No File, try again\n");
+    }
+    closedir(d);
+        
+    // if device disconnected, try to connect again
+    //if (!msd.connected())
+    //break;
+}
+
+
+int main() {
+    lcd.cls();
+    lcd.printf("JAI MATA DI!\n");
+    wait(2);
+    copyallusb();
+    while(1) {
+        led=!led;
+        Thread::wait(500);       
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 5838d8c4432a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jun 30 22:51:00 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file