![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
LogitechC270 webcam class driver alpha version
Fork of USBHostMSD_HelloWorld by
main.cpp@12:ea4badc78215, 2013-03-20 (annotated)
- Committer:
- va009039
- Date:
- Wed Mar 20 14:28:39 2013 +0000
- Revision:
- 12:ea4badc78215
- Parent:
- 11:6a8eef89eb22
support detach
Who changed what in which revision?
User | Revision | Line number | New 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 |
va009039 | 10:387c49b2fc7e | 11 | USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _5FPS); // 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()) { |
va009039 | 10:387c49b2fc7e | 25 | FILE* fp = fopen(path, "wb"); |
va009039 | 10:387c49b2fc7e | 26 | if (fp) { |
va009039 | 10:387c49b2fc7e | 27 | fwrite(buf, r, 1, fp); |
va009039 | 10:387c49b2fc7e | 28 | fclose(fp); |
va009039 | 10:387c49b2fc7e | 29 | } |
va009039 | 10:387c49b2fc7e | 30 | shot++; |
va009039 | 10:387c49b2fc7e | 31 | leds = shot % 8; |
va009039 | 10:387c49b2fc7e | 32 | } |
va009039 | 10:387c49b2fc7e | 33 | interval_t.reset(); |
va009039 | 10:387c49b2fc7e | 34 | } |
va009039 | 10:387c49b2fc7e | 35 | if (!msd->connected()) { |
va009039 | 10:387c49b2fc7e | 36 | msd->connect(); |
va009039 | 11:6a8eef89eb22 | 37 | Thread::wait(500); |
va009039 | 10:387c49b2fc7e | 38 | } |
va009039 | 11:6a8eef89eb22 | 39 | if (!cam->connected()) { |
va009039 | 11:6a8eef89eb22 | 40 | cam->connect(); |
va009039 | 11:6a8eef89eb22 | 41 | Thread::wait(500); |
va009039 | 11:6a8eef89eb22 | 42 | } else { |
va009039 | 11:6a8eef89eb22 | 43 | cam->poll(); |
va009039 | 11:6a8eef89eb22 | 44 | } |
va009039 | 10:387c49b2fc7e | 45 | } |
va009039 | 10:387c49b2fc7e | 46 | } |