![](/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 カード保存用に変更。
main.cpp@12:c827ed52021d, 2013-03-19 (annotated)
- Committer:
- masato
- Date:
- Tue Mar 19 14:16:25 2013 +0000
- Revision:
- 12:c827ed52021d
- Parent:
- 11:944c66b16508
for C210 and StartBoard Orange
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
masato | 12:c827ed52021d | 1 | #define MSDFILESYSTEM 0 // 0:SDFileSystem, 1:USBHostMSD |
masato | 12:c827ed52021d | 2 | |
masato | 12:c827ed52021d | 3 | #if MSDFILESYSTEM |
masato | 12:c827ed52021d | 4 | #include "USBHostMSD.h" |
masato | 12:c827ed52021d | 5 | #else |
masato | 12:c827ed52021d | 6 | #include "SDFileSystem.h" |
masato | 12:c827ed52021d | 7 | #endif |
va009039 | 10:387c49b2fc7e | 8 | #include "USBHostC270.h" |
va009039 | 10:387c49b2fc7e | 9 | |
va009039 | 10:387c49b2fc7e | 10 | Serial pc(USBTX, USBRX); |
va009039 | 10:387c49b2fc7e | 11 | BusOut leds(LED1, LED2, LED3); |
masato | 12:c827ed52021d | 12 | #if !MSDFILESYSTEM |
masato | 11:944c66b16508 | 13 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
masato | 12:c827ed52021d | 14 | #endif |
masato | 12:c827ed52021d | 15 | |
masato | 12:c827ed52021d | 16 | #include "TextLCD.h" |
masato | 12:c827ed52021d | 17 | TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 |
va009039 | 10:387c49b2fc7e | 18 | |
va009039 | 10:387c49b2fc7e | 19 | int main() { |
va009039 | 10:387c49b2fc7e | 20 | pc.baud(921600); |
masato | 12:c827ed52021d | 21 | #if MSDFILESYSTEM |
masato | 12:c827ed52021d | 22 | USBHostMSD* msd = new USBHostMSD("usb"); // USB flash drive |
masato | 12:c827ed52021d | 23 | #endif |
va009039 | 10:387c49b2fc7e | 24 | USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _5FPS); // Logitech C270 |
va009039 | 10:387c49b2fc7e | 25 | while(!cam->connect()) { |
va009039 | 10:387c49b2fc7e | 26 | Thread::wait(500); |
va009039 | 10:387c49b2fc7e | 27 | } |
va009039 | 10:387c49b2fc7e | 28 | |
va009039 | 10:387c49b2fc7e | 29 | uint8_t buf[1024*3]; |
va009039 | 10:387c49b2fc7e | 30 | Timer interval_t; |
va009039 | 10:387c49b2fc7e | 31 | interval_t.reset(); |
va009039 | 10:387c49b2fc7e | 32 | interval_t.start(); |
va009039 | 10:387c49b2fc7e | 33 | int shot = 0; |
va009039 | 10:387c49b2fc7e | 34 | while(1) { |
masato | 11:944c66b16508 | 35 | if (interval_t.read_ms() > 2000) { |
masato | 11:944c66b16508 | 36 | printf("start\r\n"); |
va009039 | 10:387c49b2fc7e | 37 | int r = cam->readJPEG(buf, sizeof(buf)); |
va009039 | 10:387c49b2fc7e | 38 | char path[32]; |
masato | 12:c827ed52021d | 39 | #if MSDFILESYSTEM |
masato | 12:c827ed52021d | 40 | snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20); |
masato | 12:c827ed52021d | 41 | #else |
masato | 11:944c66b16508 | 42 | snprintf(path, sizeof(path), "/sd/image%02d.jpg", shot % 20); |
masato | 12:c827ed52021d | 43 | #endif |
masato | 12:c827ed52021d | 44 | lcd.locate( 0, 0 ); |
masato | 12:c827ed52021d | 45 | lcd.printf( path ); |
masato | 11:944c66b16508 | 46 | printf("%d %s %d bytes\r\n", shot, path, r); |
masato | 12:c827ed52021d | 47 | #if MSDFILESYSTEM |
masato | 12:c827ed52021d | 48 | if (msd->connected()) |
masato | 12:c827ed52021d | 49 | #endif |
masato | 11:944c66b16508 | 50 | { |
va009039 | 10:387c49b2fc7e | 51 | FILE* fp = fopen(path, "wb"); |
va009039 | 10:387c49b2fc7e | 52 | if (fp) { |
masato | 12:c827ed52021d | 53 | lcd.locate( 0, 1 ); |
masato | 12:c827ed52021d | 54 | lcd.printf( "writing." ); |
masato | 11:944c66b16508 | 55 | printf("write\r\n"); |
va009039 | 10:387c49b2fc7e | 56 | fwrite(buf, r, 1, fp); |
va009039 | 10:387c49b2fc7e | 57 | fclose(fp); |
masato | 12:c827ed52021d | 58 | lcd.locate( 0, 1 ); |
masato | 12:c827ed52021d | 59 | lcd.printf( "finish. " ); |
va009039 | 10:387c49b2fc7e | 60 | } |
va009039 | 10:387c49b2fc7e | 61 | shot++; |
va009039 | 10:387c49b2fc7e | 62 | leds = shot % 8; |
va009039 | 10:387c49b2fc7e | 63 | } |
va009039 | 10:387c49b2fc7e | 64 | interval_t.reset(); |
masato | 11:944c66b16508 | 65 | printf("end\r\n"); |
va009039 | 10:387c49b2fc7e | 66 | } |
masato | 12:c827ed52021d | 67 | #if MSDFILESYSTEM |
masato | 12:c827ed52021d | 68 | if (!msd->connected()) msd->connect(); |
masato | 12:c827ed52021d | 69 | #endif |
va009039 | 10:387c49b2fc7e | 70 | cam->poll(); |
va009039 | 10:387c49b2fc7e | 71 | } |
va009039 | 10:387c49b2fc7e | 72 | } |