RAMDisk example for the USBFileSystem
Dependencies: mbed USBFileSystem
Fork of USBFileSystem_RAMDISK_HelloWorld by
main.cpp
- Committer:
- Sissors
- Date:
- 2015-01-18
- Revision:
- 5:9261d5bd633b
- Parent:
- 3:fc1bfb25b644
File content as of revision 5:9261d5bd633b:
/* This program is based on Richard Green's RAM_DISK program for the KL25Z So all hail the Hypnotoad!!!! (And Richard Green, but only after the Hypnotoad) */ #include "mbed.h" #include "USBMSD_Ram.h" DigitalOut myled(LED1); USBMSD_Ram ram; void usbCallback(bool available) { if (available) { FILE *fp = fopen("/USB/IN.txt", "r"); char buffer[100]; fgets (buffer, 100, fp); printf("%s\r\n", buffer); fclose(fp); } } int main() { ram.attachUSB(&usbCallback); wait(0.1); printf("Hello World!\r\n"); //Connect USB ram.connect(); FILE* fp; char buffer[101]; printf("Type your text here! (100 max length)\n"); while(1) { gets(buffer); myled = !myled; //Open file for write, keep trying until we succeed //This is needed because if USB happens to be writing it will fail while(1) { fp = fopen("/USB/OUT.txt", "w"); if (fp != NULL) break; } fprintf(fp, buffer); fclose(fp); } }