mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Update drivers and screenshot
This commit is contained in:
parent
3011b1abc2
commit
f565ebab28
@ -52,6 +52,7 @@ void tft_espi_init(uint8_t rotation)
|
|||||||
tft.begin();
|
tft.begin();
|
||||||
tft.setSwapBytes(true); /* set endianess */
|
tft.setSwapBytes(true); /* set endianess */
|
||||||
tft.setRotation(rotation);
|
tft.setRotation(rotation);
|
||||||
|
tft.fillScreen(TFT_DARKCYAN);
|
||||||
|
|
||||||
#ifdef USE_DMA_TO_TFT
|
#ifdef USE_DMA_TO_TFT
|
||||||
// DMA - should work with STM32F2xx/F4xx/F7xx processors
|
// DMA - should work with STM32F2xx/F4xx/F7xx processors
|
||||||
@ -91,6 +92,28 @@ void tft_espi_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TOUCH_CS)
|
#if defined(TOUCH_CS)
|
||||||
|
|
||||||
|
void tft_espi_calibrate(uint16_t * calData)
|
||||||
|
{
|
||||||
|
tft.fillScreen(TFT_BLACK);
|
||||||
|
tft.setCursor(20, 0);
|
||||||
|
tft.setTextFont(1);
|
||||||
|
tft.setTextSize(1);
|
||||||
|
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
|
||||||
|
tft.println(PSTR("Touch corners as indicated"));
|
||||||
|
|
||||||
|
tft.setTextFont(1);
|
||||||
|
delay(500);
|
||||||
|
tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
|
||||||
|
tft.setTouch(calData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tft_espi_set_touch(uint16_t * calData)
|
||||||
|
{
|
||||||
|
tft.setTouch(calData);
|
||||||
|
}
|
||||||
|
|
||||||
bool tft_espi_get_touch(uint16_t * touchX, uint16_t * touchY, uint16_t threshold)
|
bool tft_espi_get_touch(uint16_t * touchX, uint16_t * touchY, uint16_t threshold)
|
||||||
{
|
{
|
||||||
return tft.getTouch(touchX, touchY, threshold);
|
return tft.getTouch(touchX, touchY, threshold);
|
@ -47,6 +47,8 @@ void tft_espi_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t co
|
|||||||
void tft_espi_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
|
void tft_espi_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
|
||||||
|
|
||||||
#if defined(TOUCH_CS)
|
#if defined(TOUCH_CS)
|
||||||
|
void tft_espi_calibrate(uint16_t * calData);
|
||||||
|
void tft_espi_set_touch(uint16_t * calData);
|
||||||
bool tft_espi_get_touch(uint16_t * touchX, uint16_t * touchY, uint16_t threshold);
|
bool tft_espi_get_touch(uint16_t * touchX, uint16_t * touchY, uint16_t threshold);
|
||||||
#endif
|
#endif
|
||||||
|
|
422
src/hasp_gui.cpp
422
src/hasp_gui.cpp
@ -5,13 +5,11 @@
|
|||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#include "lv_drv_conf.h"
|
#include "lv_drv_conf.h"
|
||||||
|
|
||||||
//#define USE_FSMC 1
|
// Select Display Driver
|
||||||
|
|
||||||
// Display Driver
|
|
||||||
#if defined(USE_FSMC)
|
#if defined(USE_FSMC)
|
||||||
#include "display/fsmc_ili9341.h"
|
#include "fsmc_ili9341.h"
|
||||||
#else
|
#else
|
||||||
#include "display/tft_espi_drv.h"
|
#include "tft_espi_drv.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Touch Driver
|
// Touch Driver
|
||||||
@ -21,10 +19,8 @@
|
|||||||
// Filesystem Driver
|
// Filesystem Driver
|
||||||
#include "lv_fs_if.h"
|
#include "lv_fs_if.h"
|
||||||
|
|
||||||
//#include "TFT_eSPI.h" // moved to Display Driver
|
|
||||||
//#include "lv_zifont.h"
|
//#include "lv_zifont.h"
|
||||||
|
|
||||||
//#include "hasp_tft.h"
|
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
@ -50,29 +46,11 @@
|
|||||||
#include <FS.h> // Include the SPIFFS library
|
#include <FS.h> // Include the SPIFFS library
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BACKLIGHT_CHANNEL 15 // pwm channek 0-15
|
#define BACKLIGHT_CHANNEL 15 // pwm channel 0-15
|
||||||
|
|
||||||
/* ---------- Screenshot Variables ---------- */
|
#if HASP_USE_SPIFFS > 0
|
||||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
||||||
File pFileOut;
|
File pFileOut;
|
||||||
#endif
|
#endif
|
||||||
uint8_t guiSnapshot = 0;
|
|
||||||
|
|
||||||
#if defined(STM32F4xx)
|
|
||||||
//#include <EthernetWebServer_STM32.h>
|
|
||||||
// EthernetWebServer * webClient(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
ESP8266WebServer * webClient; // for snatshot
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include <WebServer.h>
|
|
||||||
WebServer * webClient; // for snatshot
|
|
||||||
#endif // ESP32
|
|
||||||
/* ------------------------------------------- */
|
|
||||||
|
|
||||||
// #define LVGL_TICK_PERIOD 30
|
// #define LVGL_TICK_PERIOD 30
|
||||||
|
|
||||||
@ -125,95 +103,7 @@ static bool guiCheckSleep()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static void gui_take_screenshot(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
/* Experimental Display flushing */
|
||||||
// {
|
|
||||||
// uint i = 0;
|
|
||||||
// uint16_t c;
|
|
||||||
// uint8_t pixel[1024];
|
|
||||||
|
|
||||||
// for(int y = area->y1; y <= area->y2; y++) {
|
|
||||||
// for(int x = area->x1; x <= area->x2; x++) {
|
|
||||||
// /* Function for converting LittlevGL pixel format to RGB888 */
|
|
||||||
// // data = DISP_IMPL_lvgl_formatPixel(*color_p);
|
|
||||||
|
|
||||||
// // Complex 32 bpp
|
|
||||||
// /* pixel[i++] = (LV_COLOR_GET_B(*color_p) * 263 + 7) >> 5;
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_G(*color_p) * 259 + 3) >> 6;
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_R(*color_p) * 263 + 7) >> 5;
|
|
||||||
// pixel[i++] = 0xFF;*/
|
|
||||||
|
|
||||||
// // Simple 32 bpp
|
|
||||||
// // pixel[i++] = (LV_COLOR_GET_B(*color_p) << 3);
|
|
||||||
// // pixel[i++] = (LV_COLOR_GET_G(*color_p) << 2);
|
|
||||||
// // pixel[i++] = (LV_COLOR_GET_R(*color_p) << 3);
|
|
||||||
// // pixel[i++] = 0xFF;
|
|
||||||
|
|
||||||
// c = color_p->full;
|
|
||||||
|
|
||||||
// // Simple 16 bpp
|
|
||||||
// pixel[i++] = c & 0xFF;
|
|
||||||
// pixel[i++] = (c >> 8) & 0xFF;
|
|
||||||
|
|
||||||
// color_p++;
|
|
||||||
|
|
||||||
// if(i + 4 >= sizeof(pixel)) {
|
|
||||||
// switch(guiSnapshot) {
|
|
||||||
// case 1:
|
|
||||||
// // Save to local file
|
|
||||||
// pFileOut.write(pixel, i);
|
|
||||||
// break;
|
|
||||||
// case 2:
|
|
||||||
// // Send to remote client
|
|
||||||
// if(webClient->client().write(pixel, i) != i) {
|
|
||||||
// Log.warning(F("GUI: Pixelbuffer not completely sent"));
|
|
||||||
// lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// i = 0;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if(i > 0) {
|
|
||||||
// switch(guiSnapshot) {
|
|
||||||
// case 1:
|
|
||||||
// // Save to local file
|
|
||||||
// pFileOut.write(pixel, i);
|
|
||||||
// break;
|
|
||||||
// case 2:
|
|
||||||
// // Send to remote client
|
|
||||||
// if(webClient->client().write(pixel, i) != i) {
|
|
||||||
// Log.warning(F("GUI: Pixelbuffer not completely sent"));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/* Flush VDB bytes to a stream */
|
|
||||||
static void gui_take_screenshot(uint8_t * data_p, size_t len)
|
|
||||||
{
|
|
||||||
size_t res = 0;
|
|
||||||
switch(guiSnapshot) {
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
|
||||||
case 1:
|
|
||||||
res = pFileOut.write(data_p, len);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case 2:
|
|
||||||
#if HASP_USE_HTTP > 0
|
|
||||||
res = httpClientWrite(data_p, len);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
res = 0; // nothing to do
|
|
||||||
}
|
|
||||||
if(res != len) {
|
|
||||||
Log.warning(F("GUI: Pixelbuffer not completely sent"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Experimetnal Display flushing */
|
|
||||||
static void IRAM_ATTR my_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
static void IRAM_ATTR my_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
@ -226,9 +116,9 @@ static void IRAM_ATTR my_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area,
|
|||||||
tft.endWrite(); /* terminate TFT transaction */
|
tft.endWrite(); /* terminate TFT transaction */
|
||||||
|
|
||||||
/* Send Screenshot data */
|
/* Send Screenshot data */
|
||||||
if(guiSnapshot != 0) {
|
// if(guiSnapshot != 0) {
|
||||||
gui_take_screenshot((uint8_t *)color_p, len * sizeof(lv_color_t)); /* Number of bytes */
|
// gui_take_screenshot(disp, area, color_p);
|
||||||
}
|
//}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_FSMC)
|
#if defined(USE_FSMC)
|
||||||
@ -236,96 +126,11 @@ static void IRAM_ATTR my_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area,
|
|||||||
#else
|
#else
|
||||||
tft_espi_flush(area->x1, area->y1, area->x2, area->y2, color_p);
|
tft_espi_flush(area->x1, area->y1, area->x2, area->y2, color_p);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Tell lvgl that flushing is done */
|
/* Tell lvgl that flushing is done */
|
||||||
lv_disp_flush_ready(disp);
|
lv_disp_flush_ready(disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display flushing */
|
|
||||||
/*
|
|
||||||
void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
|
||||||
{
|
|
||||||
uint16_t c;
|
|
||||||
|
|
||||||
tft.startWrite(); // Start new TFT transaction
|
|
||||||
tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1),
|
|
||||||
(area->y2 - area->y1 + 1)); // set the working window
|
|
||||||
|
|
||||||
if(guiSnapshot != 0) {
|
|
||||||
uint i = 0;
|
|
||||||
uint8_t pixel[1024];
|
|
||||||
|
|
||||||
for(int y = area->y1; y <= area->y2; y++) {
|
|
||||||
for(int x = area->x1; x <= area->x2; x++) {
|
|
||||||
// Function for converting LittlevGL pixel format to RGB888
|
|
||||||
// data = DISP_IMPL_lvgl_formatPixel(*color_p);
|
|
||||||
|
|
||||||
// Complex 32 bpp
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_B(*color_p) * 263 + 7) >> 5;
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_G(*color_p) * 259 + 3) >> 6;
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_R(*color_p) * 263 + 7) >> 5;
|
|
||||||
// pixel[i++] = 0xFF;
|
|
||||||
|
|
||||||
// Simple 32 bpp
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_B(*color_p) << 3);
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_G(*color_p) << 2);
|
|
||||||
// pixel[i++] = (LV_COLOR_GET_R(*color_p) << 3);
|
|
||||||
// pixel[i++] = 0xFF;
|
|
||||||
|
|
||||||
c = color_p->full;
|
|
||||||
tft.writeColor(c, 1); // also update tft
|
|
||||||
|
|
||||||
// Simple 16 bpp
|
|
||||||
pixel[i++] = c & 0xFF;
|
|
||||||
pixel[i++] = (c >> 8) & 0xFF;
|
|
||||||
|
|
||||||
color_p++;
|
|
||||||
|
|
||||||
if(i + 4 >= sizeof(pixel)) {
|
|
||||||
switch(guiSnapshot) {
|
|
||||||
case 1:
|
|
||||||
// Save to local file
|
|
||||||
pFileOut.write(pixel, i);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
// Send to remote client
|
|
||||||
if(webClient->client().write(pixel, i) != i) {
|
|
||||||
Log.warning(F("GUI: Pixelbuffer not completely sent"));
|
|
||||||
lv_disp_flush_ready(disp); // tell lvgl that flushing is done
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i > 0) {
|
|
||||||
switch(guiSnapshot) {
|
|
||||||
case 1:
|
|
||||||
// Save to local file
|
|
||||||
pFileOut.write(pixel, i);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
// Send to remote client
|
|
||||||
if(webClient->client().write(pixel, i) != i) {
|
|
||||||
Log.warning(F("GUI: Pixelbuffer not completely sent"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(int y = area->y1; y <= area->y2; y++) {
|
|
||||||
for(int x = area->x1; x <= area->x2; x++) {
|
|
||||||
c = color_p->full;
|
|
||||||
tft.writeColor(c, 1);
|
|
||||||
color_p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tft.endWrite(); // terminate TFT transaction
|
|
||||||
|
|
||||||
lv_disp_flush_ready(disp); // tell lvgl that flushing is done
|
|
||||||
} */
|
|
||||||
|
|
||||||
/* Interrupt driven periodic handler */
|
/* Interrupt driven periodic handler */
|
||||||
static void IRAM_ATTR lv_tick_handler(void)
|
static void IRAM_ATTR lv_tick_handler(void)
|
||||||
{
|
{
|
||||||
@ -596,9 +401,7 @@ bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t *
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!touched) return false;
|
if(touched && guiSleeping > 0) guiCheckSleep(); // update Idle
|
||||||
|
|
||||||
if(guiSleeping > 0) guiCheckSleep(); // update Idle
|
|
||||||
|
|
||||||
// Ignore first press?
|
// Ignore first press?
|
||||||
|
|
||||||
@ -624,25 +427,14 @@ bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t *
|
|||||||
|
|
||||||
void guiCalibrate()
|
void guiCalibrate()
|
||||||
{
|
{
|
||||||
#if TOUCH_DRIVER == 0 && 0
|
#if TOUCH_DRIVER == 0 && USE_TFT_ESPI > 0
|
||||||
tft.fillScreen(TFT_BLACK);
|
tft_espi_calibrate(calData);
|
||||||
tft.setCursor(20, 0);
|
|
||||||
tft.setTextFont(1);
|
|
||||||
tft.setTextSize(1);
|
|
||||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
|
||||||
|
|
||||||
tft.println(PSTR("Touch corners as indicated"));
|
|
||||||
|
|
||||||
tft.setTextFont(1);
|
|
||||||
delay(500);
|
|
||||||
tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
|
|
||||||
|
|
||||||
for(uint8_t i = 0; i < 5; i++) {
|
for(uint8_t i = 0; i < 5; i++) {
|
||||||
Serial.print(calData[i]);
|
Serial.print(calData[i]);
|
||||||
if(i < 4) Serial.print(", ");
|
if(i < 4) Serial.print(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
tft.setTouch(calData);
|
|
||||||
delay(500);
|
delay(500);
|
||||||
lv_obj_invalidate(lv_disp_get_layer_sys(NULL));
|
lv_obj_invalidate(lv_disp_get_layer_sys(NULL));
|
||||||
#endif
|
#endif
|
||||||
@ -658,6 +450,10 @@ void guiSetup()
|
|||||||
tft_espi_init(guiRotation);
|
tft_espi_init(guiRotation);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if TOUCH_DRIVER == 1
|
||||||
|
GT911_setup();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
tft.begin();
|
tft.begin();
|
||||||
tft.setSwapBytes(true); /* set endianess */
|
tft.setSwapBytes(true); /* set endianess */
|
||||||
@ -669,8 +465,8 @@ void guiSetup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
tft.setRotation(guiRotation); /* 1/3=Landscape or 0/2=Portrait orientation */
|
tft.setRotation(guiRotation); /* 1/3=Landscape or 0/2=Portrait orientation */
|
||||||
#if TOUCH_DRIVER == 0
|
#if TOUCH_DRIVER == 0 && USE_TFT_ESPI > 0
|
||||||
tft.setTouch(calData);
|
tft_espi_set_touch(calData);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -769,6 +565,29 @@ void guiSetup()
|
|||||||
}
|
}
|
||||||
lv_disp_drv_register(&disp_drv);
|
lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
|
/* Initialize Global progress bar*/
|
||||||
|
lv_obj_t * bar = lv_bar_create(lv_layer_sys(), NULL);
|
||||||
|
lv_obj_set_hidden(bar, true);
|
||||||
|
lv_bar_set_range(bar, 0, 100);
|
||||||
|
lv_bar_set_value(bar, 10, LV_ANIM_OFF);
|
||||||
|
lv_obj_set_size(bar, 200, 15);
|
||||||
|
lv_obj_align(bar, lv_layer_sys(), LV_ALIGN_CENTER, 0, -10);
|
||||||
|
lv_obj_set_user_data(bar, 10);
|
||||||
|
lv_obj_set_style_local_value_color(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
||||||
|
lv_obj_set_style_local_value_align(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_ALIGN_CENTER);
|
||||||
|
lv_obj_set_style_local_value_ofs_y(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, 20);
|
||||||
|
lv_obj_set_style_local_value_font(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, &lv_font_montserrat_12);
|
||||||
|
lv_obj_set_style_local_bg_color(lv_layer_sys(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
|
||||||
|
lv_obj_set_style_local_bg_opa(lv_layer_sys(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0);
|
||||||
|
|
||||||
|
/*Initialize the graphics library's tick*/
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
tick.attach_ms(guiTickPeriod, lv_tick_handler);
|
||||||
|
#else
|
||||||
|
tick.start();
|
||||||
|
#endif
|
||||||
|
lv_tick_handler();
|
||||||
|
|
||||||
/*Initialize the touch pad*/
|
/*Initialize the touch pad*/
|
||||||
lv_indev_drv_t indev_drv;
|
lv_indev_drv_t indev_drv;
|
||||||
lv_indev_drv_init(&indev_drv);
|
lv_indev_drv_init(&indev_drv);
|
||||||
@ -823,7 +642,6 @@ void guiSetup()
|
|||||||
|
|
||||||
/*Initialize the graphics library's tick*/
|
/*Initialize the graphics library's tick*/
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||||
tick.attach_ms(guiTickPeriod, lv_tick_handler);
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -849,10 +667,6 @@ void guiSetup()
|
|||||||
MyTim->resume();*/
|
MyTim->resume();*/
|
||||||
tick.start();
|
tick.start();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TOUCH_DRIVER == 1
|
|
||||||
GT911_setup();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR guiLoop()
|
void IRAM_ATTR guiLoop()
|
||||||
@ -952,8 +766,9 @@ bool guiGetConfig(const JsonObject & settings)
|
|||||||
v.set(calData[i]);
|
v.set(calData[i]);
|
||||||
} else {
|
} else {
|
||||||
changed = true;
|
changed = true;
|
||||||
#if 0
|
|
||||||
tft.setTouch(calData);
|
#if TOUCH_DRIVER == 0 && USE_TFT_ESPI > 0
|
||||||
|
tft_espi_set_touch(calData);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@ -966,8 +781,9 @@ bool guiGetConfig(const JsonObject & settings)
|
|||||||
array.add(calData[i]);
|
array.add(calData[i]);
|
||||||
}
|
}
|
||||||
changed = true;
|
changed = true;
|
||||||
#if 0
|
|
||||||
tft.setTouch(calData);
|
#if TOUCH_DRIVER == 0 && USE_TFT_ESPI > 0
|
||||||
|
tft_espi_set_touch(calData);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1025,8 +841,8 @@ bool guiSetConfig(const JsonObject & settings)
|
|||||||
oobeSetAutoCalibrate(true);
|
oobeSetAutoCalibrate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if TOUCH_DRIVER == 0 && USE_TFT_ESPI > 0
|
||||||
if(status) tft.setTouch(calData);
|
if(status) tft_espi_set_touch(calData);
|
||||||
#endif
|
#endif
|
||||||
changed |= status;
|
changed |= status;
|
||||||
}
|
}
|
||||||
@ -1034,6 +850,9 @@ bool guiSetConfig(const JsonObject & settings)
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* **************************** SCREENSHOTS ************************************** */
|
||||||
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_HTTP > 0
|
||||||
|
|
||||||
static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
|
static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
|
||||||
{
|
{
|
||||||
*buffer_p++ = data & 0xFF;
|
*buffer_p++ = data & 0xFF;
|
||||||
@ -1042,25 +861,6 @@ static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
|
|||||||
*buffer_p++ = (data >> 24) & 0xFF;
|
*buffer_p++ = (data >> 24) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void guiSendBmpHeader();
|
|
||||||
|
|
||||||
void guiTakeScreenshot()
|
|
||||||
{
|
|
||||||
// webClient = &client;
|
|
||||||
// lv_disp_t * disp = lv_disp_get_default();
|
|
||||||
|
|
||||||
// webClient->setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t));
|
|
||||||
// webClient->send(200, PSTR("image/bmp"), "");
|
|
||||||
|
|
||||||
guiSnapshot = 2;
|
|
||||||
guiSendBmpHeader();
|
|
||||||
lv_obj_invalidate(lv_scr_act());
|
|
||||||
lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */
|
|
||||||
guiSnapshot = 0;
|
|
||||||
|
|
||||||
Log.verbose(F("GUI: Bitmap data flushed to webclient"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Send Bitmap Header.
|
/** Send Bitmap Header.
|
||||||
*
|
*
|
||||||
* Sends a header in BMP format for the size of the screen.
|
* Sends a header in BMP format for the size of the screen.
|
||||||
@ -1068,10 +868,11 @@ void guiTakeScreenshot()
|
|||||||
* @note: send header before refreshing the whole screen
|
* @note: send header before refreshing the whole screen
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
static void guiSendBmpHeader()
|
static void gui_get_bitmap_header(uint8_t * buffer, size_t bufsize)
|
||||||
{
|
{
|
||||||
uint8_t buffer[128];
|
// uint8_t buffer[128];
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
|
memset(buffer, 0, bufsize);
|
||||||
|
|
||||||
lv_disp_t * disp = lv_disp_get_default();
|
lv_disp_t * disp = lv_disp_get_default();
|
||||||
buffer[0] = 0x42; // B
|
buffer[0] = 0x42; // B
|
||||||
@ -1109,55 +910,106 @@ static void guiSendBmpHeader()
|
|||||||
buffer[70 + 2] = 0x69;
|
buffer[70 + 2] = 0x69;
|
||||||
buffer[70 + 1] = 0x6E;
|
buffer[70 + 1] = 0x6E;
|
||||||
buffer[70 + 0] = 0x20;
|
buffer[70 + 0] = 0x20;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_flush_not_complete()
|
||||||
|
{
|
||||||
|
Log.warning(F("GUI: Pixelbuffer not completely sent"));
|
||||||
|
}
|
||||||
|
#endif // HASP_USE_SPIFFS > 0 || HASP_USE_HTTP > 0
|
||||||
|
|
||||||
if(guiSnapshot == 1) {
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0
|
||||||
size_t len = pFileOut.write(buffer, 122);
|
/* Flush VDB bytes to a file */
|
||||||
if(len != sizeof(buffer)) {
|
static void gui_screenshot_to_file(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
||||||
Log.warning(F("GUI: Data written does not match header size"));
|
{
|
||||||
} else {
|
size_t len = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1); /* Number of pixels */
|
||||||
Log.verbose(F("GUI: Bitmap header written"));
|
len *= sizeof(lv_color_t); /* Number of bytes */
|
||||||
}
|
size_t res = pFileOut.write((uint8_t *)color_p, len);
|
||||||
#endif
|
if(res != len) gui_flush_not_complete();
|
||||||
|
my_flush_cb(disp, area, color_p);
|
||||||
} else if(guiSnapshot == 2) {
|
|
||||||
#if HASP_USE_HTTP > 0
|
|
||||||
if(httpClientWrite(buffer, 122) != 122) {
|
|
||||||
Log.warning(F("GUI: Data sent does not match header size"));
|
|
||||||
} else {
|
|
||||||
Log.verbose(F("GUI: Bitmap header sent"));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Take Screenshot.
|
/** Take Screenshot.
|
||||||
*
|
*
|
||||||
* Flush buffer into a binary file.
|
* Flush buffer into a binary file.
|
||||||
*
|
*
|
||||||
* @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements.
|
* @note: data pixel should be formated to uint16_t RGB. Set by Bitmap header.
|
||||||
*
|
*
|
||||||
* @param[in] pFileName Output binary file name.
|
* @param[in] pFileName Output binary file name.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
#if HASP_USE_SPIFFS > 0
|
|
||||||
void guiTakeScreenshot(const char * pFileName)
|
void guiTakeScreenshot(const char * pFileName)
|
||||||
{
|
{
|
||||||
|
uint8_t buffer[128];
|
||||||
|
gui_get_bitmap_header(buffer, sizeof(buffer));
|
||||||
|
|
||||||
pFileOut = SPIFFS.open(pFileName, "w");
|
pFileOut = SPIFFS.open(pFileName, "w");
|
||||||
|
if(pFileOut) {
|
||||||
|
|
||||||
if(pFileOut == 0) {
|
size_t len = pFileOut.write(buffer, 122);
|
||||||
|
if(len == 122) {
|
||||||
|
Log.verbose(F("GUI: Bitmap header written"));
|
||||||
|
|
||||||
|
/* Refresh screen to screenshot callback */
|
||||||
|
lv_disp_t * disp = lv_disp_get_default();
|
||||||
|
void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
|
||||||
|
flush_cb = disp->driver.flush_cb; /* store callback */
|
||||||
|
disp->driver.flush_cb = gui_screenshot_to_file;
|
||||||
|
lv_obj_invalidate(lv_scr_act());
|
||||||
|
lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */
|
||||||
|
disp->driver.flush_cb = flush_cb; /* restore callback */
|
||||||
|
|
||||||
|
Log.verbose(F("GUI: Birmap data flushed to %s"), pFileName);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.error(F("GUI: Data written does not match header size"));
|
||||||
|
}
|
||||||
|
pFileOut.close();
|
||||||
|
|
||||||
|
} else {
|
||||||
Log.warning(F("GUI: %s cannot be opened"), pFileName);
|
Log.warning(F("GUI: %s cannot be opened"), pFileName);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
guiSnapshot = 1;
|
#if HASP_USE_HTTP > 0
|
||||||
guiSendBmpHeader();
|
/* Flush VDB bytes to a webclient */
|
||||||
|
static void gui_screenshot_to_http(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
||||||
|
{
|
||||||
|
size_t len = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1); /* Number of pixels */
|
||||||
|
len *= sizeof(lv_color_t); /* Number of bytes */
|
||||||
|
size_t res = httpClientWrite((uint8_t *)color_p, len);
|
||||||
|
if(res != len) gui_flush_not_complete();
|
||||||
|
my_flush_cb(disp, area, color_p);
|
||||||
|
}
|
||||||
|
|
||||||
lv_obj_invalidate(lv_scr_act());
|
/** Take Screenshot.
|
||||||
lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */
|
*
|
||||||
guiSnapshot = 0;
|
* Flush buffer into a http client.
|
||||||
|
*
|
||||||
|
* @note: data pixel should be formated to uint16_t RGB. Set by Bitmap header.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
void guiTakeScreenshot()
|
||||||
|
{
|
||||||
|
uint8_t buffer[128];
|
||||||
|
gui_get_bitmap_header(buffer, sizeof(buffer));
|
||||||
|
|
||||||
pFileOut.close();
|
if(httpClientWrite(buffer, 122) == 122) {
|
||||||
Log.verbose(F("[Display] data flushed to %s"), pFileName);
|
Log.verbose(F("GUI: Bitmap header sent"));
|
||||||
|
|
||||||
|
/* Refresh screen to screenshot callback */
|
||||||
|
lv_disp_t * disp = lv_disp_get_default();
|
||||||
|
void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
|
||||||
|
flush_cb = disp->driver.flush_cb; /* store callback */
|
||||||
|
disp->driver.flush_cb = gui_screenshot_to_http;
|
||||||
|
lv_obj_invalidate(lv_scr_act());
|
||||||
|
lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */
|
||||||
|
disp->driver.flush_cb = flush_cb; /* restore callback */
|
||||||
|
|
||||||
|
Log.verbose(F("GUI: Bitmap data flushed to webclient"));
|
||||||
|
} else {
|
||||||
|
Log.error(F("GUI: Data sent does not match header size"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@ -52,11 +52,12 @@ void tftShowConfig(TFT_eSPI & tft)
|
|||||||
tft.getSetup(tftSetup);
|
tft.getSetup(tftSetup);
|
||||||
|
|
||||||
Log.verbose(F("TFT: TFT_eSPI : v%s"), tftSetup.version.c_str());
|
Log.verbose(F("TFT: TFT_eSPI : v%s"), tftSetup.version.c_str());
|
||||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32)
|
// #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
Log.verbose(F("TFT: Processor : ESP%x"), tftSetup.esp);
|
// Log.verbose(F("TFT: Processor : ESP%x"), tftSetup.esp);
|
||||||
#else
|
// #else
|
||||||
Log.verbose(F("TFT: Processor : STM%x"), tftSetup.esp);
|
// Log.verbose(F("TFT: Processor : STM%x"), tftSetup.esp);
|
||||||
#endif
|
// #endif
|
||||||
|
Log.verbose(F("TFT: Processor : %s"), halGetChipModel());
|
||||||
Log.verbose(F("TFT: CPU freq. : %i MHz"), halGetCpuFreqMHz());
|
Log.verbose(F("TFT: CPU freq. : %i MHz"), halGetCpuFreqMHz());
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
@ -70,7 +71,7 @@ void tftShowConfig(TFT_eSPI & tft)
|
|||||||
|
|
||||||
if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch
|
if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch
|
||||||
{
|
{
|
||||||
Log.verbose(F("TFT: Driver : %s"),halDisplayDriverName().c_str()); // tftSetup.tft_driver);
|
Log.verbose(F("TFT: Driver : %s"), halDisplayDriverName().c_str()); // tftSetup.tft_driver);
|
||||||
Log.verbose(F("TFT: Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height);
|
Log.verbose(F("TFT: Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height);
|
||||||
} else if(tftSetup.tft_driver == 0xE9D)
|
} else if(tftSetup.tft_driver == 0xE9D)
|
||||||
Log.verbose(F("Driver = ePaper"));
|
Log.verbose(F("Driver = ePaper"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user