Pages: [1]   Go Down
Author Topic: Radio Shack Camera Shield camsd.pde sketch - writing jpeg files to a SD  (Read 1529 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anyone know how to modify this sketch so the camera auto increments the file name by 1 instead of replacing the "temp.jpg" with the same name? (The sketch below is only a portion of the total sketch. It's the part that writes the file).

I would like the camera to capture: "temp1.jpg, temp2.jpg, temp3.jpg..." and so on. The camera script detects motion, and then snaps a new shot - which is great. However, I would like to see all of the shots in progression versus the way it works now -- by replacing the last photo with the most recent photo under the same file name.

#ifdef sdCamera

/*******************************************************************************
 * Function Name  : capture_photo
 * Description     : capture a photo and store the file named temp.jpg into SD
 *               
 * Input        : None
 *               
 * Output        : None
 * Return        : None
 *******************************************************************************/
void capture_photo(){   
   
   // Check to see if the file exists:
   // if exists,delete the file:
   if(sd.exists("temp.jpg")) sd.remove("temp.jpg");
      
   // open a new empty file for write at end like the Native SD library
    if (!myFile.open("temp.jpg", O_RDWR | O_CREAT | O_AT_END)) {
      sd.errorHalt("opening temp.jpg for write failed");
       }
   
   // close the file:
    myFile.close();

   VC0706_compression_ratio(63);
   delay(100);

   VC0706_frame_control(3);
   delay(10);
   
   VC0706_frame_control(0);
   delay(10);
   rx_ready=false;
   rx_counter=0;
   
   Serial.end();         // clear all rx buffer
   delay(5);
   
   Serial.begin(115200);

   //get frame buffer length
   VC0706_get_framebuffer_length(0);
   delay(10);
   buffer_read();

   //while(1){};
   
   // store frame buffer length for coming reading
   frame_length=(VC0706_rx_buffer[5]<<smiley-cool+VC0706_rx_buffer[6];
   frame_length=frame_length<<16;
   frame_length=frame_length+(0x0ff00&(VC0706_rx_buffer[7]<<smiley-cool)+VC0706_rx_buffer[8];

   vc_frame_address =READ_DATA_BLOCK_NO;
      
   myFile.open("temp.jpg", O_RDWR);   
   while(vc_frame_address<frame_length){   
      VC0706_read_frame_buffer(vc_frame_address-READ_DATA_BLOCK_NO, READ_DATA_BLOCK_NO);
      delay(9);

      //get the data with length=READ_DATA_BLOCK_NObytes
      rx_ready=false;
      rx_counter=0;
      buffer_read();

      // write data to temp.jpg
      myFile.write(VC0706_rx_buffer+5,READ_DATA_BLOCK_NO);
   
      //read next READ_DATA_BLOCK_NO bytes from frame buffer
      vc_frame_address=vc_frame_address+READ_DATA_BLOCK_NO;
   
      }

   // get the last data
   vc_frame_address=vc_frame_address-READ_DATA_BLOCK_NO;

   last_data_length=frame_length-vc_frame_address;

   
   VC0706_read_frame_buffer(vc_frame_address,last_data_length);
   delay(9);
   //get the data
   rx_ready=false;
   rx_counter=0;
   buffer_read();
         
   myFile.write(VC0706_rx_buffer+5,last_data_length);
   
   myFile.close();

}

#endif
« Last Edit: March 11, 2013, 10:40:50 pm by runpilotfish » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does anyone know how to modify this sketch so the camera auto increments the file name by 1 instead of replacing the "temp.jpg" with the same name? (The sketch below is only a portion of the total sketch. It's the part that writes the file).
Sure. Replace this:
Code:
   // Check to see if the file exists:
   // if exists,delete the file:
   if(sd.exists("temp.jpg")) sd.remove("temp.jpg");
     
   // open a new empty file for write at end like the Native SD library
    if (!myFile.open("temp.jpg", O_RDWR | O_CREAT | O_AT_END)) {
With code that does what you want.

sprintf() might prove useful. Some global variable added to that snippet might be useful.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. I figured thats the part of the code to fix. Just don't know how. There's not a lot of good info out there on auto-incrementing file names for Arduino. Most of the examples I've seen are part of a larger, much more complex application.
Logged

Pages: [1]   Go Up
Jump to: