![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ハイパー・マイコン mbedでインターネット 電子工作 6章 リスト6-1 Camera-XBeeWifi のプログラム
Dependencies: CameraC1098 TextLCD mbed
main.cpp@0:c9cd08c93546, 2014-07-13 (annotated)
- Committer:
- sunifu
- Date:
- Sun Jul 13 12:47:06 2014 +0000
- Revision:
- 0:c9cd08c93546
2014.07.13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:c9cd08c93546 | 1 | /** |
sunifu | 0:c9cd08c93546 | 2 | * CameraXBeeWifi program. |
sunifu | 0:c9cd08c93546 | 3 | * |
sunifu | 0:c9cd08c93546 | 4 | * CameraC328Library |
sunifu | 0:c9cd08c93546 | 5 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
sunifu | 0:c9cd08c93546 | 6 | * http://shinta.main.jp/ |
sunifu | 0:c9cd08c93546 | 7 | * |
sunifu | 0:c9cd08c93546 | 8 | * CameraC1098-SS Library |
sunifu | 0:c9cd08c93546 | 9 | * Copyright (C) 2012 Tadao Iida |
sunifu | 0:c9cd08c93546 | 10 | */ |
sunifu | 0:c9cd08c93546 | 11 | |
sunifu | 0:c9cd08c93546 | 12 | #include "mbed.h" |
sunifu | 0:c9cd08c93546 | 13 | #include "CameraC1098.h" |
sunifu | 0:c9cd08c93546 | 14 | #include "TextLCD.h" |
sunifu | 0:c9cd08c93546 | 15 | |
sunifu | 0:c9cd08c93546 | 16 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
sunifu | 0:c9cd08c93546 | 17 | |
sunifu | 0:c9cd08c93546 | 18 | CameraC1098 camera(p9, p10); |
sunifu | 0:c9cd08c93546 | 19 | |
sunifu | 0:c9cd08c93546 | 20 | Serial xbeewifi(p13,p14); |
sunifu | 0:c9cd08c93546 | 21 | |
sunifu | 0:c9cd08c93546 | 22 | /** |
sunifu | 0:c9cd08c93546 | 23 | * A callback function for jpeg images. |
sunifu | 0:c9cd08c93546 | 24 | * You can block this function until saving the image datas. |
sunifu | 0:c9cd08c93546 | 25 | * |
sunifu | 0:c9cd08c93546 | 26 | * @param buf A pointer to the image buffer. |
sunifu | 0:c9cd08c93546 | 27 | * @param siz A size of the image buffer. |
sunifu | 0:c9cd08c93546 | 28 | */ |
sunifu | 0:c9cd08c93546 | 29 | void jpeg_callback(char *buf, size_t siz) { |
sunifu | 0:c9cd08c93546 | 30 | |
sunifu | 0:c9cd08c93546 | 31 | for (int i = 0; i < (int)siz; i++) { |
sunifu | 0:c9cd08c93546 | 32 | xbeewifi.putc(buf[i]) ; |
sunifu | 0:c9cd08c93546 | 33 | } |
sunifu | 0:c9cd08c93546 | 34 | |
sunifu | 0:c9cd08c93546 | 35 | } |
sunifu | 0:c9cd08c93546 | 36 | |
sunifu | 0:c9cd08c93546 | 37 | void sync(void) { |
sunifu | 0:c9cd08c93546 | 38 | CameraC1098::ErrorNumber err = CameraC1098::NoError; |
sunifu | 0:c9cd08c93546 | 39 | |
sunifu | 0:c9cd08c93546 | 40 | err = camera.sync(); |
sunifu | 0:c9cd08c93546 | 41 | lcd.locate(0,0); |
sunifu | 0:c9cd08c93546 | 42 | if (CameraC1098::NoError == err) { |
sunifu | 0:c9cd08c93546 | 43 | printf("[ OK ] : CameraC1098::sync\r\n"); |
sunifu | 0:c9cd08c93546 | 44 | lcd.printf("Camera Sync [OK]"); |
sunifu | 0:c9cd08c93546 | 45 | } else { |
sunifu | 0:c9cd08c93546 | 46 | printf("[FAIL] : CameraC1098::sync (Error=%02X)\r\n", (int)err); |
sunifu | 0:c9cd08c93546 | 47 | lcd.printf("Camera init [NG]"); |
sunifu | 0:c9cd08c93546 | 48 | } |
sunifu | 0:c9cd08c93546 | 49 | } |
sunifu | 0:c9cd08c93546 | 50 | |
sunifu | 0:c9cd08c93546 | 51 | void test_jpeg_snapshot_picture(void) { |
sunifu | 0:c9cd08c93546 | 52 | CameraC1098::ErrorNumber err = CameraC1098::NoError; |
sunifu | 0:c9cd08c93546 | 53 | |
sunifu | 0:c9cd08c93546 | 54 | err = camera.getJpegSnapshotPicture(jpeg_callback); |
sunifu | 0:c9cd08c93546 | 55 | |
sunifu | 0:c9cd08c93546 | 56 | lcd.locate(0,0); |
sunifu | 0:c9cd08c93546 | 57 | if (CameraC1098::NoError == err) { |
sunifu | 0:c9cd08c93546 | 58 | printf("[ OK ] : CameraC1098::getJpegSnapshotPicture\r\n"); |
sunifu | 0:c9cd08c93546 | 59 | lcd.printf("Camera send [OK]"); |
sunifu | 0:c9cd08c93546 | 60 | } else { |
sunifu | 0:c9cd08c93546 | 61 | printf("[FAIL] : CameraC1098::getJpegSnapshotPicture (Error=%02X)\r\n", (int)err); |
sunifu | 0:c9cd08c93546 | 62 | lcd.printf("Camera send [NG]"); |
sunifu | 0:c9cd08c93546 | 63 | } |
sunifu | 0:c9cd08c93546 | 64 | } |
sunifu | 0:c9cd08c93546 | 65 | |
sunifu | 0:c9cd08c93546 | 66 | int main() { |
sunifu | 0:c9cd08c93546 | 67 | |
sunifu | 0:c9cd08c93546 | 68 | wait(2.0) ; |
sunifu | 0:c9cd08c93546 | 69 | |
sunifu | 0:c9cd08c93546 | 70 | printf("\r\n"); |
sunifu | 0:c9cd08c93546 | 71 | printf("==========\r\n"); |
sunifu | 0:c9cd08c93546 | 72 | printf("CameraC1098\r\n"); |
sunifu | 0:c9cd08c93546 | 73 | printf("==========\r\n"); |
sunifu | 0:c9cd08c93546 | 74 | CameraC1098::ErrorNumber err = CameraC1098::NoError; |
sunifu | 0:c9cd08c93546 | 75 | |
sunifu | 0:c9cd08c93546 | 76 | err = camera.init(CameraC1098::Baud230400, CameraC1098::JpegResolution320x240); |
sunifu | 0:c9cd08c93546 | 77 | |
sunifu | 0:c9cd08c93546 | 78 | camera.setmbedBaud( CameraC1098::Baud230400 ); |
sunifu | 0:c9cd08c93546 | 79 | |
sunifu | 0:c9cd08c93546 | 80 | xbeewifi.baud(230400); |
sunifu | 0:c9cd08c93546 | 81 | |
sunifu | 0:c9cd08c93546 | 82 | lcd.locate(0,0); |
sunifu | 0:c9cd08c93546 | 83 | |
sunifu | 0:c9cd08c93546 | 84 | if (CameraC1098::NoError == err) { |
sunifu | 0:c9cd08c93546 | 85 | printf("[ OK ] : CameraC1098::init\r\n") ; |
sunifu | 0:c9cd08c93546 | 86 | lcd.printf("Camera init [OK]"); |
sunifu | 0:c9cd08c93546 | 87 | } else { |
sunifu | 0:c9cd08c93546 | 88 | printf("[FAIL] : CameraC1098::init (Error=%02X)\r\n", (int)err) ; |
sunifu | 0:c9cd08c93546 | 89 | lcd.printf("Camera init [NG]"); |
sunifu | 0:c9cd08c93546 | 90 | exit(-1); |
sunifu | 0:c9cd08c93546 | 91 | } |
sunifu | 0:c9cd08c93546 | 92 | |
sunifu | 0:c9cd08c93546 | 93 | sync(); |
sunifu | 0:c9cd08c93546 | 94 | |
sunifu | 0:c9cd08c93546 | 95 | while(1){ |
sunifu | 0:c9cd08c93546 | 96 | lcd.locate(0,1); |
sunifu | 0:c9cd08c93546 | 97 | lcd.printf("pictshort "); |
sunifu | 0:c9cd08c93546 | 98 | test_jpeg_snapshot_picture(); |
sunifu | 0:c9cd08c93546 | 99 | } |
sunifu | 0:c9cd08c93546 | 100 | } |