MODIFIED BY FEVZI YAZGAN BOUDRATE AND IMAGESIZE FUNCTION ADDED ALSO IT SENDS THE IMAGE AT ONE TIME TO THE MBED. SO IT IS FASTER TO SEND IMAGE AT A ONE TIME:)

Dependencies:   mbed Camera_LS_Y201 SDFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main2.cpp Source File

main2.cpp

00001 /**
00002 MODIFIED BY FEVZI YAZGAN 
00003 BOUDRATE AND IMAGESIZE FUNCTION ADDED ALSO IT SENDS THE IMAGE AT ONE TIME TO THE MBED. 
00004 SO IT IS FASTER TO SEND IMAGE AT A ONE TIME:)
00005 
00006  * =============================================================================
00007  * LS-Y201 - Test program. (Version 0.0.2)
00008  * =============================================================================
00009  * Copyright (c) 2010-2011 Shinichiro Nakamura (CuBeatSystems)
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a copy
00012  * of this software and associated documentation files (the "Software"), to deal
00013  * in the Software without restriction, including without limitation the rights
00014  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00015  * copies of the Software, and to permit persons to whom the Software is
00016  * furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included in
00019  * all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00022  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00024  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00026  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00027  * THE SOFTWARE.
00028  * =============================================================================
00029  */
00030 #include "mbed.h"
00031 #include "Camera_LS_Y201.h"
00032 #include "SDFileSystem.h"
00033 
00034 #define DEBMSG      printf
00035 #define NEWLINE()   printf("\r\n")
00036 
00037 #define USE_SDCARD 0
00038 
00039 #if USE_SDCARD
00040 #define FILENAME    "/sd/IMG_%04d.jpg"
00041 SDFileSystem fs(p5, p6, p7, p8, "sd");
00042 #else
00043 #define FILENAME    "/local/IMG_%04d.jpg"
00044 LocalFileSystem fs("local");
00045 #endif
00046 Camera_LS_Y201 cam1(p13, p14, Camera_LS_Y201::Default);
00047 
00048 typedef struct work {
00049     FILE *fp;
00050 } work_t;
00051 
00052 work_t work;
00053 
00054 /**
00055  * Callback function for readJpegFileContent.
00056  *
00057  * @param buf A pointer to a buffer.
00058  * @param siz A size of the buffer.
00059  */
00060 void callback_func( int total, uint8_t *buf, size_t siz) 
00061 {
00062     fwrite(buf, siz, 1, work.fp);
00063 }
00064 
00065 /**
00066  * Capture.
00067  *
00068  * @param cam A pointer to a camera object.
00069  * @param filename The file name.
00070  *
00071  * @return Return 0 if it succeed.
00072  */
00073 int capture(Camera_LS_Y201 *cam, char *filename) {
00074     /*
00075      * Take a picture.
00076      */
00077     if (cam->takePicture() != 0) {
00078         return -1;
00079     }
00080     DEBMSG("Captured.");
00081     NEWLINE();
00082 
00083     /*
00084      * Open file.
00085      */
00086     work.fp = fopen(filename, "wb");
00087     if (work.fp == NULL) {
00088         return -2;
00089     }
00090 
00091     /*
00092      * Read the content.
00093      */
00094     DEBMSG("%s", filename);
00095     NEWLINE();
00096     if (cam->readJpegFileContent(callback_func) != 0) {
00097         fclose(work.fp);
00098         return -3;
00099     }
00100     fclose(work.fp);
00101 
00102     /*
00103      * Stop taking pictures.
00104      */
00105     cam->stopTakingPictures();
00106 
00107     return 0;
00108 }
00109 
00110 /**
00111  * Entry point.
00112  */
00113 int main(void) {
00114     DEBMSG("Camera module");
00115     NEWLINE();
00116     DEBMSG("Resetting...");
00117     NEWLINE();
00118     wait(1);
00119 
00120     if (cam1.reset() == 0) {
00121         DEBMSG("Reset OK.");
00122         NEWLINE();
00123     } else {
00124         DEBMSG("Reset fail.");
00125         NEWLINE();
00126         error("Reset fail.");
00127     }
00128 
00129     wait(1);
00130     cam1.setImageSize(Camera_LS_Y201::ImageSize160x120);
00131     wait(1);
00132     cam1.setBaudrate(Camera_LS_Y201::Baud115200);
00133     wait(1);
00134     Camera_LS_Y201 cam2(p13, p14, Camera_LS_Y201::Bauds115200);
00135 
00136     wait(1);
00137 
00138     int cnt = 0;
00139     while (cnt<10) {
00140         char fname[64];
00141         snprintf(fname, sizeof(fname) - 1, FILENAME, cnt);
00142         int r = capture(&cam2, fname);
00143         if (r == 0) {
00144             DEBMSG("[%04d]:OK.", cnt);
00145             NEWLINE();
00146         } else {
00147             DEBMSG("[%04d]:NG. (code=%d)", cnt, r);
00148             NEWLINE();
00149             error("Failure.");
00150         }
00151         cnt++;
00152     }
00153 }