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

Committer:
fyazgan
Date:
Wed Mar 02 05:53:13 2011 +0000
Revision:
0:21b87062f376

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fyazgan 0:21b87062f376 1 /**
fyazgan 0:21b87062f376 2 MODIFIED BY FEVZI YAZGAN
fyazgan 0:21b87062f376 3 BOUDRATE AND IMAGESIZE FUNCTION ADDED ALSO IT SENDS THE IMAGE AT ONE TIME TO THE MBED.
fyazgan 0:21b87062f376 4 SO IT IS FASTER TO SEND IMAGE AT A ONE TIME:)
fyazgan 0:21b87062f376 5
fyazgan 0:21b87062f376 6 * =============================================================================
fyazgan 0:21b87062f376 7 * LS-Y201 - Test program. (Version 0.0.2)
fyazgan 0:21b87062f376 8 * =============================================================================
fyazgan 0:21b87062f376 9 * Copyright (c) 2010-2011 Shinichiro Nakamura (CuBeatSystems)
fyazgan 0:21b87062f376 10 *
fyazgan 0:21b87062f376 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
fyazgan 0:21b87062f376 12 * of this software and associated documentation files (the "Software"), to deal
fyazgan 0:21b87062f376 13 * in the Software without restriction, including without limitation the rights
fyazgan 0:21b87062f376 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fyazgan 0:21b87062f376 15 * copies of the Software, and to permit persons to whom the Software is
fyazgan 0:21b87062f376 16 * furnished to do so, subject to the following conditions:
fyazgan 0:21b87062f376 17 *
fyazgan 0:21b87062f376 18 * The above copyright notice and this permission notice shall be included in
fyazgan 0:21b87062f376 19 * all copies or substantial portions of the Software.
fyazgan 0:21b87062f376 20 *
fyazgan 0:21b87062f376 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fyazgan 0:21b87062f376 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fyazgan 0:21b87062f376 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fyazgan 0:21b87062f376 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fyazgan 0:21b87062f376 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fyazgan 0:21b87062f376 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
fyazgan 0:21b87062f376 27 * THE SOFTWARE.
fyazgan 0:21b87062f376 28 * =============================================================================
fyazgan 0:21b87062f376 29 */
fyazgan 0:21b87062f376 30 #include "mbed.h"
fyazgan 0:21b87062f376 31 #include "Camera_LS_Y201.h"
fyazgan 0:21b87062f376 32 #include "SDFileSystem.h"
fyazgan 0:21b87062f376 33
fyazgan 0:21b87062f376 34 #define DEBMSG printf
fyazgan 0:21b87062f376 35 #define NEWLINE() printf("\r\n")
fyazgan 0:21b87062f376 36
fyazgan 0:21b87062f376 37 #define USE_SDCARD 0
fyazgan 0:21b87062f376 38
fyazgan 0:21b87062f376 39 #if USE_SDCARD
fyazgan 0:21b87062f376 40 #define FILENAME "/sd/IMG_%04d.jpg"
fyazgan 0:21b87062f376 41 SDFileSystem fs(p5, p6, p7, p8, "sd");
fyazgan 0:21b87062f376 42 #else
fyazgan 0:21b87062f376 43 #define FILENAME "/local/IMG_%04d.jpg"
fyazgan 0:21b87062f376 44 LocalFileSystem fs("local");
fyazgan 0:21b87062f376 45 #endif
fyazgan 0:21b87062f376 46 Camera_LS_Y201 cam1(p13, p14, Camera_LS_Y201::Default);
fyazgan 0:21b87062f376 47
fyazgan 0:21b87062f376 48 typedef struct work {
fyazgan 0:21b87062f376 49 FILE *fp;
fyazgan 0:21b87062f376 50 } work_t;
fyazgan 0:21b87062f376 51
fyazgan 0:21b87062f376 52 work_t work;
fyazgan 0:21b87062f376 53
fyazgan 0:21b87062f376 54 /**
fyazgan 0:21b87062f376 55 * Callback function for readJpegFileContent.
fyazgan 0:21b87062f376 56 *
fyazgan 0:21b87062f376 57 * @param buf A pointer to a buffer.
fyazgan 0:21b87062f376 58 * @param siz A size of the buffer.
fyazgan 0:21b87062f376 59 */
fyazgan 0:21b87062f376 60 void callback_func( int total, uint8_t *buf, size_t siz)
fyazgan 0:21b87062f376 61 {
fyazgan 0:21b87062f376 62 fwrite(buf, siz, 1, work.fp);
fyazgan 0:21b87062f376 63 }
fyazgan 0:21b87062f376 64
fyazgan 0:21b87062f376 65 /**
fyazgan 0:21b87062f376 66 * Capture.
fyazgan 0:21b87062f376 67 *
fyazgan 0:21b87062f376 68 * @param cam A pointer to a camera object.
fyazgan 0:21b87062f376 69 * @param filename The file name.
fyazgan 0:21b87062f376 70 *
fyazgan 0:21b87062f376 71 * @return Return 0 if it succeed.
fyazgan 0:21b87062f376 72 */
fyazgan 0:21b87062f376 73 int capture(Camera_LS_Y201 *cam, char *filename) {
fyazgan 0:21b87062f376 74 /*
fyazgan 0:21b87062f376 75 * Take a picture.
fyazgan 0:21b87062f376 76 */
fyazgan 0:21b87062f376 77 if (cam->takePicture() != 0) {
fyazgan 0:21b87062f376 78 return -1;
fyazgan 0:21b87062f376 79 }
fyazgan 0:21b87062f376 80 DEBMSG("Captured.");
fyazgan 0:21b87062f376 81 NEWLINE();
fyazgan 0:21b87062f376 82
fyazgan 0:21b87062f376 83 /*
fyazgan 0:21b87062f376 84 * Open file.
fyazgan 0:21b87062f376 85 */
fyazgan 0:21b87062f376 86 work.fp = fopen(filename, "wb");
fyazgan 0:21b87062f376 87 if (work.fp == NULL) {
fyazgan 0:21b87062f376 88 return -2;
fyazgan 0:21b87062f376 89 }
fyazgan 0:21b87062f376 90
fyazgan 0:21b87062f376 91 /*
fyazgan 0:21b87062f376 92 * Read the content.
fyazgan 0:21b87062f376 93 */
fyazgan 0:21b87062f376 94 DEBMSG("%s", filename);
fyazgan 0:21b87062f376 95 NEWLINE();
fyazgan 0:21b87062f376 96 if (cam->readJpegFileContent(callback_func) != 0) {
fyazgan 0:21b87062f376 97 fclose(work.fp);
fyazgan 0:21b87062f376 98 return -3;
fyazgan 0:21b87062f376 99 }
fyazgan 0:21b87062f376 100 fclose(work.fp);
fyazgan 0:21b87062f376 101
fyazgan 0:21b87062f376 102 /*
fyazgan 0:21b87062f376 103 * Stop taking pictures.
fyazgan 0:21b87062f376 104 */
fyazgan 0:21b87062f376 105 cam->stopTakingPictures();
fyazgan 0:21b87062f376 106
fyazgan 0:21b87062f376 107 return 0;
fyazgan 0:21b87062f376 108 }
fyazgan 0:21b87062f376 109
fyazgan 0:21b87062f376 110 /**
fyazgan 0:21b87062f376 111 * Entry point.
fyazgan 0:21b87062f376 112 */
fyazgan 0:21b87062f376 113 int main(void) {
fyazgan 0:21b87062f376 114 DEBMSG("Camera module");
fyazgan 0:21b87062f376 115 NEWLINE();
fyazgan 0:21b87062f376 116 DEBMSG("Resetting...");
fyazgan 0:21b87062f376 117 NEWLINE();
fyazgan 0:21b87062f376 118 wait(1);
fyazgan 0:21b87062f376 119
fyazgan 0:21b87062f376 120 if (cam1.reset() == 0) {
fyazgan 0:21b87062f376 121 DEBMSG("Reset OK.");
fyazgan 0:21b87062f376 122 NEWLINE();
fyazgan 0:21b87062f376 123 } else {
fyazgan 0:21b87062f376 124 DEBMSG("Reset fail.");
fyazgan 0:21b87062f376 125 NEWLINE();
fyazgan 0:21b87062f376 126 error("Reset fail.");
fyazgan 0:21b87062f376 127 }
fyazgan 0:21b87062f376 128
fyazgan 0:21b87062f376 129 wait(1);
fyazgan 0:21b87062f376 130 cam1.setImageSize(Camera_LS_Y201::ImageSize160x120);
fyazgan 0:21b87062f376 131 wait(1);
fyazgan 0:21b87062f376 132 cam1.setBaudrate(Camera_LS_Y201::Baud115200);
fyazgan 0:21b87062f376 133 wait(1);
fyazgan 0:21b87062f376 134 Camera_LS_Y201 cam2(p13, p14, Camera_LS_Y201::Bauds115200);
fyazgan 0:21b87062f376 135
fyazgan 0:21b87062f376 136 wait(1);
fyazgan 0:21b87062f376 137
fyazgan 0:21b87062f376 138 int cnt = 0;
fyazgan 0:21b87062f376 139 while (cnt<10) {
fyazgan 0:21b87062f376 140 char fname[64];
fyazgan 0:21b87062f376 141 snprintf(fname, sizeof(fname) - 1, FILENAME, cnt);
fyazgan 0:21b87062f376 142 int r = capture(&cam2, fname);
fyazgan 0:21b87062f376 143 if (r == 0) {
fyazgan 0:21b87062f376 144 DEBMSG("[%04d]:OK.", cnt);
fyazgan 0:21b87062f376 145 NEWLINE();
fyazgan 0:21b87062f376 146 } else {
fyazgan 0:21b87062f376 147 DEBMSG("[%04d]:NG. (code=%d)", cnt, r);
fyazgan 0:21b87062f376 148 NEWLINE();
fyazgan 0:21b87062f376 149 error("Failure.");
fyazgan 0:21b87062f376 150 }
fyazgan 0:21b87062f376 151 cnt++;
fyazgan 0:21b87062f376 152 }
fyazgan 0:21b87062f376 153 }