Description
I’ve been following the documentation as I want to take a snapshot on device and save it to an SD card.
So far I’ve tried to use lv_snapshot_take
but it returns NULL all the time as there is not enough RAM in the region it is running in on the Teensy (RAM1)
So I tried to use lv_snapshot_take_to_buf
but the watchdog on the Teensy is resetting the device due to a null pointer.
Below is a function I wrote to take a snapshot and save it to SD.
I call it where I want to take a snapshot and pass the lv_scr_act() object to it to take a full screen snapshot.
Can anyone provide an example of how they used lv_snapshot_take_to_buf
to make sure i am using it correctly?
What MCU/Processor/Board and compiler are you using?
Teensy MicroMod (IMXRT1062)
What LVGL version are you using?
v8.1
Code to reproduce
#include "../lib/lvgl/lvgl.h"
#include "SdFat.h"
#include "Arduino.h"
SdFs sd;
FsFile file;
// Use Teensy SDIO
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// Size to log 10 byte lines at 25 kHz for more than ten minutes.
#define LOG_FILE_SIZE (480*320*3) // 480px * 320px * 3bytes per pixle
#define LOG_FILENAME "snapshot.c"
DMAMEM uint16_t buff[LOG_FILE_SIZE/2]; //Buffer in RAM2 to place the snapshot
lv_img_dsc_t * img;
void takeSnapshot(lv_obj_t * screenshot){
arm_dcache_flush((uint16_t*)buff, sizeof(buff)); // always flush cache after writing to DMAMEM variable that will be accessed by DMA
lv_res_t snap = lv_snapshot_take_to_buf(screenshot, LV_IMG_CF_TRUE_COLOR_ALPHA, img, &buff, sizeof(buff));
if (snap == LV_RES_INV){
Serial.println("Snapshot failed");
}
else{
// Initialize the SD.
if (!sd.begin(SD_CONFIG)) {
sd.initErrorHalt(&Serial);
}
// Open or create file - truncate existing file.
if (!file.open(LOG_FILENAME, O_RDWR | O_CREAT | O_TRUNC)) {
Serial.println("open failed\n");
return;
}
// File must be pre-allocated to avoid huge
// delays searching for free clusters.
if (!file.preAllocate(LOG_FILE_SIZE)) {
Serial.println("preAllocate failed\n");
file.close();
return;
}
file.write((uint16_t*)buff);
file.close();
Serial.println("Snapshot saved");
}
}