modify for C210 webcam and Startboard Orange.

Dependencies:   TextLCD USBHost mbed

Fork of USBHostC270_example by Norimasa Okamoto

Norimasa Okamoto さんの http://mbed.org/users/va009039/code/USBHostC270_example/ を C210 webcam と StarBoard Orange での SD カード保存用に変更。

main.cpp

Committer:
masato
Date:
2013-03-19
Revision:
11:944c66b16508
Parent:
10:387c49b2fc7e
Child:
12:c827ed52021d

File content as of revision 11:944c66b16508:

// #include "USBHostMSD.h"
#include "USBHostC270.h"
#include "SDFileSystem.h"

Serial pc(USBTX, USBRX);
BusOut leds(LED1, LED2, LED3);
SDFileSystem  sd(p5, p6, p7, p8,  "sd");

int main() {
    pc.baud(921600);

    // USBHostMSD* msd = new USBHostMSD("usb"); // USB flash drive

    USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _5FPS); // Logitech C270
    while(!cam->connect()) {
        Thread::wait(500);
    }

    uint8_t buf[1024*3];
    Timer interval_t;
    interval_t.reset();
    interval_t.start();
    int shot = 0;
    while(1) {
        if (interval_t.read_ms() > 2000) {
            printf("start\r\n");
            int r = cam->readJPEG(buf, sizeof(buf));
            char path[32];
            // snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20);
            snprintf(path, sizeof(path), "/sd/image%02d.jpg", shot % 20);
            printf("%d %s %d bytes\r\n", shot, path, r);
            // if (msd->connected()) 
            {
                FILE* fp = fopen(path, "wb");
                if (fp) {
                    printf("write\r\n");
                    fwrite(buf, r, 1, fp);
                    fclose(fp);
                }
                shot++;
                leds = shot % 8;
            }
            interval_t.reset();
            printf("end\r\n");
        }
        // if (!msd->connected()) msd->connect();
        cam->poll();    
    }
}