Tips: Show a jpg from storage such as SD

This is a simple example to show jpg on display app.

 

#include <Arduino.h>
#include <DisplayApp.h>
#include "SdUsbConnect.h"

DisplayApp display_app;
SdUsbConnect storage("storage");

void setup() {
Serial.begin(9600);
pinMode(PIN_LED_RED, OUTPUT);
pinMode(PIN_LED_GREEN, OUTPUT);
pinMode(PIN_LED_BLUE, OUTPUT);

Serial.println("Test starts");

// SD & USB
Serial.print("Finding strage..");
storage.wait_connect();
Serial.println("done");

}

void loop() {
FILE * fp = fopen("/storage/faceimg.jpg", "r");
if (fp != NULL) {
digitalWrite(PIN_LED_GREEN, HIGH);
fseek(fp, 0, SEEK_END);
uint32_t jpegSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
uint8_t * buffer = (uint8_t*) malloc (jpegSize);
for(uint32_t i = 0; i < jpegSize; i++){
buffer[i] = (uint8_t)fgetc(fp);
}
display_app.SendJpeg(buffer, jpegSize);
fclose (fp);
digitalWrite(PIN_LED_GREEN, LOW);
} else {
Serial.print("Not found jpg");
digitalWrite(PIN_LED_RED, HIGH);
delay(1);
}
}