エレキジャック Web版 マイコン・カーを製作してみよう<21> マイコンカー制御プログラムです。http://www.eleki-jack.com/arm/2012/10/21.html  このプログラムは次回の記事でアップされるパソコン用プログラムを使ってマイコンカーを制御するプログラムです。マイコンカーとパソコンの通信はXbeeを使っています。

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
sunifu
Date:
Tue May 08 11:20:33 2012 +0000
Parent:
4:887ced27d5d6
Child:
6:2ce8f719d84d
Commit message:
0.9.5

Changed in this revision

CameraC1098/CameraC1098.cpp Show annotated file Show diff for this revision Revisions of this file
CameraC1098/CameraC1098.h Show annotated file Show diff for this revision Revisions of this file
CameraC1098/SerialBuffered.cpp Show annotated file Show diff for this revision Revisions of this file
CameraC1098/SerialBuffered.h 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/CameraC1098.cpp	Mon May 07 05:57:12 2012 +0000
+++ b/CameraC1098/CameraC1098.cpp	Tue May 08 11:20:33 2012 +0000
@@ -24,8 +24,8 @@
  * @param rx A pin for receive.
  * @param baud Baud rate. (Default is Baud14400.)
  */
-CameraC1098::CameraC1098(PinName tx, PinName rx, Baud baud) : serial(tx, rx) {
-    serial.baud((int)baud);
+CameraC1098::CameraC1098(PinName tx, PinName rx, int baud) : serial(tx, rx) {
+    serial.baud(baud);
 }
 
 /**
@@ -77,21 +77,19 @@
                     if ( NoError == sendAck(0x0D, 0x00) ) {
                         en = sendInitial(baud,jr);
                         if (NoError != en) {
-                            printf("sendInitalError\r\n");
                             return en;
                         }    
-                        printf("sendInital OK\r\n");
                         en = recvAckOrNck();
                         if (NoError != en) {
-                            printf("recvAckOrNckError\r\n");
                             return en;
                         }      
-                        wait_ms(50) ;    
+                        wait_ms(50) ;
+                        setmbedBaud(baud);   
+                        //wait_ms(50) ; 
                         static bool alreadySetupPackageSize = false;
                         if (!alreadySetupPackageSize) {
                             en = sendSetPackageSize(packageSize);
                             if (NoError != en) {
-                                printf("sendSetPackageSizeError\r\n");
                                 return en;
                             }
                             WAITFUNC();
@@ -101,7 +99,7 @@
                             }
                             alreadySetupPackageSize = true;
                         }
-                        setmbedBaud(baud);
+                        
                         wait(2.0);
                         return (ErrorNumber)NoError;                                                                 
                        /*
@@ -300,25 +298,25 @@
 void CameraC1098::setmbedBaud(Baud baud){
     switch((int)baud){
     case 2:
-        serial.baud(460800);
+        serial._baud(460800);
         break;
     case 3:
-        serial.baud(230400);
+        serial._baud(230400);
         break;
     case 4:
-        serial.baud(115200);
+        serial._baud(115200);
         break;
     case 5:
-        serial.baud(57600);
+        serial._baud(57600);
         break;
     case 6:
-        serial.baud(28800);
+        serial._baud((int)28800);
         break;
     case 7:
-        serial.baud(14400);
+        serial._baud(14400);
         break;    
     default:
-        serial.baud(14400);  
+        serial._baud(14400);  
     }
 }
 
@@ -369,7 +367,6 @@
     if (!SENDFUNC(send, sizeof(send))) {
         return (ErrorNumber)SendRegisterTimeout;
     }
-
     return (ErrorNumber)NoError;
 }
 
@@ -377,14 +374,11 @@
     char recv[COMMAND_LENGTH];
     
     if (!RECVFUNC(recv, sizeof(recv))) {
-        printf("recvSync UnexpectedReply0\r\n");
         return (ErrorNumber)UnexpectedReply;
     }
     if ((0xAA != recv[0]) || (0x0D != recv[1])) {
-        printf("recvSync UnexpectedReply1\r\n");
         return (ErrorNumber)UnexpectedReply;
     }
-    printf("recvSync NoError\r\n");
     return (ErrorNumber)NoError;
 }
 
@@ -418,22 +412,17 @@
     char recv[COMMAND_LENGTH];
         
     if (!RECVFUNC(recv, sizeof(recv))) {
-    printf("recvAckOrNck UnexpectedReply0\r\n");
         return (ErrorNumber)UnexpectedReply;
     }
     if ((0xAA == recv[0]) && (0x0E == recv[1])) {
-        printf("recvAckOrNck\r\n");
         return (ErrorNumber)NoError;
     }
     if ((0xAA == recv[0]) && (0x0F == recv[1]) && (0x00 == recv[2])) {
-        printf("recvAckOrNck\r\n");
         return (ErrorNumber)NoError;
     }    
     if ((0xAA == recv[0]) && (0x0F == recv[1])) {
-        printf("recvAckOrNck Error[%02x]\r\n",recv[4]);
         return (ErrorNumber)recv[4];
     }
-    printf("recvAckOrNck UnexpectedReply1\r\n");
     return (ErrorNumber)UnexpectedReply;
 }
 
--- a/CameraC1098/CameraC1098.h	Mon May 07 05:57:12 2012 +0000
+++ b/CameraC1098/CameraC1098.h	Tue May 08 11:20:33 2012 +0000
@@ -70,9 +70,9 @@
      *
      * @param tx A pin for transmit.
      * @param rx A pin for receive.
-     * @param baud Baud rate. (Default is Baud14400.)
+     * @param baud Baud rate. (Default is 14400.)
      */
-    CameraC1098(PinName tx, PinName rx, Baud baud = Baud14400);
+    CameraC1098(PinName tx, PinName rx, int baud = 14400);
 
     /** Destructor.
      * 
--- a/CameraC1098/SerialBuffered.cpp	Mon May 07 05:57:12 2012 +0000
+++ b/CameraC1098/SerialBuffered.cpp	Tue May 08 11:20:33 2012 +0000
@@ -97,3 +97,7 @@
         }
     }
 }
+
+void SerialBuffered::_baud(int b) {
+    Serial::baud(b);
+}    
--- a/CameraC1098/SerialBuffered.h	Mon May 07 05:57:12 2012 +0000
+++ b/CameraC1098/SerialBuffered.h	Tue May 08 11:20:33 2012 +0000
@@ -48,6 +48,7 @@
      */
     size_t readBytes(uint8_t *bytes, size_t requested);
 
+    void _baud(int b);
 private:
     void handleInterrupt();
     static const int BUFFERSIZE = 4096;
--- a/main.cpp	Mon May 07 05:57:12 2012 +0000
+++ b/main.cpp	Tue May 08 11:20:33 2012 +0000
@@ -26,7 +26,7 @@
  * Variables.
  */
 static const int CAPTURE_FRAMES = 3;
-static char buf[256+1];
+static char buf[1024+1];
 static FILE *fp_jpeg;
 
 /*
@@ -102,13 +102,13 @@
     err = camera.init(CameraC1098::Baud28800, CameraC1098::JpegResolution80x64);
   
     if (CameraC1098::NoError == err) {
-        printf("[ OK ] : CameraC1098::init\r\n");
+        printf("[ OK ] : CameraC1098::init\r\n") ;
     } else {
-        printf("[FAIL] : CameraC1098::init (Error=%02X)\r\n", (int)err);
+        printf("[FAIL] : CameraC1098::init (Error=%02X)\r\n", (int)err) ;
     }
     // 
-    //sync();
-    //test_jpeg_snapshot_picture();
+    sync();
+    test_jpeg_snapshot_picture();
     
     return 0;
 }