add sanity check when doing snapshot

This commit is contained in:
Luc 2019-09-20 02:04:27 +08:00
parent 9ba7716cd1
commit b0f9db71e0
3 changed files with 22 additions and 5 deletions

View File

@ -20,8 +20,7 @@
//Screen size //Screen size
#define SCREEN_WIDTH 320 #define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240 #define SCREEN_HEIGHT 240
#define SCREEN_BG TFT_BLACK #define SNAP_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT * 4)
#define CALIBRATION_BG TFT_BLACK #define CALIBRATION_BG TFT_WHITE
#define CALIBRATION_FG TFT_GREEN
#define CALIBRATION_CORNER TFT_RED #define CALIBRATION_CORNER TFT_RED

View File

@ -20,6 +20,7 @@
//Screen size //Screen size
#define SCREEN_WIDTH 480 #define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 320 #define SCREEN_HEIGHT 320
#define SNAP_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT * 4)
#define CALIBRATION_BG TFT_WHITE #define CALIBRATION_BG TFT_WHITE
#define CALIBRATION_CORNER TFT_RED #define CALIBRATION_CORNER TFT_RED

View File

@ -89,6 +89,9 @@ Display esp3d_display;
static lv_disp_buf_t esp_lv_disp_buf; static lv_disp_buf_t esp_lv_disp_buf;
static lv_color_t lv_buf1[LV_HOR_RES_MAX * 10]; static lv_color_t lv_buf1[LV_HOR_RES_MAX * 10];
static lv_color_t lv_buf2[LV_HOR_RES_MAX * 10]; static lv_color_t lv_buf2[LV_HOR_RES_MAX * 10];
#if defined(DISPLAY_SNAPSHOT_FEATURE)
static uint8_t error_snapshot = 0;
#endif //DISPLAY_SNAPSHOT_FEATURE
Ticker esp_lv_tick; /* timer for interrupt handler */ Ticker esp_lv_tick; /* timer for interrupt handler */
#define LVGL_TICK_PERIOD 10 #define LVGL_TICK_PERIOD 10
#define ESP_FLASH_LETTER_DRIVE 'F' #define ESP_FLASH_LETTER_DRIVE 'F'
@ -111,7 +114,13 @@ void esp_lv_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *c
#if defined(DISPLAY_SNAPSHOT_FEATURE) #if defined(DISPLAY_SNAPSHOT_FEATURE)
if(bSnapshot) { if(bSnapshot) {
uint32_t data = lv_color_to32(*color_p); uint32_t data = lv_color_to32(*color_p);
fsSnapFile.write((const uint8_t *)(&data), sizeof(uint32_t)); //to handle any write issue
if (fsSnapFile.write((const uint8_t *)(&data), sizeof(uint32_t)) != sizeof(uint32_t)){
//if error we stop to dump
bSnapshot = false;
//raise error
error_snapshot = 1;
}
} }
#endif //DISPLAY_SNAPSHOT_FEATURE #endif //DISPLAY_SNAPSHOT_FEATURE
color_p++; color_p++;
@ -636,6 +645,11 @@ bool Display::snapshot(char * filename)
{ {
bool res = false; bool res = false;
#if defined(DISPLAY_SNAPSHOT_FEATURE) #if defined(DISPLAY_SNAPSHOT_FEATURE)
//sanity check to avoid to corrupt FS with capacity overload
error_snapshot = 0;
if (ESP_FileSystem::freeBytes() < SNAP_SIZE) {
return false;
}
if(filename) { if(filename) {
fsSnapFile = ESP_FileSystem::open(filename, ESP_FILE_WRITE); fsSnapFile = ESP_FileSystem::open(filename, ESP_FILE_WRITE);
} else { } else {
@ -650,7 +664,10 @@ bool Display::snapshot(char * filename)
lv_refr_now(lv_disp_get_default()); /* Will call our disp_drv.disp_flush function */ lv_refr_now(lv_disp_get_default()); /* Will call our disp_drv.disp_flush function */
bSnapshot = false; bSnapshot = false;
fsSnapFile.close(); fsSnapFile.close();
return true; //if any snapshot error
if (error_snapshot == 0) {
res = true;
}
#endif //DISPLAY_SNAPSHOT_FEATURE #endif //DISPLAY_SNAPSHOT_FEATURE
return res; return res;
} }