Skip to content

Commit

Permalink
Screen output via HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
norbert-walter committed Nov 4, 2024
1 parent 72acf9f commit d9cd544
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
51 changes: 48 additions & 3 deletions lib/obp60task/OBP60Extensions.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifdef BOARD_OBP60S3

#include <Arduino.h>
#define FASTLED_ALL_PINS_HARDWARE_SPI
#define FASTLED_ESP32_SPI_BUS FSPI
#define FASTLED_ESP32_FLASH_LOCK 1
#include <PCF8574.h> // Driver for PCF8574 output modul from Horter
#include <Wire.h> // I2C
#include <RTClib.h> // Driver for DS1388 RTC
Expand Down Expand Up @@ -57,6 +54,9 @@ GxEPD2_BW<GxEPD2_420_SE0420NQ04, GxEPD2_420_SE0420NQ04::HEIGHT> display(GxEPD2_4
GxEPD2_BW<GxEPD2_420_SE0420NQ04, GxEPD2_420_SE0420NQ04::HEIGHT> & getdisplay(){return display;}
#endif

// Framebuffer for HTTP output
uint8_t framebuffer[GxEPD_WIDTH * GxEPD_HEIGHT / 8]; // Binary framebuffer (1 bit per pixel)

// Horter I2C moduls
PCF8574 pcf8574_Out(PCF8574_I2C_ADDR1); // First digital output modul PCF8574 from Horter

Expand Down Expand Up @@ -404,4 +404,49 @@ void generatorGraphic(uint x, uint y, int pcolor, int bcolor){
getdisplay().print("G");
}

// BMP header for black-and-white image (1 bit per pixel)
const uint8_t bmp_header[] = {
0x42, 0x4D, // 'BM' signature
0x36, 0x08, 0x00, 0x00, // File size in bytes (to be adjusted later)
0x00, 0x00, 0x00, 0x00, // Reserved
0x3E, 0x00, 0x00, 0x00, // Data offset (pixel array starts at byte 62)
0x28, 0x00, 0x00, 0x00, // Header size (40 bytes)
(uint8_t)(GxEPD_WIDTH & 0xFF), (uint8_t)((GxEPD_WIDTH >> 8) & 0xFF), 0x00, 0x00, // Image width
(uint8_t)(GxEPD_HEIGHT & 0xFF), (uint8_t)((GxEPD_HEIGHT >> 8) & 0xFF), 0x00, 0x00, // Image height
0x01, 0x00, // Number of color planes (1)
0x01, 0x00, // Color depth (1 bit per pixel)
0x00, 0x00, 0x00, 0x00, // Compression (none)
0x00, 0x08, 0x00, 0x00, // Image data size (calculate)
0x13, 0x0B, 0x00, 0x00, // Horizontal resolution (2835 pixels/meter)
0x13, 0x0B, 0x00, 0x00, // Vertical resolution (2835 pixels/meter)
0x02, 0x00, 0x00, 0x00, // Colors in color palette (2)
0x00, 0x00, 0x00, 0x00, // Important colors (all)
0x00, 0x00, 0x00, 0x00, // Color palette: Black
0xFF, 0xFF, 0xFF, 0x00 // Color palette: White
};

// Function to handle HTTP image request
void handleImageRequest(AsyncWebServerRequest *request) {
// Fill framebuffer (test pattern, e.g., diagonal lines)
for (int i = 0; i < sizeof(framebuffer); i++) {
framebuffer[i] = (i % 2 == 0) ? 0xFF : 0x00; // Example pattern
}

// Calculate total file size
size_t imageSize = sizeof(bmp_header) + sizeof(framebuffer);

// Combine header and framebuffer into one buffer
uint8_t* imageBuffer = new uint8_t[imageSize];
memcpy(imageBuffer, bmp_header, sizeof(bmp_header));
memcpy(imageBuffer + sizeof(bmp_header), framebuffer, sizeof(framebuffer));

// Send response with content type and custom header
AsyncWebServerResponse *response = request->beginResponse_P(200, "image/bmp", (const uint8_t*)imageBuffer, imageSize);
response->addHeader("Content-Disposition", "inline; filename=image.bmp");
request->send(response);

// Free the allocated buffer
delete[] imageBuffer;
}

#endif
7 changes: 4 additions & 3 deletions lib/obp60task/OBP60Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#define _OBP60EXTENSIONPORT_H

#include <Arduino.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include "OBP60Hardware.h"
#define FASTLED_ALL_PINS_HARDWARE_SPI
#define FASTLED_ESP32_SPI_BUS FSPI
#define FASTLED_ESP32_FLASH_LOCK 1
#include "LedSpiTask.h"
#include <GxEPD2_BW.h> // E-paper lib V2

Expand Down Expand Up @@ -39,6 +38,8 @@ GxEPD2_BW<GxEPD2_420_GYE042A87, GxEPD2_420_GYE042A87::HEIGHT> & getdisplay();
GxEPD2_BW<GxEPD2_420_SE0420NQ04, GxEPD2_420_SE0420NQ04::HEIGHT> & getdisplay();
#endif

void handleImageRequest(AsyncWebServerRequest *request); // HTTP hande image request

void hardwareInit();

void setPortPin(uint pin, bool value); // Set port pin for extension port
Expand Down
9 changes: 8 additions & 1 deletion lib/obp60task/obp60task.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#ifdef BOARD_OBP60S3
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include "obp60task.h"
#include "Pagedata.h" // Data exchange for pages
#include "OBP60Hardware.h" // PIN definitions
Expand Down Expand Up @@ -40,7 +42,6 @@ void OBP60Init(GwApi *api){
api->getLogger()->logDebug(GwLog::LOG,"obp60init running");

// Check I2C devices


// Init hardware
hardwareInit();
Expand Down Expand Up @@ -293,6 +294,12 @@ void underVoltageDetection(GwApi *api){
void OBP60Task(GwApi *api){
// vTaskDelete(NULL);
// return;

// Start HTTP creen copy service (BMP-Picture)
AsyncWebServer server(8080);
server.on("/image.bmp", HTTP_GET, handleImageRequest);
server.begin();

GwLog *logger=api->getLogger();
GwConfigHandler *config=api->getConfig();
startLedTask(api);
Expand Down
1 change: 1 addition & 0 deletions lib/obp60task/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lib_deps =
Wire
SPI
esphome/[email protected]
esphome/ESPAsyncWebServer-esphome@^3.3.0
robtillaart/[email protected]
adafruit/Adafruit Unified Sensor @ 1.1.13
blemasle/[email protected]
Expand Down

0 comments on commit d9cd544

Please sign in to comment.