camera!! test!!

Dependencies:   CameraC328 SDFileSystem mbed

Fork of Camera_TestProgram_2015 by Ricky Kwon

Files at this revision

API Documentation at this revision

Comitter:
Ricky_Kwon
Date:
Tue Jul 21 05:06:05 2015 +0000
Parent:
0:31be9011f67e
Commit message:
Camera(LJ-DSC02) with WIZwiki-W7500

Changed in this revision

CameraC328.lib Show annotated file Show diff for this revision Revisions of this file
Camera_LS_Y201.lib Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 31be9011f67e -r 7e547bf0f166 CameraC328.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CameraC328.lib	Tue Jul 21 05:06:05 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/shintamainjp/code/CameraC328/#49cfda6c547f
diff -r 31be9011f67e -r 7e547bf0f166 Camera_LS_Y201.lib
--- a/Camera_LS_Y201.lib	Fri Oct 10 21:48:33 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/shintamainjp/code/Camera_LS_Y201/#43358d40f879
diff -r 31be9011f67e -r 7e547bf0f166 SDFileSystem.lib
--- a/SDFileSystem.lib	Fri Oct 10 21:48:33 2014 +0000
+++ b/SDFileSystem.lib	Tue Jul 21 05:06:05 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/mbed/code/SDFileSystem/#7b35d1709458
+http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
diff -r 31be9011f67e -r 7e547bf0f166 main.cpp
--- a/main.cpp	Fri Oct 10 21:48:33 2014 +0000
+++ b/main.cpp	Tue Jul 21 05:06:05 2015 +0000
@@ -1,123 +1,256 @@
+/**
+ * Test program.
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+/*
+ * Include files.
+ */
+
 #include "mbed.h"
-#include "Camera_LS_Y201.h"
+#include "CameraC328.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");
+
+/*
+ * Definitions.
+ */
+#define USE_JPEG_HIGH_RESOLUTION  1
+#define USE_SD_CARD 1
+
+/*
+ * Variables.
+ */
+static const int CAPTURE_FRAMES = 5;
+static const int RAWIMG_X = 10;
+static const int RAWIMG_Y = 10;
+static char buf[RAWIMG_X * RAWIMG_Y * 2];
+static FILE *fp_jpeg;
+
+/*
+ * Modules.
+ */
+#if USE_SD_CARD
+SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "fs"); // the pinout on the mbed Cool Components workshop board
 #else
-#define FILENAME    "/local/IMG_%04d.jpg"
-LocalFileSystem fs("local");
+LocalFileSystem fs("fs");
 #endif
-Camera_LS_Y201 cam1(p13, p14);
- 
-typedef struct work {
-    FILE *fp;
-} work_t;
- 
-work_t work;
- 
+CameraC328 camera(PA_14, PA_13, CameraC328::Baud14400);
 /**
- * Callback function for readJpegFileContent.
+ * 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 a buffer.
- * @param siz A size of the buffer.
+ * @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;
+
+    err = camera.sync();
+    if (CameraC328::NoError == err) {
+        printf("[ OK ] : CameraC328::sync\n");
+    } else {
+        printf("[FAIL] : CameraC328::sync (Error=%02X)\n", (int)err);
+    }
+}
+
+/**
+ * A test function for uncompressed snapshot picture.
  */
-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();
+void test_uncompressed_snapshot_picture(void) {
+    CameraC328::ErrorNumber err = CameraC328::NoError;
+
+    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 < CAPTURE_FRAMES; i++) {
+        err = camera.getUncompressedSnapshotPicture(uncompressed_callback);
+        if (CameraC328::NoError == err) {
+            printf("[ OK ] : CameraC328::getUncompressedSnapshotPicture\n");
+        } else {
+            printf("[FAIL] : CameraC328::getUncompressedSnapshotPicture (Error=%02X)\n", (int)err);
+        }
+
+        char fname[64];
+        snprintf(fname, sizeof(fname), "/fs/ucss%04d.ppm", i);
+        FILE *fp = fopen(fname, "w");
+        fprintf(fp, "P3\n");
+        fprintf(fp, "%d %d\n", RAWIMG_X, RAWIMG_Y);
+        fprintf(fp, "%d\n", 255);
+        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;
+                uint8_t b = ((dat >> 0) & 0x1f) << 3;
+                fprintf(fp,"%d %d %d\n", r, g, b);
+            }
+        }
+        fclose(fp);
     }
 }
- 
+
 /**
- * Capture.
- *
- * @param cam A pointer to a camera object.
- * @param filename The file name.
- *
- * @return Return 0 if it succeed.
+ * A test function for uncompressed preview picture.
  */
-int capture(Camera_LS_Y201 *cam, char *filename) {
-    /*
-     * Take a picture.
-     */
-    if (cam->takePicture() != 0) {
-        return -1;
+void test_uncompressed_preview_picture(void) {
+    CameraC328::ErrorNumber err = CameraC328::NoError;
+
+    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 < CAPTURE_FRAMES; i++) {
+        err = camera.getUncompressedPreviewPicture(uncompressed_callback);
+        if (CameraC328::NoError == err) {
+            printf("[ OK ] : CameraC328::getUncompressedPreviewPicture\n");
+        } else {
+            printf("[FAIL] : CameraC328::getUncompressedPreviewPicture (Error=%02X)\n", (int)err);
+        }
+
+        char fname[64];
+        snprintf(fname, sizeof(fname), "/fs/ucpv%04d.ppm", i);
+        FILE *fp = fopen(fname, "w");
+        fprintf(fp, "P3\n");
+        fprintf(fp, "%d %d\n", RAWIMG_X, RAWIMG_Y);
+        fprintf(fp, "%d\n", 255);
+        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;
+                uint8_t b = ((dat >> 0) & 0x1f) << 3;
+                fprintf(fp,"%d %d %d\n", r, g, b);
+            }
+        }
+        fclose(fp);
+    }
+}
+
+/**
+ * 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);
     }
-    DEBMSG("Captured.");
-    NEWLINE();
- 
-    /*
-     * Open file.
-     */
-    work.fp = fopen(filename, "wb");
-    if (work.fp == NULL) {
-        return -2;
+
+    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");
+
+        err = camera.getJpegSnapshotPicture(jpeg_callback);
+        if (CameraC328::NoError == err) {
+            printf("[ OK ] : CameraC328::getJpegSnapshotPicture\n");
+        } else {
+            printf("[FAIL] : CameraC328::getJpegSnapshotPicture (Error=%02X)\n", (int)err);
+        }
+
+        fclose(fp_jpeg);
+    }
+}
+
+/**
+ * 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);
     }
- 
-    /*
-     * Read the content.
-     */
-    DEBMSG("%s", filename);
-    NEWLINE();
-    if (cam->readJpegFileContent(callback_func) != 0) {
-        fclose(work.fp);
-        return -3;
+
+    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");
+
+        err = camera.getJpegPreviewPicture(jpeg_callback);
+        if (CameraC328::NoError == err) {
+            printf("[ OK ] : CameraC328::getJpegPreviewPicture\n");
+        } else {
+            printf("[FAIL] : CameraC328::getJpegPreviewPicture (Error=%02X)\n", (int)err);
+        }
+
+        fclose(fp_jpeg);
     }
-    fclose(work.fp);
+}
+
+/**
+ * A entry point.
+ */
+int main() {
+    printf("\n");
+    printf("==========\n");
+    printf("CameraC328\n");
+    printf("==========\n");
+
+    sync();
+//    test_uncompressed_snapshot_picture();
+//    test_uncompressed_preview_picture();
+//    test_jpeg_preview_picture();
+    test_jpeg_snapshot_picture();
+
+    /*printf("Hello World!\n");   
  
-    /*
-     * Stop taking pictures.
-     */
-    cam->stopTakingPictures();
- 
-    return 0;
-}
- 
-/**
- * Entry point.
- */
-int main(void) {
-    DEBMSG("Camera module");
-    NEWLINE();
-    DEBMSG("Resetting...");
-    NEWLINE();
-    wait(1);
+    mkdir("/fs/mydir", 0777);
+    
+    FILE *fp = fopen("/fs/mydir/sdtest.txt", "w");
+    if(fp == NULL) {
+        error("Could not open file for write\n");
+    }
+    fprintf(fp, "Hello fun SD Card World!");
+    fclose(fp); 
  
-    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++;
-    }
-}
\ No newline at end of file
+    printf("Goodbye World!\n");
+    return 0;*/
+}
diff -r 31be9011f67e -r 7e547bf0f166 mbed.bld
--- a/mbed.bld	Fri Oct 10 21:48:33 2014 +0000
+++ b/mbed.bld	Tue Jul 21 05:06:05 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file