Skip to content

Commit

Permalink
Merge pull request #126 from thooge/screenshot
Browse files Browse the repository at this point in the history
Screenshot feature
  • Loading branch information
norbert-walter authored Dec 23, 2024
2 parents 2a19a2e + c7b6baf commit df5ff1c
Show file tree
Hide file tree
Showing 9 changed files with 498 additions and 18 deletions.
43 changes: 42 additions & 1 deletion lib/obp60task/OBP60Extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Pagedata.h"
#include "OBP60Hardware.h"
#include "OBP60Extensions.h"
#include "imglib.h"

// Character sets
#include "Ubuntu_Bold8pt7b.h"
Expand Down Expand Up @@ -404,4 +405,44 @@ void generatorGraphic(uint x, uint y, int pcolor, int bcolor){
getdisplay().print("G");
}

#endif
// Function to handle HTTP image request
void doImageRequest(GwApi *api, int *pageno, const PageStruct pages[MAX_PAGE_NUMBER], AsyncWebServerRequest *request) {
GwLog *logger = api->getLogger();

String imgformat = api->getConfig()->getConfigItem(api->getConfig()->imageFormat,true)->asString();
imgformat.toLowerCase();
String filename = "Page" + String(*pageno) + "_" + pages[*pageno].description->pageName + "." + imgformat;

logger->logDebug(GwLog::LOG,"handle image request [%s]: %s", imgformat, filename);

uint8_t *fb = getdisplay().getBuffer(); // EPD framebuffer
std::vector<uint8_t> imageBuffer; // image in webserver transferbuffer
String mimetype;

if (imgformat == "gif") {
// GIF is commpressed with LZW, so small
mimetype = "image/gif";
if (!createGIF(fb, &imageBuffer, GxEPD_WIDTH, GxEPD_HEIGHT)) {
logger->logDebug(GwLog::LOG,"GIF creation failed: Hashtable init error!");
return;
}
}
else if (imgformat == "bmp") {
// Microsoft BMP bitmap
mimetype = "image/bmp";
createBMP(fb, &imageBuffer, GxEPD_WIDTH, GxEPD_HEIGHT);
}
else {
// PBM simple portable bitmap
mimetype = "image/x-portable-bitmap";
createPBM(fb, &imageBuffer, GxEPD_WIDTH, GxEPD_HEIGHT);
}

AsyncWebServerResponse *response = request->beginResponse_P(200, mimetype, (const uint8_t*)imageBuffer.data(), imageBuffer.size());
response->addHeader("Content-Disposition", "inline; filename=" + filename);
request->send(response);

imageBuffer.clear();
}

#endif
4 changes: 3 additions & 1 deletion lib/obp60task/OBP60Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ void solarGraphic(uint x, uint y, int pcolor, int bcolor); // S
void generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic with fill level
void startLedTask(GwApi *api);

#endif
void doImageRequest(GwApi *api, int *pageno, const PageStruct pages[MAX_PAGE_NUMBER], AsyncWebServerRequest *request);

#endif
5 changes: 0 additions & 5 deletions lib/obp60task/OBP60Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
#define OBP_SPI_DIN 48
#define SHOW_TIME 6000 // Show time in [ms] for logo and WiFi QR code
#define FULL_REFRESH_TIME 600 // Refresh cycle time in [s][600...3600] for full display update (very important healcy function)
#define MAX_PAGE_NUMBER 10 // Max number of pages for show data
#define FONT1 "Ubuntu_Bold8pt7b"
#define FONT2 "Ubuntu_Bold24pt7b"
#define FONT3 "Ubuntu_Bold32pt7b"
#define FONT4 "DSEG7Classic_BoldItalic80pt7b"

// GPS (NEO-6M, NEO-M8N, ATGM336H)
#define OBP_GPS_RX 2
Expand Down
9 changes: 9 additions & 0 deletions lib/obp60task/Pagedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <functional>
#include <vector>

#define MAX_PAGE_NUMBER 10 // Max number of pages for show data

typedef std::vector<GwApi::BoatValue *> ValueList;
typedef struct{
String pageName;
Expand Down Expand Up @@ -114,6 +116,13 @@ class PageDescription{
}
};

class PageStruct{
public:
Page *page=NULL;
PageData parameters;
PageDescription *description=NULL;
};

// Structure for formated boat values
typedef struct{
double value;
Expand Down
16 changes: 16 additions & 0 deletions lib/obp60task/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,22 @@
"obp60":"true"
}
},
{
"name": "imageFormat",
"label": "Screenshot Format",
"type": "list",
"default":"PBM",
"description": "Graphics file format for screenshots [GIF|PBM|BMP]",
"list": [
{"l":"Compressed image (GIF)","v":"GIF"},
{"l":"Portable bitmap (PBM)","v":"PBM"},
{"l":"Windows bitmap (BMP)","v":"BMP"}
],
"category":"OBP60 Pages",
"capabilities": {
"obp60":"true"
}
},
{
"name": "page1type",
"label": "Type",
Expand Down
Loading

0 comments on commit df5ff1c

Please sign in to comment.