LogitechC270 webcam class driver alpha version

Dependencies:   USBHost mbed

Fork of USBHostMSD_HelloWorld by Samuel Mokrani

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "USBHostMSD.h"
00002 #include "USBHostC270.h"
00003 
00004 Serial pc(USBTX, USBRX);
00005 BusOut leds(LED1, LED2, LED3);
00006 
00007 int main() {
00008     pc.baud(921600);
00009 
00010     USBHostMSD* msd = new USBHostMSD("usb"); // USB flash drive
00011     USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _5FPS); // Logitech C270
00012 
00013     uint8_t buf[1024*3];
00014     Timer interval_t;
00015     interval_t.reset();
00016     interval_t.start();
00017     int shot = 0;
00018     while(1) {
00019         if (interval_t.read() > 10 && cam->connected()) {
00020             int r = cam->readJPEG(buf, sizeof(buf));
00021             char path[32];
00022             snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20);
00023             printf("%d %s %d bytes\n", shot, path, r);
00024             if (msd->connected()) {
00025                 FILE* fp = fopen(path, "wb");
00026                 if (fp) {
00027                     fwrite(buf, r, 1, fp);
00028                     fclose(fp);
00029                 }
00030                 shot++;
00031                 leds = shot % 8;
00032             }
00033             interval_t.reset();
00034         }
00035         if (!msd->connected()) {
00036             msd->connect();
00037             Thread::wait(500);
00038         }
00039         if (!cam->connected()) {
00040             cam->connect();
00041             Thread::wait(500);
00042         } else {
00043             cam->poll();
00044         }
00045     }
00046 }