![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
3.3[V]で動作するJpegシリアルカメラ(C1098-SS( http://www.silentsystem.jp/c1098.htm ))のサンプルプログラムです。
main.cpp@0:0482779cd78e, 2012-05-08 (annotated)
- Committer:
- sunifu
- Date:
- Tue May 08 13:52:50 2012 +0000
- Revision:
- 0:0482779cd78e
v 0.9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:0482779cd78e | 1 | /** |
sunifu | 0:0482779cd78e | 2 | * Test program. |
sunifu | 0:0482779cd78e | 3 | * |
sunifu | 0:0482779cd78e | 4 | * CameraC328Library |
sunifu | 0:0482779cd78e | 5 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
sunifu | 0:0482779cd78e | 6 | * http://shinta.main.jp/ |
sunifu | 0:0482779cd78e | 7 | * |
sunifu | 0:0482779cd78e | 8 | * CameraC1098-SS Library |
sunifu | 0:0482779cd78e | 9 | * Copyright (C) 2012 Tadao Iida |
sunifu | 0:0482779cd78e | 10 | */ |
sunifu | 0:0482779cd78e | 11 | |
sunifu | 0:0482779cd78e | 12 | /* |
sunifu | 0:0482779cd78e | 13 | * Include files. |
sunifu | 0:0482779cd78e | 14 | */ |
sunifu | 0:0482779cd78e | 15 | |
sunifu | 0:0482779cd78e | 16 | #include "mbed.h" |
sunifu | 0:0482779cd78e | 17 | #include "CameraC1098.h" |
sunifu | 0:0482779cd78e | 18 | #include "SDFileSystem.h" |
sunifu | 0:0482779cd78e | 19 | |
sunifu | 0:0482779cd78e | 20 | /* |
sunifu | 0:0482779cd78e | 21 | * Definitions. |
sunifu | 0:0482779cd78e | 22 | */ |
sunifu | 0:0482779cd78e | 23 | #define USE_JPEG_HIGH_RESOLUTION 1 |
sunifu | 0:0482779cd78e | 24 | #define USE_SD_CARD 1 |
sunifu | 0:0482779cd78e | 25 | |
sunifu | 0:0482779cd78e | 26 | /* |
sunifu | 0:0482779cd78e | 27 | * Variables. |
sunifu | 0:0482779cd78e | 28 | */ |
sunifu | 0:0482779cd78e | 29 | static const int CAPTURE_FRAMES = 3; |
sunifu | 0:0482779cd78e | 30 | static char buf[256+1]; |
sunifu | 0:0482779cd78e | 31 | static FILE *fp_jpeg; |
sunifu | 0:0482779cd78e | 32 | |
sunifu | 0:0482779cd78e | 33 | /* |
sunifu | 0:0482779cd78e | 34 | * Modules. |
sunifu | 0:0482779cd78e | 35 | */ |
sunifu | 0:0482779cd78e | 36 | #if USE_SD_CARD |
sunifu | 0:0482779cd78e | 37 | SDFileSystem sd(p5, p6, p7, p8, "fs"); |
sunifu | 0:0482779cd78e | 38 | #else |
sunifu | 0:0482779cd78e | 39 | LocalFileSystem fs("fs"); |
sunifu | 0:0482779cd78e | 40 | #endif |
sunifu | 0:0482779cd78e | 41 | |
sunifu | 0:0482779cd78e | 42 | CameraC1098 camera(p9, p10); |
sunifu | 0:0482779cd78e | 43 | |
sunifu | 0:0482779cd78e | 44 | |
sunifu | 0:0482779cd78e | 45 | /** |
sunifu | 0:0482779cd78e | 46 | * A callback function for jpeg images. |
sunifu | 0:0482779cd78e | 47 | * You can block this function until saving the image datas. |
sunifu | 0:0482779cd78e | 48 | * |
sunifu | 0:0482779cd78e | 49 | * @param buf A pointer to the image buffer. |
sunifu | 0:0482779cd78e | 50 | * @param siz A size of the image buffer. |
sunifu | 0:0482779cd78e | 51 | */ |
sunifu | 0:0482779cd78e | 52 | void jpeg_callback(char *buf, size_t siz) { |
sunifu | 0:0482779cd78e | 53 | for (int i = 0; i < (int)siz; i++) { |
sunifu | 0:0482779cd78e | 54 | fprintf(fp_jpeg, "%c", buf[i]); |
sunifu | 0:0482779cd78e | 55 | } |
sunifu | 0:0482779cd78e | 56 | } |
sunifu | 0:0482779cd78e | 57 | |
sunifu | 0:0482779cd78e | 58 | /** |
sunifu | 0:0482779cd78e | 59 | * Synchronizing. |
sunifu | 0:0482779cd78e | 60 | */ |
sunifu | 0:0482779cd78e | 61 | void sync(void) { |
sunifu | 0:0482779cd78e | 62 | CameraC1098::ErrorNumber err = CameraC1098::NoError; |
sunifu | 0:0482779cd78e | 63 | |
sunifu | 0:0482779cd78e | 64 | err = camera.sync(); |
sunifu | 0:0482779cd78e | 65 | if (CameraC1098::NoError == err) { |
sunifu | 0:0482779cd78e | 66 | printf("[ OK ] : CameraC1098::sync\r\n"); |
sunifu | 0:0482779cd78e | 67 | } else { |
sunifu | 0:0482779cd78e | 68 | printf("[FAIL] : CameraC1098::sync (Error=%02X)\r\n", (int)err); |
sunifu | 0:0482779cd78e | 69 | } |
sunifu | 0:0482779cd78e | 70 | } |
sunifu | 0:0482779cd78e | 71 | |
sunifu | 0:0482779cd78e | 72 | |
sunifu | 0:0482779cd78e | 73 | /** |
sunifu | 0:0482779cd78e | 74 | * A test function for jpeg snapshot picture. |
sunifu | 0:0482779cd78e | 75 | */ |
sunifu | 0:0482779cd78e | 76 | void test_jpeg_snapshot_picture(void) { |
sunifu | 0:0482779cd78e | 77 | CameraC1098::ErrorNumber err = CameraC1098::NoError; |
sunifu | 0:0482779cd78e | 78 | for (int i = 0; i < CAPTURE_FRAMES; i++) { |
sunifu | 0:0482779cd78e | 79 | char fname[64]; |
sunifu | 0:0482779cd78e | 80 | snprintf(fname, sizeof(fname), "/fs/jpss%04d.jpg", i); |
sunifu | 0:0482779cd78e | 81 | fp_jpeg = fopen(fname, "w"); |
sunifu | 0:0482779cd78e | 82 | |
sunifu | 0:0482779cd78e | 83 | err = camera.getJpegSnapshotPicture(jpeg_callback); |
sunifu | 0:0482779cd78e | 84 | |
sunifu | 0:0482779cd78e | 85 | if (CameraC1098::NoError == err) { |
sunifu | 0:0482779cd78e | 86 | printf("[ OK ] : CameraC1098::getJpegSnapshotPicture\r\n"); |
sunifu | 0:0482779cd78e | 87 | } else { |
sunifu | 0:0482779cd78e | 88 | printf("[FAIL] : CameraC1098::getJpegSnapshotPicture (Error=%02X)\r\n", (int)err); |
sunifu | 0:0482779cd78e | 89 | } |
sunifu | 0:0482779cd78e | 90 | fclose(fp_jpeg); |
sunifu | 0:0482779cd78e | 91 | } |
sunifu | 0:0482779cd78e | 92 | } |
sunifu | 0:0482779cd78e | 93 | |
sunifu | 0:0482779cd78e | 94 | /** |
sunifu | 0:0482779cd78e | 95 | * A entry point. |
sunifu | 0:0482779cd78e | 96 | */ |
sunifu | 0:0482779cd78e | 97 | int main() { |
sunifu | 0:0482779cd78e | 98 | printf("\r\n"); |
sunifu | 0:0482779cd78e | 99 | printf("==========\r\n"); |
sunifu | 0:0482779cd78e | 100 | printf("CameraC1098\r\n"); |
sunifu | 0:0482779cd78e | 101 | printf("==========\r\n"); |
sunifu | 0:0482779cd78e | 102 | CameraC1098::ErrorNumber err = CameraC1098::NoError; |
sunifu | 0:0482779cd78e | 103 | err = camera.init(CameraC1098::Baud460800, CameraC1098::JpegResolution320x240); |
sunifu | 0:0482779cd78e | 104 | |
sunifu | 0:0482779cd78e | 105 | if (CameraC1098::NoError == err) { |
sunifu | 0:0482779cd78e | 106 | printf("[ OK ] : CameraC1098::init\r\n"); |
sunifu | 0:0482779cd78e | 107 | } else { |
sunifu | 0:0482779cd78e | 108 | printf("[FAIL] : CameraC1098::init (Error=%02X)\r\n", (int)err); |
sunifu | 0:0482779cd78e | 109 | } |
sunifu | 0:0482779cd78e | 110 | // |
sunifu | 0:0482779cd78e | 111 | sync(); |
sunifu | 0:0482779cd78e | 112 | test_jpeg_snapshot_picture(); |
sunifu | 0:0482779cd78e | 113 | |
sunifu | 0:0482779cd78e | 114 | return 0; |
sunifu | 0:0482779cd78e | 115 | } |