add some feature
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "gui.h"
|
||||
#include "statusbar.h"
|
||||
#include "screenshot.h"
|
||||
#include "keyboard.h"
|
||||
#include "mainbar/mainbar.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "config.h"
|
||||
#include <TTGO.h>
|
||||
#include "screenshot.h"
|
||||
#include <rom/crc.h>
|
||||
#include <endian.h>
|
||||
|
||||
lv_disp_drv_t screenshot_disp_drv;
|
||||
static lv_disp_buf_t screenshot_disp_buf;
|
||||
@@ -8,14 +11,20 @@ static lv_color_t screenshot_buf1[ LV_HOR_RES_MAX * 1 ];
|
||||
lv_disp_t *system_disp;
|
||||
lv_disp_t *screenshot_disp;
|
||||
|
||||
uint16_t *png;
|
||||
|
||||
volatile bool screenshot = false;
|
||||
|
||||
static void screenshot_disp_flush( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p );
|
||||
|
||||
void screenshot_setup( void ) {
|
||||
|
||||
png = (uint16_t*)ps_malloc( LV_HOR_RES_MAX * LV_VER_RES_MAX * 2 );
|
||||
|
||||
|
||||
system_disp = lv_disp_get_default();
|
||||
|
||||
lv_disp_buf_init(&screenshot_disp_buf, screenshot_buf1, NULL, LV_HOR_RES_MAX * 1 );
|
||||
|
||||
lv_disp_drv_init( &screenshot_disp_drv );
|
||||
lv_disp_buf_init( &screenshot_disp_buf, screenshot_buf1, NULL, LV_HOR_RES_MAX * 1 );
|
||||
screenshot_disp_drv.hor_res = TFT_WIDTH;
|
||||
screenshot_disp_drv.ver_res = TFT_HEIGHT;
|
||||
screenshot_disp_drv.flush_cb = screenshot_disp_flush;
|
||||
@@ -26,30 +35,42 @@ void screenshot_setup( void ) {
|
||||
}
|
||||
|
||||
void screenshot_take( void ) {
|
||||
/*
|
||||
unsigned char* image = (unsigned char*)ps_malloc(240 * 240 * 3);
|
||||
Serial.printf("Total heap: %d\r\n", ESP.getHeapSize());
|
||||
Serial.printf("Free heap: %d\r\n", ESP.getFreeHeap());
|
||||
Serial.printf("Total PSRAM: %d\r\n", ESP.getPsramSize());
|
||||
Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());
|
||||
*/
|
||||
lv_obj_invalidate(lv_scr_act());
|
||||
lv_disp_set_default( screenshot_disp );
|
||||
lv_refr_now( screenshot_disp );
|
||||
lv_obj_invalidate(lv_scr_act());
|
||||
lv_disp_set_default( system_disp );
|
||||
lv_refr_now( system_disp );
|
||||
Serial.printf("take screenshot\r\n");
|
||||
|
||||
// free(image);
|
||||
screenshot_disp->driver.flush_cb = system_disp->driver.flush_cb;
|
||||
system_disp->driver.flush_cb = screenshot_disp_flush;
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
lv_refr_now( system_disp );
|
||||
system_disp->driver.flush_cb = screenshot_disp->driver.flush_cb;
|
||||
}
|
||||
|
||||
void screenshot_save( void ) {
|
||||
Serial.printf("save screenshot\r\n");
|
||||
|
||||
SPIFFS.remove("/screen.565");
|
||||
fs::File file = SPIFFS.open( "/screen.565", FILE_WRITE );
|
||||
|
||||
file.write( (uint8_t *)png, LV_HOR_RES_MAX * LV_VER_RES_MAX * 2 );
|
||||
file.close();
|
||||
|
||||
fs::File root = SPIFFS.open("/");
|
||||
file = root.openNextFile();
|
||||
while(file){
|
||||
Serial.printf("FILE: %s (%dbytes)\r\n", file.name(), file.size() );
|
||||
file = root.openNextFile();
|
||||
}
|
||||
}
|
||||
|
||||
static void screenshot_disp_flush( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p ) {
|
||||
|
||||
int32_t x, y;
|
||||
uint32_t x, y;
|
||||
uint16_t *data = (uint16_t *)color_p;
|
||||
|
||||
for(y = area->y1; y <= area->y2; y++) {
|
||||
// Serial.printf("refresh Y=%d\r\n",y);
|
||||
// for(x = area->x1; x <= area->x2; x++) {
|
||||
// }
|
||||
}
|
||||
for(x = area->x1; x <= area->x2; x++) {
|
||||
*(png + (y * LV_HOR_RES_MAX + x )) = *data;
|
||||
data++;
|
||||
}
|
||||
}
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
@@ -3,34 +3,31 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define SCREENSHOT_EVENT _BV(0)
|
||||
|
||||
void screenshot_setup( void );
|
||||
void screenshot_take( void );
|
||||
void screenshot_save( void );
|
||||
|
||||
struct _PNG_HEADER {
|
||||
uint8_t png[8] = { 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a };
|
||||
uint32_t len = 13;
|
||||
uint8_t IHDR[4] = { 'I', 'H', 'D', 'R' };
|
||||
uint32_t width = LV_HOR_RES_MAX;
|
||||
uint32_t height = LV_VER_RES_MAX;
|
||||
uint8_t bitdepth = 8;
|
||||
uint8_t colortype = 2;
|
||||
uint8_t compression = 0;
|
||||
uint8_t filter = 0;
|
||||
uint8_t interlace_method = 0;
|
||||
uint32_t crc = 0;
|
||||
};
|
||||
|
||||
struct _PNG_RGB_PIXEL {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
struct _PNG_IDAT_CHUNCK {
|
||||
uint32_t len;
|
||||
uint8_t IDAT[ 4 ] = { 'I', 'D', 'A', 'T' };
|
||||
uint8_t data[ LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof( _PNG_RGB_PIXEL ) ];
|
||||
uint32_t crc;
|
||||
};
|
||||
struct PNG_IMAGE {
|
||||
uint8_t png[ 8 ];
|
||||
uint32_t IHDR_len;
|
||||
uint8_t IHDR[ 4 ];
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint8_t bitdepth;
|
||||
uint8_t colortype;
|
||||
uint8_t compression;
|
||||
uint8_t filter;
|
||||
uint8_t interlace_method;
|
||||
uint32_t IHDR_crc;
|
||||
uint32_t IDAT_len = LV_HOR_RES_MAX * LV_VER_RES_MAX * 3;
|
||||
uint8_t IDAT[ 4 ];
|
||||
uint8_t data[ LV_HOR_RES_MAX * LV_VER_RES_MAX * 3 ];
|
||||
uint32_t IDAT_crc;
|
||||
uint32_t IEND_len;
|
||||
uint8_t IEND[ 4 ];
|
||||
uint32_t IEND_crc;
|
||||
} __attribute__((packed));
|
||||
|
||||
#endif // _SCREENSHOT_H
|
||||
Reference in New Issue
Block a user