Go Down

Topic: Code of a camera ! (Read 454 times) previous topic - next topic

stribuda

I have a camera and i wana program it , but i don't understand very well the code so can you explain me this ?
Code: [Select]
/* Linksprite : the name of camera */

#include <NewSoftSerial.h>

byte incomingbyte;                  // what is this ?
NewSoftSerial mySerial(4,5);     //Configure pin 4 and 5 as soft serial port   , so for arduino leonardo i have to write "mySerial(0,1)" because tx>pin 0 and rx>pin 1
int a=0x0000,j=0,k=0,count=0;                    //Read Starting address     ,  what is this to ?
uint8_t MH,ML;                      // what is this ?
boolean EndFlag=0;                 // this is for test no ?
                               
void SendResetCmd();              // this is functions who is declared in <NewSoftSerial.h> ?
void SendTakePhotoCmd();        // what's their functions ?
void SendReadDataCmd();
void StopTakePhotoCmd();

void setup()
{
  Serial.begin(19200);                   // can i write "Serial.begin(9600);" ?
  mySerial.begin(38400);               
}

void loop()
{
     SendResetCmd();
     delay(4000);                               //After reset, wait 2-3 second to send take picture command
     
      SendTakePhotoCmd();

     while(mySerial.available()>0)
      {
        incomingbyte=mySerial.read();

      }   
      byte a[32];  // what does that mean ?
     
      while(!EndFlag)       // what does that mean ?
      { 
         j=0;
         k=0;
         count=0;
         SendReadDataCmd();

         delay(25);
          while(mySerial.available()>0)
          {
               incomingbyte=mySerial.read();
               k++;
               if((k>5)&&(j<32)&&(!EndFlag))
               {
               a[j]=incomingbyte;
               if((a[j-1]==0xFF)&&(a[j]==0xD9))      //Check if the picture is over
               EndFlag=1;                           
               j++;
       count++;
               }
          }
         
          for(j=0;j<count;j++)
          {   if(a[j]<0x10)
              Serial.print("0");
              Serial.print(a[j],HEX);
              Serial.print(" ");
          }                                       //Send jpeg picture over the serial port
          Serial.println();
      }     
     while(1);
}

//Send Reset command
void SendResetCmd()
{
      mySerial.print(0x56, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x26, BYTE);
      mySerial.print(0x00, BYTE);
}

//Send take picture command
void SendTakePhotoCmd()
{
      mySerial.print(0x56, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x36, BYTE);
      mySerial.print(0x01, BYTE);
      mySerial.print(0x00, BYTE); 
}

//Read data
void SendReadDataCmd()
{
      MH=a/0x100;
      ML=a%0x100;
      mySerial.print(0x56, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x32, BYTE);
      mySerial.print(0x0c, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x0a, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(MH, BYTE);
      mySerial.print(ML, BYTE);   
      mySerial.print(0x00, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x20, BYTE);
      mySerial.print(0x00, BYTE); 
      mySerial.print(0x0a, BYTE);
      a+=0x20;                            //address increases 32£¬set according to buffer size
}

void StopTakePhotoCmd()
{
      mySerial.print(0x56, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x36, BYTE);
      mySerial.print(0x01, BYTE);
      mySerial.print(0x03, BYTE);       
}


PS : i know that BYTE is not supported  so i hate to change for example mySerial.print(0x56, BYTE); to mySerial.write(0x56);
Please help me i have to finish this project quickly .
Thanks.

PaulS

Quote
but i don't understand very well the code so can you explain me this ?

The function names seem pretty self-explanatory. You need to ask more specific questions than that.

Quote
Please help me i have to finish this project quickly .

Should have started sooner, eh?

Quote
i wana program it

i wana have you use proper capitalization and to spell words correctly.

PeterH


Please help me i have to finish this project quickly .


Many of the questions commented in that code refer to straight forward C++ statements, so I suggest you start with a basic C++ tutorial.

Given the current level of understanding implied by all those questions, I'd suggest you aren't going to finish this quickly without a lot of help.
I only provide help via the forum - please do not contact me for private consultancy.

mistergreen

Better to ask the manufacture of the camera. A lot of the code is product specific it seems.

Go Up