diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 282a1e28..82732c95 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -1,9 +1,6 @@ #ifdef BOARD_OBP60S3 #include -#define FASTLED_ALL_PINS_HARDWARE_SPI -#define FASTLED_ESP32_SPI_BUS FSPI -#define FASTLED_ESP32_FLASH_LOCK 1 #include // Driver for PCF8574 output modul from Horter #include // I2C #include // Driver for DS1388 RTC @@ -57,6 +54,9 @@ GxEPD2_BW display(GxEPD2_4 GxEPD2_BW & 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 @@ -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 \ No newline at end of file diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index e02cd8b8..bb53e8e9 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -2,10 +2,9 @@ #define _OBP60EXTENSIONPORT_H #include +#include +#include #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 // E-paper lib V2 @@ -39,6 +38,8 @@ GxEPD2_BW & getdisplay(); GxEPD2_BW & getdisplay(); #endif +void handleImageRequest(AsyncWebServerRequest *request); // HTTP hande image request + void hardwareInit(); void setPortPin(uint pin, bool value); // Set port pin for extension port diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 9922e887..ea68c62e 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -1,4 +1,6 @@ #ifdef BOARD_OBP60S3 +#include +#include #include "obp60task.h" #include "Pagedata.h" // Data exchange for pages #include "OBP60Hardware.h" // PIN definitions @@ -40,7 +42,6 @@ void OBP60Init(GwApi *api){ api->getLogger()->logDebug(GwLog::LOG,"obp60init running"); // Check I2C devices - // Init hardware hardwareInit(); @@ -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); diff --git a/lib/obp60task/platformio.ini b/lib/obp60task/platformio.ini index dc919a94..860977c4 100644 --- a/lib/obp60task/platformio.ini +++ b/lib/obp60task/platformio.ini @@ -18,6 +18,7 @@ lib_deps = Wire SPI esphome/AsyncTCP-esphome@2.0.1 + esphome/ESPAsyncWebServer-esphome@^3.3.0 robtillaart/PCF8574@0.3.9 adafruit/Adafruit Unified Sensor @ 1.1.13 blemasle/MCP23017@2.0.0