testing n-Bed with a Logitech C270 camera

Dependencies:   USBHost mbed

Fork of USBHostC270_example by Norimasa Okamoto

Committer:
chalikias
Date:
Mon Apr 27 19:54:05 2015 +0000
Revision:
13:237a886b0b78
Parent:
11:6a8eef89eb22
Child:
14:449f809d07eb
tested

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 10:387c49b2fc7e 1 #include "USBHostMSD.h"
va009039 10:387c49b2fc7e 2 #include "USBHostC270.h"
va009039 10:387c49b2fc7e 3
va009039 10:387c49b2fc7e 4 Serial pc(USBTX, USBRX);
va009039 10:387c49b2fc7e 5 BusOut leds(LED1, LED2, LED3);
va009039 10:387c49b2fc7e 6
va009039 10:387c49b2fc7e 7 int main() {
va009039 10:387c49b2fc7e 8 pc.baud(921600);
va009039 10:387c49b2fc7e 9
va009039 10:387c49b2fc7e 10 USBHostMSD* msd = new USBHostMSD("usb"); // USB flash drive
chalikias 13:237a886b0b78 11 USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_800x600, _1FPS); // Logitech C270
va009039 10:387c49b2fc7e 12
va009039 10:387c49b2fc7e 13 uint8_t buf[1024*3];
va009039 10:387c49b2fc7e 14 Timer interval_t;
va009039 10:387c49b2fc7e 15 interval_t.reset();
va009039 10:387c49b2fc7e 16 interval_t.start();
va009039 10:387c49b2fc7e 17 int shot = 0;
va009039 10:387c49b2fc7e 18 while(1) {
va009039 11:6a8eef89eb22 19 if (interval_t.read() > 10 && cam->connected()) {
va009039 10:387c49b2fc7e 20 int r = cam->readJPEG(buf, sizeof(buf));
va009039 10:387c49b2fc7e 21 char path[32];
va009039 10:387c49b2fc7e 22 snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20);
va009039 10:387c49b2fc7e 23 printf("%d %s %d bytes\n", shot, path, r);
va009039 10:387c49b2fc7e 24 if (msd->connected()) {
chalikias 13:237a886b0b78 25 printf("msd connected\n");
va009039 10:387c49b2fc7e 26 FILE* fp = fopen(path, "wb");
va009039 10:387c49b2fc7e 27 if (fp) {
va009039 10:387c49b2fc7e 28 fwrite(buf, r, 1, fp);
va009039 10:387c49b2fc7e 29 fclose(fp);
va009039 10:387c49b2fc7e 30 }
va009039 10:387c49b2fc7e 31 shot++;
va009039 10:387c49b2fc7e 32 leds = shot % 8;
va009039 10:387c49b2fc7e 33 }
chalikias 13:237a886b0b78 34 else {
chalikias 13:237a886b0b78 35 printf("msd NOT connected\n");
chalikias 13:237a886b0b78 36 }
va009039 10:387c49b2fc7e 37 interval_t.reset();
va009039 10:387c49b2fc7e 38 }
va009039 10:387c49b2fc7e 39 if (!msd->connected()) {
va009039 10:387c49b2fc7e 40 msd->connect();
va009039 11:6a8eef89eb22 41 Thread::wait(500);
va009039 10:387c49b2fc7e 42 }
va009039 11:6a8eef89eb22 43 if (!cam->connected()) {
va009039 11:6a8eef89eb22 44 cam->connect();
va009039 11:6a8eef89eb22 45 Thread::wait(500);
va009039 11:6a8eef89eb22 46 } else {
va009039 11:6a8eef89eb22 47 cam->poll();
va009039 11:6a8eef89eb22 48 }
va009039 10:387c49b2fc7e 49 }
va009039 10:387c49b2fc7e 50 }