Ibrahim Abd Elkader
/
ucam
main.cpp@0:796c01948235, 2011-12-09 (annotated)
- Committer:
- mux
- Date:
- Fri Dec 09 05:32:12 2011 +0000
- Revision:
- 0:796c01948235
4D uCAM driver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mux | 0:796c01948235 | 1 | #include "mbed.h" |
mux | 0:796c01948235 | 2 | #include "ucam.h" |
mux | 0:796c01948235 | 3 | #define BUFFER_LENGTH 4096 |
mux | 0:796c01948235 | 4 | |
mux | 0:796c01948235 | 5 | Serial firefly(p28, p27); |
mux | 0:796c01948235 | 6 | Serial debug(USBTX, USBRX); |
mux | 0:796c01948235 | 7 | |
mux | 0:796c01948235 | 8 | DigitalOut firefly_led(LED1); |
mux | 0:796c01948235 | 9 | UCam ucam(p13, p14, LED2, 1228800); // tx, rx, led, baud |
mux | 0:796c01948235 | 10 | |
mux | 0:796c01948235 | 11 | uint16_t len; |
mux | 0:796c01948235 | 12 | uint8_t ubuf[BUFFER_LENGTH]; |
mux | 0:796c01948235 | 13 | uint8_t take_snapshot =0; |
mux | 0:796c01948235 | 14 | |
mux | 0:796c01948235 | 15 | void firefly_isr() |
mux | 0:796c01948235 | 16 | { |
mux | 0:796c01948235 | 17 | while(firefly.readable()) |
mux | 0:796c01948235 | 18 | firefly.getc(); |
mux | 0:796c01948235 | 19 | take_snapshot = 1; |
mux | 0:796c01948235 | 20 | } |
mux | 0:796c01948235 | 21 | |
mux | 0:796c01948235 | 22 | int main() |
mux | 0:796c01948235 | 23 | { |
mux | 0:796c01948235 | 24 | debug.puts("initiating firefly...\r\n"); |
mux | 0:796c01948235 | 25 | firefly.baud(921600); |
mux | 0:796c01948235 | 26 | firefly.attach(firefly_isr); |
mux | 0:796c01948235 | 27 | firefly_led = 1; |
mux | 0:796c01948235 | 28 | |
mux | 0:796c01948235 | 29 | debug.puts("initiating ucam...\r\n"); |
mux | 0:796c01948235 | 30 | |
mux | 0:796c01948235 | 31 | if (ucam.connect() == 0){ |
mux | 0:796c01948235 | 32 | debug.puts("connection to ucam established\r\n"); |
mux | 0:796c01948235 | 33 | } else { |
mux | 0:796c01948235 | 34 | debug.puts("connection to ucam failed\r\n"); |
mux | 0:796c01948235 | 35 | return -1; |
mux | 0:796c01948235 | 36 | } |
mux | 0:796c01948235 | 37 | |
mux | 0:796c01948235 | 38 | |
mux | 0:796c01948235 | 39 | if (ucam.start_video(COLOR_JPEG, JPEG_160x128, JPEG_160x128) != 0) { |
mux | 0:796c01948235 | 40 | debug.printf("failed to start video\r\n"); |
mux | 0:796c01948235 | 41 | return -1; |
mux | 0:796c01948235 | 42 | } |
mux | 0:796c01948235 | 43 | |
mux | 0:796c01948235 | 44 | Timer t; |
mux | 0:796c01948235 | 45 | uint16_t i; |
mux | 0:796c01948235 | 46 | |
mux | 0:796c01948235 | 47 | while (1) { |
mux | 0:796c01948235 | 48 | |
mux | 0:796c01948235 | 49 | t.reset(); |
mux | 0:796c01948235 | 50 | |
mux | 0:796c01948235 | 51 | if (take_snapshot |
mux | 0:796c01948235 | 52 | && ucam.next_frame(ubuf, &len) == 0) { |
mux | 0:796c01948235 | 53 | |
mux | 0:796c01948235 | 54 | firefly.putc(((char*)&len)[0]); //size lsb |
mux | 0:796c01948235 | 55 | firefly.putc(((char*)&len)[1]); //size msb |
mux | 0:796c01948235 | 56 | |
mux | 0:796c01948235 | 57 | for(i=0; i < len; i++){ |
mux | 0:796c01948235 | 58 | firefly.putc(ubuf[i]); |
mux | 0:796c01948235 | 59 | } |
mux | 0:796c01948235 | 60 | |
mux | 0:796c01948235 | 61 | take_snapshot = 0; |
mux | 0:796c01948235 | 62 | debug.printf("frame %f \r\n", t.read()); |
mux | 0:796c01948235 | 63 | } |
mux | 0:796c01948235 | 64 | wait_ms(10); |
mux | 0:796c01948235 | 65 | } |
mux | 0:796c01948235 | 66 | } |