![](/media/cache/profiles/45ab12afa05e563bb484781693dffc87.50x50_q85.jpg)
modify for C210 webcam and Startboard Orange.
Dependencies: TextLCD USBHost mbed
Fork of USBHostC270_example by
Norimasa Okamoto さんの http://mbed.org/users/va009039/code/USBHostC270_example/ を C210 webcam と StarBoard Orange での SD カード保存用に変更。
Diff: main.cpp
- Revision:
- 12:c827ed52021d
- Parent:
- 11:944c66b16508
diff -r 944c66b16508 -r c827ed52021d main.cpp --- a/main.cpp Tue Mar 19 12:21:08 2013 +0000 +++ b/main.cpp Tue Mar 19 14:16:25 2013 +0000 @@ -1,16 +1,26 @@ -// #include "USBHostMSD.h" +#define MSDFILESYSTEM 0 // 0:SDFileSystem, 1:USBHostMSD + +#if MSDFILESYSTEM +#include "USBHostMSD.h" +#else +#include "SDFileSystem.h" +#endif #include "USBHostC270.h" -#include "SDFileSystem.h" Serial pc(USBTX, USBRX); BusOut leds(LED1, LED2, LED3); +#if !MSDFILESYSTEM SDFileSystem sd(p5, p6, p7, p8, "sd"); +#endif + +#include "TextLCD.h" +TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 int main() { pc.baud(921600); - - // USBHostMSD* msd = new USBHostMSD("usb"); // USB flash drive - +#if MSDFILESYSTEM + USBHostMSD* msd = new USBHostMSD("usb"); // USB flash drive +#endif USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _5FPS); // Logitech C270 while(!cam->connect()) { Thread::wait(500); @@ -26,16 +36,27 @@ printf("start\r\n"); int r = cam->readJPEG(buf, sizeof(buf)); char path[32]; - // snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20); +#if MSDFILESYSTEM + snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20); +#else snprintf(path, sizeof(path), "/sd/image%02d.jpg", shot % 20); +#endif + lcd.locate( 0, 0 ); + lcd.printf( path ); printf("%d %s %d bytes\r\n", shot, path, r); - // if (msd->connected()) +#if MSDFILESYSTEM + if (msd->connected()) +#endif { FILE* fp = fopen(path, "wb"); if (fp) { + lcd.locate( 0, 1 ); + lcd.printf( "writing." ); printf("write\r\n"); fwrite(buf, r, 1, fp); fclose(fp); + lcd.locate( 0, 1 ); + lcd.printf( "finish. " ); } shot++; leds = shot % 8; @@ -43,7 +64,9 @@ interval_t.reset(); printf("end\r\n"); } - // if (!msd->connected()) msd->connect(); +#if MSDFILESYSTEM + if (!msd->connected()) msd->connect(); +#endif cam->poll(); } }