エレキジャック Web版 マイコン・カーを製作してみよう<21> マイコンカー制御プログラムです。http://www.eleki-jack.com/arm/2012/10/21.html このプログラムは次回の記事でアップされるパソコン用プログラムを使ってマイコンカーを制御するプログラムです。マイコンカーとパソコンの通信はXbeeを使っています。
Revision 2:9758930faa7e, committed 2012-05-06
- Comitter:
- sunifu
- Date:
- Sun May 06 09:43:28 2012 +0000
- Parent:
- 1:8f2a9b48a9e0
- Child:
- 3:ba97046adcd1
- Commit message:
- 0.0.9
Changed in this revision
CameraC1098.cpp | 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 |
--- a/CameraC1098.cpp Sat May 05 15:04:33 2012 +0000 +++ b/CameraC1098.cpp Sun May 06 09:43:28 2012 +0000 @@ -68,39 +68,22 @@ int i ; ErrorNumber en; WAITIDLE(); - for ( i = 0x02 ; i <= 0x07 ; i++ ) { - sendAck(0x0D, 0x00); - en = sendInitial((Baud)i, jr); - wait_ms(50) ; - if (NoError == en) { - if (NoError == sendSync()) { - if (NoError == recvAckOrNck()) { - if (NoError == recvSync()) { - if (NoError == sendAck(0x0D, 0x00)) { - /* - * After synchronization, the camera needs a little time for AEC and AGC to be stable. - * Users should wait for 1-2 seconds before capturing the first picture. - */ - wait(2); - return NoError; - } - } - } - } - wait_ms(50); - } - } - /* - for (int i = 0; i < SYNCMAX; i++) { - if (NoError == sendSync()) { - if (NoError == recvAckOrNck()) { - if (NoError == recvSync()) { - if (NoError == sendAck(0x0D, 0x00)) { - WAITFUNC(); - en = recvAckOrNck(); - if (NoError != en) { - return en; - } + setmbedBaud((Baud)(0x07)) ; + + for ( i = 1 ; i < 7 ; i++ ) { + if ( NoError == sendSync() ) { + if ( NoError == recvAckOrNck() ){ + if ( NoError == recvSync() ) { + if ( NoError == sendAck(0x0D, 0x00) ) { + en = sendInitial(baud,jr); + if (NoError != en) { + return en; + } + en = recvAckOrNck(); + if (NoError != en) { + return en; + } + wait_ms(50) ; static bool alreadySetupPackageSize = false; if (!alreadySetupPackageSize) { en = sendSetPackageSize(packageSize); @@ -114,16 +97,22 @@ } alreadySetupPackageSize = true; } - return (ErrorNumber)NoError; + setmbedBaud(baud); + wait(2.0); + return (ErrorNumber)NoError; + /* + * After synchronization, the camera needs a little time for AEC and AGC to be stable. + * Users should wait for 1-2 seconds before capturing the first picture. + */ } - } + } + }else{ + setmbedBaud((Baud)(i+1)) ; } } - wait_ms(50); - } - */ + wait_ms(50); + } return UnexpectedReply; - } @@ -138,6 +127,7 @@ WAITIDLE(); ErrorNumber en; + en = sendSnapshot(); if (NoError != en) { return en; @@ -245,16 +235,15 @@ send[0] = 0xAA; send[1] = 0x01; - send[2] = (int)baud; + send[2] = (char)baud; send[3] = 0x07; send[4] = 0x00; send[5] = (char)jr; if (!SENDFUNC(send, sizeof(send))) { - printf("SendInitial SendRegisterTimeout\r\n"); return (ErrorNumber)SendRegisterTimeout; } - printf("SendInitial NoError Baud[%X] Jr[%d]\r\n",baud,jr); + return (ErrorNumber)NoError; } @@ -325,9 +314,8 @@ serial.baud(14400); break; default: - serial.baud(14400); + serial.baud(14400); } - } @@ -359,7 +347,7 @@ if ((0xAA != recv[0]) || (0x0A != recv[1])) { return (ErrorNumber)UnexpectedReply; } - recv[2] = 0x01; + recv[2] = (char)0x01; *length = (recv[5] << 16) | (recv[4] << 8) | (recv[3] << 0); return (ErrorNumber)NoError; } @@ -375,10 +363,9 @@ if (!SENDFUNC(send, sizeof(send))) { - printf("SendSync Error\r\n"); return (ErrorNumber)SendRegisterTimeout; } - printf("SendSync NoError\r\n"); + return (ErrorNumber)NoError; } @@ -386,14 +373,12 @@ char recv[COMMAND_LENGTH]; if (!RECVFUNC(recv, sizeof(recv))) { - printf("RecvSync UnexpectedReply [0]\r\n"); return (ErrorNumber)UnexpectedReply; } if ((0xAA != recv[0]) || (0x0D != recv[1])) { - printf("RecvSync UnexpectedReply [1]\r\n"); return (ErrorNumber)UnexpectedReply; } - printf("RecvSync NoError \r\n"); + return (ErrorNumber)NoError; } @@ -405,7 +390,7 @@ */ CameraC1098::ErrorNumber CameraC1098::sendAck(uint8_t commandId, uint16_t packageId) { char send[COMMAND_LENGTH]; - printf("Send Ack\r\n"); + send[0] = 0xAA; send[1] = 0x0E; send[2] = commandId; @@ -427,18 +412,18 @@ char recv[COMMAND_LENGTH]; if (!RECVFUNC(recv, sizeof(recv))) { - printf("RecvAckOrNck UnexpecterReply [0]\r\n"); return (ErrorNumber)UnexpectedReply; } if ((0xAA == recv[0]) && (0x0E == recv[1])) { - printf("RecvAckOrNck NoError\r\n"); return (ErrorNumber)NoError; } + if ((0xAA == recv[0]) && (0x0F == recv[1]) && (0x00 == recv[2])) { + return (ErrorNumber)NoError; + } if ((0xAA == recv[0]) && (0x0F == recv[1])) { - printf("RecvAckOrNck ErrorCode[%d] \r\n",recv[4]); return (ErrorNumber)recv[4]; } - printf("RecvAckOrNck UnexpecterReply [1]\r\n"); + return (ErrorNumber)UnexpectedReply; }
--- a/main.cpp Sat May 05 15:04:33 2012 +0000 +++ b/main.cpp Sun May 06 09:43:28 2012 +0000 @@ -23,8 +23,8 @@ * Variables. */ static const int CAPTURE_FRAMES = 3; -static const int RAWIMG_X = 80; -static const int RAWIMG_Y = 64; +static const int RAWIMG_X = 320; +static const int RAWIMG_Y = 240; static char buf[RAWIMG_X * RAWIMG_Y * 2]; static FILE *fp_jpeg; @@ -94,15 +94,11 @@ */ int main() { printf("\r\n"); - printf("==========\r\n"); + printf("==========\r\n"); printf("CameraC1098\r\n"); printf("==========\r\n"); - // Camera Reset - //sync(); CameraC1098::ErrorNumber err = CameraC1098::NoError; - camera.setmbedBaud(CameraC1098::Baud14400); - err = camera.init(CameraC1098::Baud14400, CameraC1098::JpegResolution640x480); - + err = camera.init(CameraC1098::Baud460800, CameraC1098::JpegResolution160x128); if (CameraC1098::NoError == err) { printf("[ OK ] : CameraC1098::init\r\n"); @@ -110,8 +106,8 @@ printf("[FAIL] : CameraC1098::init (Error=%02X)\r\n", (int)err); } // - - //test_jpeg_snapshot_picture(); + sync(); + test_jpeg_snapshot_picture(); return 0; }