Add [ESP216]SNAP command to capture screenshot from advanced display

This commit is contained in:
Luc 2019-08-17 17:20:24 +02:00
parent 2933e406fb
commit adbbd9067c
9 changed files with 127 additions and 1 deletions

View File

@ -76,6 +76,9 @@ Flash pins (6~11) cannot be used
* Touch Calibration
[ESP215]<CALIBRATE>[pwd=<user password>]
* Take screen snapshot
[ESP216]<SNAP>[pwd=<user password>]
* Play sound
No parameter just play beep
[ESP250]F=<frequency> D=<duration> [pwd=<user password>]

View File

@ -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

View File

@ -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]<SNAP>[pwd=<user password>]
case 216:
response = ESP216(cmd_params, auth_type, output);
break;
#endif //DISPLAY_SNAPSHOT_FEATURE
#ifdef BUZZER_DEVICE
//Play sound
//[ESP250]F=<frequency> D=<duration> [pwd=<user password>]

View File

@ -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);

View File

@ -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;

View File

@ -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]<SNAP>[pwd=<user password>]
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

View File

@ -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

View File

@ -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 <lvgl.h>
#include <Ticker.h>
#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

View File

@ -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;