mentally challenged, please help with C pointer syntax

after many years, i know i’ll never get pointer syntax (or semantics either).

the (simplified) code is:

void loop() {
  camera_fb_t * fb = NULL;
  
  // Take Picture with Camera
  fb = esp_camera_fb_get();  

  String path = "/picture" + String(pictureNumber++) +".jpg";

  fs::FS &fs = SD_MMC; 
  
  File file = fs.open(path.c_str(), FILE_WRITE);
    file.write(fb->buf, fb->len); // payload (image), payload length

  file.close();  }

i want to designate 2 frame buffers (fb1, fb2) and the code will alternate with each iteration between them, so that the pointer fb will refer to fb1, next time refer to fb2, then to fb1, fb2 …

so under setup() it would say:
camera_fb_t * fb1 = NULL;
camera_fb_t * fb2 = NULL;

  • int x;*

and under loop() it would say:
_ fb = x++%2 * (pointer value fb1) + (1 - x%2) * (pointer value fb2)_// ← how do i write that?

thanx, mike

It's the folk who designed the syntax that were mentally challenged. :) :)

...R

My best guess on what you want:

void loop() {
  static camera_fb_t * fb1 = NULL;
  static camera_fb_t * fb2 = NULL;
  static bool Even = false;

  String path = "/picture" + String(pictureNumber++) +".jpg";
  fs::FS &fs = SD_MMC;
  File file = fs.open(path.c_str(), FILE_WRITE);

  // Take Picture with Camera
  if (Even)
  {
    fb1 = esp_camera_fb_get(); 
    file.write(fb1->buf, fb1->len); // payload (image), payload length
  }
  else
  {
    fb2 = esp_camera_fb_get(); 
    file.write(fb2->buf, fb2->len); // payload (image), payload length
  }
  Even = !Even; // Toggle

  file.close();  
}

I don't think you are going to get double-buffering. I suspect that the "camera_fb_t" pointer returned points to a single frame buffer inside the camera library. Both pointers will point to the same place.

DAMN your probably right. i was assuming that frame buffer was in host ram. in that case i would want to replace the each FILE.WRITE statement with a RAM.WRITE statement. the point is to compare each new photo with the previous photo. this is for motion detection. i'm gonna check that.... ok the camera document doesn't say anything about a buffer or internal memory. That implies that the frame buffer really is in host ram. the specs for the esp32cam device say 520k sram and 4M external psram. and the arduino console says that the code itself is 400k. "Sketch uses 407993 bytes (12%) of program storage space. Maximum is 3145728 bytes." so it seems that what you wrote will work without having to figure out the impossible syntax. in fact, i see a part in the code that says:

  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

so it has 2 alocated buffers already. Guess that's why the sketch uses 400k. anyway, problem solved. THANX, mike