LinkSprite JPEG Color Camera Test Program.
Dependencies: mbed Camera_LS_Y201 SDFileSystem
Revision 1:71734a321e31, committed 2011-02-09
- Comitter:
- shintamainjp
- Date:
- Wed Feb 09 23:04:04 2011 +0000
- Parent:
- 0:07895dc2b7c3
- Commit message:
- Updated the sequences of the sample.
Changed in this revision
diff -r 07895dc2b7c3 -r 71734a321e31 Camera_LS_Y201.lib --- a/Camera_LS_Y201.lib Thu Nov 25 15:44:19 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/shintamainjp/code/Camera_LS_Y201/#f71232252dcf
diff -r 07895dc2b7c3 -r 71734a321e31 extlib/FATFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extlib/FATFileSystem.lib Wed Feb 09 23:04:04 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file
diff -r 07895dc2b7c3 -r 71734a321e31 extlib/SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extlib/SDFileSystem.lib Wed Feb 09 23:04:04 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/SDFileSystem/#b1ddfc9a9b25
diff -r 07895dc2b7c3 -r 71734a321e31 main.cpp --- a/main.cpp Thu Nov 25 15:44:19 2010 +0000 +++ b/main.cpp Wed Feb 09 23:04:04 2011 +0000 @@ -1,40 +1,148 @@ +/** + * ============================================================================= + * LS-Y201 - Test program. (Version 0.0.2) + * ============================================================================= + * Copyright (c) 2010-2011 Shinichiro Nakamura (CuBeatSystems) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * ============================================================================= + */ #include "mbed.h" #include "Camera_LS_Y201.h" +#include "SDFileSystem.h" +#define DEBMSG printf +#define NEWLINE() printf("\r\n") + +#define USE_SDCARD 0 + +#if USE_SDCARD +#define FILENAME "/sd/IMG_%04d.jpg" +SDFileSystem fs(p5, p6, p7, p8, "sd"); +#else +#define FILENAME "/local/IMG_%04d.jpg" LocalFileSystem fs("local"); -Camera_LS_Y201 cam(p13, p14); +#endif +Camera_LS_Y201 cam1(p13, p14); -FILE *fp; +typedef struct work { + FILE *fp; +} work_t; + +work_t work; -void callback_func(uint8_t *buf, size_t siz) { - fwrite(buf, siz, 1, fp); +/** + * Callback function for readJpegFileContent. + * + * @param buf A pointer to a buffer. + * @param siz A size of the buffer. + */ +void callback_func(int done, int total, uint8_t *buf, size_t siz) { + fwrite(buf, siz, 1, work.fp); + + static int n = 0; + int tmp = done * 100 / total; + if (n != tmp) { + n = tmp; + DEBMSG("Writing...: %3d%%", n); + NEWLINE(); + } } -int main(void) { - fp = fopen("/local/test.jpg", "wb"); - if (fp == NULL) { - error("Failure to open a destination file."); +/** + * Capture. + * + * @param cam A pointer to a camera object. + * @param filename The file name. + * + * @return Return 0 if it succeed. + */ +int capture(Camera_LS_Y201 *cam, char *filename) { + /* + * Take a picture. + */ + if (cam->takePicture() != 0) { + return -1; } - wait(1); - - printf("reset=%d\n", cam.reset()); - wait(1); + DEBMSG("Captured."); + NEWLINE(); -#if 0 - printf("setImageSize=%d\n", cam.setImageSize(LS_Y201::ImageSize640x480)); - wait(1); -#endif - - printf("takePicture=%d\n", cam.takePicture()); - wait(1); + /* + * Open file. + */ + work.fp = fopen(filename, "wb"); + if (work.fp == NULL) { + return -2; + } - int fs; - printf("readJpegFileSize=%d\n", cam.readJpegFileSize(&fs)); - printf("\tFile size = %d\n", fs); - wait(1); + /* + * Read the content. + */ + DEBMSG("%s", filename); + NEWLINE(); + if (cam->readJpegFileContent(callback_func) != 0) { + fclose(work.fp); + return -3; + } + fclose(work.fp); - printf("readJpegFileContent=%d\n", cam.readJpegFileContent(callback_func)); - wait(1); + /* + * Stop taking pictures. + */ + cam->stopTakingPictures(); return 0; } + +/** + * Entry point. + */ +int main(void) { + DEBMSG("Camera module"); + NEWLINE(); + DEBMSG("Resetting..."); + NEWLINE(); + wait(1); + + if (cam1.reset() == 0) { + DEBMSG("Reset OK."); + NEWLINE(); + } else { + DEBMSG("Reset fail."); + NEWLINE(); + error("Reset fail."); + } + wait(1); + + int cnt = 0; + while (1) { + char fname[64]; + snprintf(fname, sizeof(fname) - 1, FILENAME, cnt); + int r = capture(&cam1, fname); + if (r == 0) { + DEBMSG("[%04d]:OK.", cnt); + NEWLINE(); + } else { + DEBMSG("[%04d]:NG. (code=%d)", cnt, r); + NEWLINE(); + error("Failure."); + } + cnt++; + } +}
diff -r 07895dc2b7c3 -r 71734a321e31 mbed.bld --- a/mbed.bld Thu Nov 25 15:44:19 2010 +0000 +++ b/mbed.bld Wed Feb 09 23:04:04 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e +http://mbed.org/users/mbed_official/code/mbed/builds/9a9732ce53a1
diff -r 07895dc2b7c3 -r 71734a321e31 mylib/Camera_LS_Y201.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mylib/Camera_LS_Y201.lib Wed Feb 09 23:04:04 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/shintamainjp/code/Camera_LS_Y201/#43358d40f879