USBMSD and CDC composite device testing code mixed up from several existing programs/libraries

Dependencies:   USBCDCMSC USBDevice USBFileSystem USBSDFileSystem USBSPIFileSystem mbed

Revision:
4:bbe1bc2eb8fb
Parent:
2:c70070f88944
--- a/main.cpp	Wed Apr 22 04:55:27 2015 +0000
+++ b/main.cpp	Wed Apr 22 16:44:50 2015 +0000
@@ -3,9 +3,14 @@
 #include "USBCDCMSC.h"
 
 DigitalOut myled(LED1);
+DigitalOut erled(LED2);
 
 USBSDFileSystem sd("sd", p5, p6, p7, p8); // the pinout on the mbed testbed board // mosi, miso, sclk, cs
-// P0_9,P0_8,P0_10,P0_7
+//USBSDFileSystem sd("sd", p11, p12, p13, p14); // the pinout on the mbed testbed board // mosi, miso, sclk, cs
+//USBSDFileSystem sd("sd", P0_10, P0_22, P0_11, P0_12); // <<NO ERROR?!
+//p7,p12,p15,p16
+// pin 19,20,22,23
+
 USBCDCMSC pc(&sd,0x1f00, 0x2012, 0x0001);
 
 //#define BLE
@@ -14,6 +19,7 @@
 //Serial pc(USBTX,USBRX); //->USBCDCMSC pc(&sd);
 Serial ble(p9,p10);
 // P0_19,P0_18
+// pin 32,31
 
 //LocalFileSystem local( "local" ); //->USBSDFileSystem sd("sd", p5, p6, p7, p8); // the pinout on the mbed testbed board // mosi, miso, sclk, cs
 //#define     SOURCE_FILE         "/local/_bin"
@@ -21,7 +27,7 @@
 
 int file_size( FILE *fp );
 enum XMODEM_CONST{
-SOH = (0x01), 
+SOH = (0x01),
 STX = (0x02),
 EOT = (0x04),
 ACK = (0x06),
@@ -38,7 +44,7 @@
     FILE* fp;
     ble.baud(57600);
     int crc=0x00;
-    
+
     if ( NULL == (fp = fopen( SOURCE_FILE, "rb" )) ) {
         exit(1);
 //        return ( ERROR_AT_FILE_OPEN );
@@ -109,56 +115,75 @@
 {
     FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
     if(fp == NULL) {
-        printf("Could not open file for write\n\r");
-    } else
-    {
-      fprintf(fp, "[%d]Hello fun SD Card World!\n\r", i);
-      printf("appending: '[%d]Hello fun SD Card World!'\n\r", i);
-      fclose(fp); 
+        erled = 0;
+        pc.printf("Could not open file for write\n\r");
+    } else {
+        erled = 1;
+        fprintf(fp, "[%d]Hello fun SD Card World!\n\n\r", i);
+        pc.printf("appending: '[%d]Hello fun SD Card World!'\n\r", i);
+        //fclose(fp);
     }
+    fclose(fp);
 }
 
-int main() 
+int main()
 {
-    /* pc.printf() and/or pc. getc() is not working. CDC packet dissappears*/
-//    sd.connect (false);
-    sd.usbMode (1); // allow fopen/fprintf when connected with USB-drive.
-    pc.printf("Hello World!\n\n");   
-    
-    pc.printf("now a USB drive should appear on your PC\n");
-    for(int i=0;i<60;i++){
+    sd.disconnect();
+    mkdir("/sd/mydir", 0777);
+//    mylog (100);
+    FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
+    for(int i=0; i<5; i++) {
+        myled = 1;
+        erled = 0;
+        wait_ms (500);
+        if(fp == NULL) {
+            pc.printf("Could not open file for write\n\r");
+        } else {
+            fprintf(fp, "[%d]Hello fun SD Card World!\n\n\r", i);
+            pc.printf("appending: '[%d]Hello fun SD Card World!'\n\r", i);
+            //fclose(fp);
+        }
+        myled = 0;
+        erled = 1;
+        wait_ms (500);
+    }
+    fclose(fp);
+    sd.usbMode(1); // allow fopen/fprintf when connected with USB-drive.
+    sd.connect();
+    /* pc.printf() and/or pc.getc() is not working. CDC packet dissappears*/
+    for(int i=0; i<5; i++) {
         myled = 1;
         wait_ms (500);
         myled = 0;
         wait_ms (500);
     }
-       
+    pc.printf("Hello World!\n\n");
+
+    pc.printf("now a USB drive should appear on your PC\n");
     pc.printf("create directory and append to log file\n");
-//    mkdir("/sd/mydir", 0777);
-    mylog (0);    
 
-    for(int i=0;i<60;i++){
+    pc.printf("Entering loop of 1 min cycle time\n\r");
+//    sd.usbMode (1); // allow fopen/fprintf when connected with USB-drive.
+//    sd.connect(false);
+
+    int i = 1;
+    int recieve=0 ;
+    while(true) {
         myled = 1;
         wait_ms (500);
         myled = 0;
         wait_ms (500);
-        mylog (i);
-    }
-//    sd.usbMode (0); // allow fopen/fprintf when connected with USB-drive.
-//    sd.disconnect ();
-
-    pc.printf("Entering loop of 1 min cycle time\n");
-    sd.connect(true);
-    int i = 1;
-    int recieve=0 ;
-    while(true) {
-        myled = 0;
-        recieve=pc.getc();
-        if(recieve != NULL){
-            pc.putc('+');
-        }
-        myled = 1;
-        wait_ms(20);
+        /*
+                myled = 0;
+                recieve=pc._getc();
+                if(recieve != NULL){
+                    pc._putc(recieve+1);
+                }else{
+                    pc._putc('+');
+                }
+                myled = 1;
+                wait_us(200);
+        */
     }
     return 0;
 }