// A simple image slideshow which reads all the .JPG files from the root
// directory of a SD card and shows each for 1 second on an ILI9341 display.

#include <JPEGDEC.h>
#include <SD.h>

#define TFT_DC 9
#define TFT_CS 10

JPEGDEC jpeg;

// Setup - initialize ILI9341 display, wait for serial monitor, open SD card
void setup()
{
  Serial.begin(115200);


  while (!SD.begin())
  {
    Serial.println("Unable to access SD Card");
    delay(1000);
  }
}

// Functions to access a file on the SD card
File myfile;

// Function to draw pixels to the display
int JPEGDraw(JPEGDRAW *pDraw)
{
  Serial.printf("jpeg draw: x,y=%d,%d, cx,cy = %d,%d\n");
  // pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight);
  return 1;
}

// Main loop, scan for all .JPG files on the card and display them
void loop()
{
  int filecount = 0;
  File dir = SD.open("/");
 
        jpeg.openFLASH((uint8_t *)thumb_test, sizeof(thumb_test), JPEGDraw);
        Serial.println(jpeg.getLastError());
        jpeg.decode(0, 0, 0);
        jpeg.close();
        filecount = filecount + 1;
        if (digitalRead(34) == LOW)
        {
          // skip delay between images when pushbutton is pressed
          delay(1000);
        }

}