supported GR-PEACH original: http://developer.mbed.org/users/va009039/code/USBHostC270_example/ The function of Isochronous has moved to USBHost_AddIso library.

Dependencies:   USBHost_custom_Addiso

Fork of USBHostC270_example_GR-PEACH by GR-PEACH_producer_meeting

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "FATFileSystem.h"
00002 #include "USBHostMSD.h"
00003 #include "USBHostC270.h"
00004 
00005 #if defined(TARGET_RZ_A1H)
00006 #include "usb_host_setting.h"
00007 #else
00008 #define USB_HOST_CH     0
00009 #endif
00010 
00011 #if (USB_HOST_CH == 1) //Audio Camera Shield USB1
00012 DigitalOut usb1en(P3_8);
00013 #endif
00014 
00015 Serial pc(USBTX, USBRX);
00016 BusOut leds(LED1, LED2, LED3);
00017 
00018 static uint8_t buf[1024*10];
00019 
00020 int main() {
00021     pc.baud(921600);
00022 
00023     
00024 #if (USB_HOST_CH == 1) //Audio Shield USB1
00025     //Audio Shield USB1 enable
00026     usb1en = 1;        //Outputs high level
00027     Thread::wait(5);
00028     usb1en = 0;        //Outputs low level
00029 #endif
00030 
00031      // USB flash drive
00032     FATFileSystem fs("usb");
00033     USBHostMSD msd;
00034     
00035     while(!msd.connect()) {
00036         Thread::wait(500);
00037     }
00038     fs.mount(&msd);
00039     
00040     USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _5FPS); // Logitech C270
00041 
00042     Timer interval_t;
00043     interval_t.reset();
00044     interval_t.start();
00045     int shot = 0;
00046     while(1) {
00047         if (interval_t.read() > 10 && cam->connected()) {
00048             int r = cam->readJPEG(buf, sizeof(buf));
00049             char path[32];
00050             snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20);
00051             printf("%d %s %d bytes\n", shot, path, r);
00052             if (msd.connected()) {
00053                 FILE* fp = fopen(path, "wb");
00054                 if (fp) {
00055                     fwrite(buf, r, 1, fp);
00056                     fclose(fp);
00057                 }
00058                 shot++;
00059                 leds = shot % 8;
00060             }
00061             interval_t.reset();
00062         }
00063         // If USB flash disk is unplugged, wait until USB is re-plugged
00064         if (!msd.connected()) {
00065             while(!msd.connect())
00066             {
00067                 Thread::wait(500);
00068             }
00069             fs.mount(&msd);
00070         }
00071         // If Logitech C270 is unplugged, try to re-plug it
00072         if (!cam->connected()) {
00073             cam->connect();
00074             Thread::wait(500);
00075         } else {
00076             cam->poll();
00077         }
00078     }
00079 }