From adbbd9067ce4ee89c3ddad29191a6350a8ae20a9 Mon Sep 17 00:00:00 2001 From: Luc Date: Sat, 17 Aug 2019 17:20:24 +0200 Subject: [PATCH] Add [ESP216]SNAP command to capture screenshot from advanced display --- docs/Commands.txt | 3 + esp3d/configuration.h | 5 ++ esp3d/src/core/commands.cpp | 7 ++ esp3d/src/core/commands.h | 3 + esp3d/src/core/espcmd/ESP215.cpp | 1 + esp3d/src/core/espcmd/ESP216.cpp | 64 +++++++++++++++++++ esp3d/src/include/version.h | 2 +- esp3d/src/modules/display/advanceddisplay.cpp | 42 ++++++++++++ esp3d/src/modules/display/advanceddisplay.h | 1 + 9 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 esp3d/src/core/espcmd/ESP216.cpp diff --git a/docs/Commands.txt b/docs/Commands.txt index d627175e..58af654f 100644 --- a/docs/Commands.txt +++ b/docs/Commands.txt @@ -76,6 +76,9 @@ Flash pins (6~11) cannot be used * Touch Calibration [ESP215][pwd=] +* Take screen snapshot +[ESP216][pwd=] + * Play sound No parameter just play beep [ESP250]F= D= [pwd=] diff --git a/esp3d/configuration.h b/esp3d/configuration.h index 08f597bf..2569f21f 100644 --- a/esp3d/configuration.h +++ b/esp3d/configuration.h @@ -158,6 +158,11 @@ #define DEBUG_ESP3D_OUTPUT_PORT 8000 #endif //ESP_DEBUG_FEATURE +#if defined (DISPLAY_DEVICE) && (DISPLAY_UI_TYPE == UI_TYPE_ADVANCED) +//allows to use [ESP216]SNAP to do screen capture +#define DISPLAY_SNAPSHOT_FEATURE +#endif //DISPLAY_DEVICE + /************************************ * * Serial Communications diff --git a/esp3d/src/core/commands.cpp b/esp3d/src/core/commands.cpp index e6aeb937..bba4c4a0 100644 --- a/esp3d/src/core/commands.cpp +++ b/esp3d/src/core/commands.cpp @@ -366,6 +366,13 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_ response = ESP215(cmd_params, auth_type, output); break; #endif //DISPLAY_TOUCH_DRIVER +#if defined(DISPLAY_SNAPSHOT_FEATURE) + //Take screen snapshot + //[ESP216][pwd=] + case 216: + response = ESP216(cmd_params, auth_type, output); + break; +#endif //DISPLAY_SNAPSHOT_FEATURE #ifdef BUZZER_DEVICE //Play sound //[ESP250]F= D= [pwd=] diff --git a/esp3d/src/core/commands.h b/esp3d/src/core/commands.h index 944e61ec..693b36cd 100644 --- a/esp3d/src/core/commands.h +++ b/esp3d/src/core/commands.h @@ -83,6 +83,9 @@ public: #if defined(DISPLAY_TOUCH_DRIVER) bool ESP215(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #endif //DISPLAY_TOUCH_DRIVER +#if defined(DISPLAY_SNAPSHOT_FEATURE) + bool ESP216(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); +#endif //DISPLAY_TOUCH_DRIVER #endif //DISPLAY_DEVICE #ifdef DHT_DEVICE bool ESP210(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); diff --git a/esp3d/src/core/espcmd/ESP215.cpp b/esp3d/src/core/espcmd/ESP215.cpp index a7069bc8..ca4d8547 100644 --- a/esp3d/src/core/espcmd/ESP215.cpp +++ b/esp3d/src/core/espcmd/ESP215.cpp @@ -49,6 +49,7 @@ bool Commands::ESP215(const char* cmd_params, level_authenticate_type auth_type, esp3d_display.startCalibration(); } else { output->printERROR("Invalid parameter!"); + response = false; } } return response; diff --git a/esp3d/src/core/espcmd/ESP216.cpp b/esp3d/src/core/espcmd/ESP216.cpp new file mode 100644 index 00000000..0306c2db --- /dev/null +++ b/esp3d/src/core/espcmd/ESP216.cpp @@ -0,0 +1,64 @@ +/* + ESP216.cpp - ESP3D command class + + Copyright (c) 2014 Luc Lebosse. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "../../include/esp3d_config.h" +#if defined(DISPLAY_SNAPSHOT_FEATURE) +#include "../commands.h" +#include "../esp3doutput.h" +#include "../settings_esp3d.h" +#include "../../modules/authentication/authentication_service.h" +#include "../../modules/display/display.h" +//Take screen snapshot +//[ESP216][pwd=] +bool Commands::ESP216(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) +{ + bool response = true; + String parameter; +#ifdef AUTHENTICATION_FEATURE + if (auth_type == LEVEL_GUEST) { + output->printERROR("Wrong authentication!", 401); + return false; + } +#else + (void)auth_type; +#endif //AUTHENTICATION_FEATURE + parameter = get_param (cmd_params, ""); + //get + if (parameter.length() == 0) { + output->printERROR("Invalid parameter!"); + response = false; + } else { //set + parameter.toUpperCase(); + if (parameter == "SNAP") { + output->printMSG("Creating snapshot"); + if(esp3d_display.snapshot()){ + output->printMSG("Snapshot saved"); + } else { + output->printERROR("Error!"); + response = false; + } + } else { + output->printERROR("Invalid parameter!"); + response = false; + } + } + return response; +} + +#endif //DISPLAY_SNAPSHOT_FEATURE diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index 3163d6cd..67adcd53 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a12" +#define FW_VERSION "3.0.0.a13" #define REPOSITORY "https://github.com/luc-github/ESP3D" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/display/advanceddisplay.cpp b/esp3d/src/modules/display/advanceddisplay.cpp index a44c49ef..6a76acb5 100644 --- a/esp3d/src/modules/display/advanceddisplay.cpp +++ b/esp3d/src/modules/display/advanceddisplay.cpp @@ -21,9 +21,17 @@ #include "../../include/esp3d_config.h" #if defined (DISPLAY_DEVICE) && (DISPLAY_UI_TYPE == UI_TYPE_ADVANCED) +//to get bmp file use ImageMagick +//Under Windows: +//ImageMagick-7.0.8-Q16>magick.exe -size 480x320 -depth 8 bgra:snapshot.bin snap.bmp +//On others systems: +//convert -size 480x320 -depth 8 bgra:snapshot.bin snap.bmp +#define SNAPFILENAME "/snapshot.bin" + #include "advanceddisplay.h" #include "../../core/settings_esp3d.h" #include "../../core/esp3doutput.h" +#include "../filesystem/esp_filesystem.h" #include #include #include "lv_flash_drv.h" @@ -34,6 +42,11 @@ lv_obj_t * esp_lv_status_label; lv_obj_t * esp_lv_IP_label; lv_obj_t * esp_lv_network_label; +#if defined(DISPLAY_SNAPSHOT_FEATURE) +static ESP_File fsSnapFile; +static bool bSnapshot; +#endif //DISPLAY_SNAPSHOT_FEATURE + #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106 #include "Wire.h" #if DISPLAY_DEVICE == OLED_I2C_SSD1306 @@ -95,6 +108,12 @@ void esp_lv_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *c for (int x = area->x1; x <= area->x2; x++) { c = color_p->full; esp3d_screen.writeColor(c, 1); +#if defined(DISPLAY_SNAPSHOT_FEATURE) + if(bSnapshot) { + uint32_t data = lv_color_to32(*color_p); + fsSnapFile.write((const uint8_t *)(&data), sizeof(uint32_t)); + } +#endif //DISPLAY_SNAPSHOT_FEATURE color_p++; } } @@ -142,6 +161,7 @@ return false; bool Display::startCalibration() { + //TODO add better calibration page with sound and contextual text bool res = false; #if defined(DISPLAY_TOUCH_DRIVER) #if DISPLAY_TOUCH_DRIVER == XPT2046_SPI @@ -418,6 +438,7 @@ Display::Display() esp_lv_bar_progression = nullptr; esp_lv_IP_label = nullptr; esp_lv_network_label = nullptr; + bSnapshot = false; } Display::~Display() @@ -607,4 +628,25 @@ void Display::progress(uint8_t v) } } + + +bool Display::snapshot() +{ + bool res = false; +#if defined(DISPLAY_SNAPSHOT_FEATURE) + fsSnapFile = ESP_FileSystem::open(SNAPFILENAME, ESP_FILE_WRITE); + if (!fsSnapFile) { + return false; + } + + bSnapshot = true; + lv_obj_invalidate(lv_scr_act()); + lv_refr_now(lv_disp_get_default()); /* Will call our disp_drv.disp_flush function */ + bSnapshot = false; + fsSnapFile.close(); + return true; +#endif //DISPLAY_SNAPSHOT_FEATURE + return res; +} + #endif //DISPLAY_DEVICE diff --git a/esp3d/src/modules/display/advanceddisplay.h b/esp3d/src/modules/display/advanceddisplay.h index 489da8b7..3b2ab56b 100644 --- a/esp3d/src/modules/display/advanceddisplay.h +++ b/esp3d/src/modules/display/advanceddisplay.h @@ -42,6 +42,7 @@ public: void progress(uint8_t v); void SetStatus(const char * status); bool startCalibration(); + bool snapshot(); private: bool _started; uint8_t _screenID;