A test program for CameraC328 library.
Dependencies: mbed CameraC328 SDFileSystem
Revision 1:01d23ea0ab41, committed 2010-09-17
- Comitter:
- shintamainjp
- Date:
- Fri Sep 17 11:16:19 2010 +0000
- Parent:
- 0:cebbdb54d1cb
- Child:
- 2:0c8d5949dd4a
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FATFileSystem.lib Fri Sep 17 11:16:19 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Fri Sep 17 11:16:19 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/SDFileSystem/#b1ddfc9a9b25
--- a/main.cpp Mon Aug 30 13:47:00 2010 +0000 +++ b/main.cpp Fri Sep 17 11:16:19 2010 +0000 @@ -5,27 +5,68 @@ * http://shinta.main.jp/ */ +/* + * Include files. + */ + #include "mbed.h" #include "CameraC328.h" +#include "SDFileSystem.h" -LocalFileSystem fs ("fs"); +/* + * Definitions. + */ +#define USE_JPEG_HIGH_RESOLUTION 1 +#define USE_SD_CARD 0 +/* + * Variables. + */ +static const int CAPTURE_FRAMES = 5; +static const int RAWIMG_X = 80; +static const int RAWIMG_Y = 60; +static char buf[RAWIMG_X * RAWIMG_Y * 2]; +static FILE *fp_jpeg; + +/* + * Modules. + */ +#if USE_SD_CARD +SDFileSystem sd(p5, p6, p7, p8, "fs"); +#else +LocalFileSystem fs("fs"); +#endif CameraC328 camera(p9, p10, CameraC328::Baud19200); -const int IMG_X = 80; -const int IMG_Y = 60; -char buf[IMG_X * IMG_Y * 2]; -FILE *fp_jpeg; +/** + * A callback function for uncompressed images. + * Please do NOT block this callback function. + * Because the camera module transmit image datas continuously. + * + * @param done a done number of packets. + * @param total a total number of packets. + * @param c received data. + */ void uncompressed_callback(size_t done, size_t total, char c) { buf[done - 1] = c; } +/** + * A callback function for jpeg images. + * You can block this function until saving the image datas. + * + * @param buf A pointer to the image buffer. + * @param siz A size of the image buffer. + */ void jpeg_callback(char *buf, size_t siz) { for (int i = 0; i < (int)siz; i++) { fprintf(fp_jpeg, "%c", buf[i]); } } +/** + * Synchronizing. + */ void sync(void) { CameraC328::ErrorNumber err = CameraC328::NoError; @@ -37,17 +78,20 @@ } } +/** + * A test function for uncompressed snapshot picture. + */ void test_uncompressed_snapshot_picture(void) { CameraC328::ErrorNumber err = CameraC328::NoError; - err = camera.init(CameraC328::Color16bit, CameraC328::RawResolution80x60, CameraC328::JpegResolution80x64); + err = camera.init(CameraC328::Color16bit, CameraC328::RawResolution80x60, CameraC328::JpegResolution160x128); if (CameraC328::NoError == err) { printf("[ OK ] : CameraC328::init\n"); } else { printf("[FAIL] : CameraC328::init (Error=%02X)\n", (int)err); } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < CAPTURE_FRAMES; i++) { err = camera.getUncompressedSnapshotPicture(uncompressed_callback); if (CameraC328::NoError == err) { printf("[ OK ] : CameraC328::getUncompressedSnapshotPicture\n"); @@ -59,11 +103,11 @@ snprintf(fname, sizeof(fname), "/fs/ucss%04d.ppm", i); FILE *fp = fopen(fname, "w"); fprintf(fp, "P3\n"); - fprintf(fp, "%d %d\n", IMG_X, IMG_Y); + fprintf(fp, "%d %d\n", RAWIMG_X, RAWIMG_Y); fprintf(fp, "%d\n", 255); - for (int y = 0; y < IMG_Y; y++) { - for (int x = 0; x < IMG_X; x++) { - int adrofs = y * (IMG_X * 2) + (x * 2); + for (int y = 0; y < RAWIMG_Y; y++) { + for (int x = 0; x < RAWIMG_X; x++) { + int adrofs = y * (RAWIMG_X * 2) + (x * 2); uint16_t dat = (buf[adrofs + 0] << 8) | (buf[adrofs + 1] << 0); uint8_t r = ((dat >> 11) & 0x1f) << 3; uint8_t g = ((dat >> 5) & 0x3f) << 2; @@ -75,17 +119,20 @@ } } +/** + * A test function for uncompressed preview picture. + */ void test_uncompressed_preview_picture(void) { CameraC328::ErrorNumber err = CameraC328::NoError; - err = camera.init(CameraC328::Color16bit, CameraC328::RawResolution80x60, CameraC328::JpegResolution80x64); + err = camera.init(CameraC328::Color16bit, CameraC328::RawResolution80x60, CameraC328::JpegResolution160x128); if (CameraC328::NoError == err) { printf("[ OK ] : CameraC328::init\n"); } else { printf("[FAIL] : CameraC328::init (Error=%02X)\n", (int)err); } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < CAPTURE_FRAMES; i++) { err = camera.getUncompressedPreviewPicture(uncompressed_callback); if (CameraC328::NoError == err) { printf("[ OK ] : CameraC328::getUncompressedPreviewPicture\n"); @@ -97,11 +144,11 @@ snprintf(fname, sizeof(fname), "/fs/ucpv%04d.ppm", i); FILE *fp = fopen(fname, "w"); fprintf(fp, "P3\n"); - fprintf(fp, "%d %d\n", IMG_X, IMG_Y); + fprintf(fp, "%d %d\n", RAWIMG_X, RAWIMG_Y); fprintf(fp, "%d\n", 255); - for (int y = 0; y < IMG_Y; y++) { - for (int x = 0; x < IMG_X; x++) { - int adrofs = y * (IMG_X * 2) + (x * 2); + for (int y = 0; y < RAWIMG_Y; y++) { + for (int x = 0; x < RAWIMG_X; x++) { + int adrofs = y * (RAWIMG_X * 2) + (x * 2); uint16_t dat = (buf[adrofs + 0] << 8) | (buf[adrofs + 1] << 0); uint8_t r = ((dat >> 11) & 0x1f) << 3; uint8_t g = ((dat >> 5) & 0x3f) << 2; @@ -113,17 +160,24 @@ } } +/** + * A test function for jpeg snapshot picture. + */ void test_jpeg_snapshot_picture(void) { CameraC328::ErrorNumber err = CameraC328::NoError; +#if USE_JPEG_HIGH_RESOLUTION err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution640x480); +#else + err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution320x240); +#endif if (CameraC328::NoError == err) { printf("[ OK ] : CameraC328::init\n"); } else { printf("[FAIL] : CameraC328::init (Error=%02X)\n", (int)err); } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < CAPTURE_FRAMES; i++) { char fname[64]; snprintf(fname, sizeof(fname), "/fs/jpss%04d.jpg", i); fp_jpeg = fopen(fname, "w"); @@ -139,17 +193,24 @@ } } +/** + * A test function for jpeg preview picture. + */ void test_jpeg_preview_picture(void) { CameraC328::ErrorNumber err = CameraC328::NoError; +#if USE_JPEG_HIGH_RESOLUTION err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution640x480); +#else + err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution320x240); +#endif if (CameraC328::NoError == err) { printf("[ OK ] : CameraC328::init\n"); } else { printf("[FAIL] : CameraC328::init (Error=%02X)\n", (int)err); } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < CAPTURE_FRAMES; i++) { char fname[64]; snprintf(fname, sizeof(fname), "/fs/jppv%04d.jpg", i); fp_jpeg = fopen(fname, "w"); @@ -165,6 +226,9 @@ } } +/** + * A entry point. + */ int main() { printf("\n"); printf("==========\n");
--- a/mbed.bld Mon Aug 30 13:47:00 2010 +0000 +++ b/mbed.bld Fri Sep 17 11:16:19 2010 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/74b8d43b5817 +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e