Tadao Iida / Mbed 2 deprecated CameraC1098_picture

Dependencies:   FatFileSystem TextLCD mbed CameraC1098 SDHC_Lib

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "CameraC1098.h"
00003 #include "SDHCFileSystem.h"
00004 #include "TextLCD.h"
00005  
00006 /*
00007  * Definitions.
00008  */
00009 #define USE_SD_CARD 1
00010 
00011 /*
00012  * Variables.
00013  */
00014 static const int CAPTURE_FRAMES = 1;
00015 static char buf[256+1];
00016 static FILE *fp_jpeg;
00017 
00018 /*
00019  * Modules.
00020  */
00021 #if USE_SD_CARD
00022 SDFileSystem sd(p5, p6, p7, p8, "fs");
00023 #else
00024 LocalFileSystem fs("fs");
00025 #endif
00026 
00027 TextLCD lcd(p24, p26, p27, p28, p29, p30);
00028 CameraC1098 camera(p9, p10);
00029  
00030 
00031 /**
00032  * A callback function for jpeg images.
00033  * You can block this function until saving the image datas.
00034  *
00035  * @param buf A pointer to the image buffer.
00036  * @param siz A size of the image buffer.
00037  */
00038 void jpeg_callback(char *buf, size_t siz) {
00039     for (int i = 0; i < (int)siz; i++) {
00040         fprintf(fp_jpeg, "%c", buf[i]);
00041     }
00042 }
00043 
00044 /**
00045  * Synchronizing.
00046  */
00047 void sync(void) {
00048     CameraC1098::ErrorNumber err = CameraC1098::NoError;
00049 
00050     err = camera.sync();
00051     lcd.locate(0,0);
00052     if (CameraC1098::NoError == err) {
00053         printf("[ OK ] : CameraC1098::sync\r\n");
00054         lcd.printf("C1098:Sync [OK] ");
00055         
00056     } else {
00057         printf("[FAIL] : CameraC1098::sync (Error=%02X)\r\n", (int)err);
00058         lcd.printf("C1098:Sync[FAIL]");
00059     }
00060 }
00061 
00062 
00063 /**
00064  * A test function for jpeg snapshot picture.
00065  */
00066 void test_jpeg_snapshot_picture(int j) {
00067     CameraC1098::ErrorNumber err = CameraC1098::NoError; 
00068     for (int i = 0; i < CAPTURE_FRAMES; i++) {
00069         char fname[64];
00070         snprintf(fname, sizeof(fname), "/fs/jpss%02d-%02d.jpg",i, j);
00071         fp_jpeg = fopen(fname, "w");
00072         if ( fp_jpeg == NULL ){
00073             lcd.locate(0,1);
00074             lcd.printf("File Open Fail ");
00075             exit(1);
00076         }
00077 
00078         err = camera.getJpegSnapshotPicture(jpeg_callback);
00079         lcd.locate(0,1);
00080         if (CameraC1098::NoError == err) {
00081             printf("[ OK ] : CameraC1098::getJpegSnapshotPicture\r\n");
00082             lcd.printf("getJpgPict [OK] ");
00083         } else {
00084             printf("[FAIL] : CameraC1098::getJpegSnapshotPicture (Error=%02X)\r\n", (int)err);
00085             lcd.printf("getJpgPict[FAIL]");
00086         }
00087         fclose(fp_jpeg);
00088     }
00089 }
00090 
00091 /**
00092  * A entry point.
00093  */
00094 int main() {
00095     printf("\r\n");
00096     printf("==========\r\n"); 
00097     printf("CameraC1098\r\n");
00098     printf("==========\r\n");
00099     CameraC1098::ErrorNumber err = CameraC1098::NoError;
00100     err = camera.init(CameraC1098::Baud460800, CameraC1098::JpegResolution80x64);    
00101      
00102     lcd.cls();
00103     lcd.locate(0,0);
00104     if (CameraC1098::NoError == err) {
00105         printf("[ OK ] : CameraC1098::init\r\n");
00106         lcd.printf("C1098:init [OK] ");
00107     } else {
00108         printf("[FAIL] : CameraC1098::init (Error=%02X)\r\n", (int)err);
00109         lcd.printf("C1098:init[FAIL]");
00110     }
00111     sync();
00112     
00113     test_jpeg_snapshot_picture(1); 
00114     err = camera.init(CameraC1098::Baud460800, CameraC1098::JpegResolution160x128);   
00115     test_jpeg_snapshot_picture(2);        
00116     err = camera.init(CameraC1098::Baud460800, CameraC1098::JpegResolution320x240);   
00117     test_jpeg_snapshot_picture(3);    
00118     err = camera.init(CameraC1098::Baud460800, CameraC1098::JpegResolution640x480);   
00119     test_jpeg_snapshot_picture(4);         
00120     
00121     return 0;
00122 }