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]<<8)+VC0706_rx_buffer[6];
frame_length=frame_length<<16;
frame_length=frame_length+(0x0ff00&(VC0706_rx_buffer[7]<<8))+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