Acquire Sensor data and email
Dependencies: C12832_lcd EthernetInterface LM75B NTPClient SimpleSMTPClient TextLCD USBHost mbed
Fork of USBHost-MSD_HelloWorld by
main.cpp@9:3ca15106a7d1, 2013-08-13 (annotated)
- Committer:
- avnisha
- Date:
- Tue Aug 13 06:11:51 2013 +0000
- Revision:
- 9:3ca15106a7d1
- Parent:
- 4:f8a5c8aa895a
- Child:
- 10:0902b3dc4d96
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:0d68fe822228 | 1 | #include "mbed.h" |
samux | 0:0d68fe822228 | 2 | #include "USBHostMSD.h" |
samux | 0:0d68fe822228 | 3 | |
samux | 0:0d68fe822228 | 4 | DigitalOut led(LED1); |
samux | 0:0d68fe822228 | 5 | |
samux | 0:0d68fe822228 | 6 | void msd_task(void const *) { |
samux | 0:0d68fe822228 | 7 | |
samux | 0:0d68fe822228 | 8 | USBHostMSD msd("usb"); |
samux | 0:0d68fe822228 | 9 | int i = 0; |
samux | 0:0d68fe822228 | 10 | |
samux | 0:0d68fe822228 | 11 | while(1) { |
samux | 0:0d68fe822228 | 12 | |
samux | 1:473f339c54c1 | 13 | // try to connect a MSD device |
samux | 1:473f339c54c1 | 14 | while(!msd.connect()) { |
samux | 1:473f339c54c1 | 15 | Thread::wait(500); |
avnisha | 9:3ca15106a7d1 | 16 | printf("waiting\n"); |
samux | 1:473f339c54c1 | 17 | } |
samux | 1:473f339c54c1 | 18 | |
samux | 4:f8a5c8aa895a | 19 | // in a loop, append a file |
samux | 4:f8a5c8aa895a | 20 | // if the device is disconnected, we try to connect it again |
samux | 1:473f339c54c1 | 21 | while(1) { |
samux | 1:473f339c54c1 | 22 | |
samux | 4:f8a5c8aa895a | 23 | // append a file |
samux | 1:473f339c54c1 | 24 | FILE * fp = fopen("/usb/test1.txt", "a"); |
samux | 1:473f339c54c1 | 25 | |
samux | 1:473f339c54c1 | 26 | if (fp != NULL) { |
samux | 1:473f339c54c1 | 27 | fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++); |
samux | 1:473f339c54c1 | 28 | printf("Goodbye World!\r\n"); |
samux | 1:473f339c54c1 | 29 | fclose(fp); |
samux | 1:473f339c54c1 | 30 | } else { |
samux | 1:473f339c54c1 | 31 | printf("FILE == NULL\r\n"); |
samux | 1:473f339c54c1 | 32 | } |
samux | 1:473f339c54c1 | 33 | |
samux | 0:0d68fe822228 | 34 | Thread::wait(500); |
samux | 0:0d68fe822228 | 35 | |
samux | 1:473f339c54c1 | 36 | // if device disconnected, try to connect again |
samux | 1:473f339c54c1 | 37 | if (!msd.connected()) |
samux | 1:473f339c54c1 | 38 | break; |
samux | 0:0d68fe822228 | 39 | } |
samux | 1:473f339c54c1 | 40 | |
samux | 0:0d68fe822228 | 41 | } |
samux | 0:0d68fe822228 | 42 | } |
samux | 0:0d68fe822228 | 43 | |
samux | 0:0d68fe822228 | 44 | |
samux | 0:0d68fe822228 | 45 | int main() { |
samux | 2:3e3df7a79050 | 46 | Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); |
samux | 0:0d68fe822228 | 47 | while(1) { |
samux | 0:0d68fe822228 | 48 | led=!led; |
samux | 0:0d68fe822228 | 49 | Thread::wait(500); |
samux | 0:0d68fe822228 | 50 | } |
samux | 0:0d68fe822228 | 51 | } |