mirror of
https://github.com/paperdash/device-epd.git
synced 2024-11-04 12:00:27 +00:00
code clean up
This commit is contained in:
parent
788b95092f
commit
ff2cf9e5c7
108
src/display.cpp
108
src/display.cpp
@ -15,12 +15,6 @@
|
||||
|
||||
GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=*/5, /*DC=*/17, /*RST=*/16, /*BUSY=*/4));
|
||||
|
||||
void saveScreen();
|
||||
void writeBitmap(const char filename[], const uint8_t bitmap[], int16_t w, int16_t h, uint16_t depth = 1);
|
||||
uint8_t filldata[] = {0x0, 0x23, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0x0};
|
||||
void write16(File &f, uint16_t v);
|
||||
void write32(File &f, uint32_t v);
|
||||
|
||||
void setupDisplay()
|
||||
{
|
||||
Serial.println("setupDisplay");
|
||||
@ -51,13 +45,6 @@ void displayWriteFramebuffer(uint8_t bitmap[])
|
||||
void displayFlush()
|
||||
{
|
||||
display.nextPage();
|
||||
/*
|
||||
// TODO setting ?
|
||||
if (true)
|
||||
{
|
||||
saveScreen();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void printSplash()
|
||||
@ -82,98 +69,3 @@ void printSplash()
|
||||
display.print(Hello);
|
||||
} while (display.nextPage());
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
void saveScreen()
|
||||
{
|
||||
unsigned long startMills = millis();
|
||||
writeBitmap("/screen.bmp", display.getBuffer(), display.width(), display.height());
|
||||
Serial.println(millis() - startMills);
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
void writeBitmap(const char filename[], const uint8_t bitmap[], int16_t w, int16_t h, uint16_t depth)
|
||||
{
|
||||
File bitmapFile;
|
||||
uint32_t rowSizeCode = (w + 8 - depth) * depth / 8;
|
||||
|
||||
// BMP rows are padded (if needed) to 4-byte boundary
|
||||
uint32_t rowSizeBMP = (w * depth / 8 + 3) & ~3;
|
||||
Serial.print("writeBitmap(\"");
|
||||
Serial.print(filename);
|
||||
Serial.println("\")");
|
||||
//Serial.print("rowSizeCode ");
|
||||
//Serial.println(rowSizeCode);
|
||||
//Serial.print("rowSizeBMP ");
|
||||
//Serial.println(rowSizeBMP);
|
||||
uint32_t headerSize = 40;
|
||||
uint32_t imageOffset = 62;
|
||||
uint32_t fileSize = imageOffset + h * rowSizeBMP;
|
||||
|
||||
String tmpFile = filename;
|
||||
tmpFile += ".tmp";
|
||||
|
||||
bitmapFile = SPIFFS.open(tmpFile, FILE_WRITE);
|
||||
if (bitmapFile)
|
||||
{
|
||||
bitmapFile.seek(0);
|
||||
write16(bitmapFile, 0x4D42); // BMP signature
|
||||
write32(bitmapFile, fileSize); // fileSize
|
||||
write32(bitmapFile, 0); // creator bytes
|
||||
write32(bitmapFile, imageOffset); // image offset
|
||||
write32(bitmapFile, headerSize); // Header size
|
||||
write32(bitmapFile, w); // image width
|
||||
write32(bitmapFile, h); // image height
|
||||
write16(bitmapFile, 1); // # planes
|
||||
write16(bitmapFile, depth); // // bits per pixel
|
||||
write32(bitmapFile, 0); // format uncompressed
|
||||
|
||||
uint32_t j = 0;
|
||||
for (uint32_t i = bitmapFile.position(); i < imageOffset; i++)
|
||||
{
|
||||
bitmapFile.write(filldata[j++]); // remaining header bytes
|
||||
}
|
||||
|
||||
uint32_t rowidx = 0;
|
||||
for (uint16_t row = 0; row < h; row++) // for each line
|
||||
{
|
||||
uint32_t colidx;
|
||||
for (colidx = 0; colidx < rowSizeCode; colidx++)
|
||||
{
|
||||
uint8_t data = pgm_read_byte(&bitmap[rowidx + colidx]);
|
||||
bitmapFile.write(data);
|
||||
}
|
||||
rowidx += rowSizeCode;
|
||||
while (colidx++ < rowSizeBMP)
|
||||
{
|
||||
bitmapFile.write(uint8_t(0)); // padding
|
||||
}
|
||||
}
|
||||
bitmapFile.close();
|
||||
|
||||
SPIFFS.remove(filename);
|
||||
SPIFFS.rename(tmpFile, filename);
|
||||
|
||||
Serial.println("done");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("open file for write failed!");
|
||||
}
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
void write16(File &f, uint16_t v)
|
||||
{
|
||||
f.write(uint8_t(v));
|
||||
f.write(uint8_t(v >> 8));
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
void write32(File &f, uint32_t v)
|
||||
{
|
||||
f.write(uint8_t(v));
|
||||
f.write(uint8_t(v >> 8));
|
||||
f.write(uint8_t(v >> 16));
|
||||
f.write(uint8_t(v >> 24));
|
||||
}
|
@ -36,7 +36,7 @@ bool downloadFile(String url, const char *path)
|
||||
int httpCode = http.GET();
|
||||
if (httpCode != HTTP_CODE_OK)
|
||||
{
|
||||
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode != HTTP_CODE_OK && httpCode).c_str());
|
||||
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
|
||||
hasError = true;
|
||||
}
|
||||
else
|
||||
|
@ -5,9 +5,12 @@
|
||||
|
||||
structImageProcess ImageProcess;
|
||||
// TODO use dynamic display width
|
||||
static constexpr int MAX_WIDTH = 640;
|
||||
static int16_t curRowDelta[MAX_WIDTH + 1];
|
||||
static int16_t nextRowDelta[MAX_WIDTH + 1];
|
||||
constexpr uint16_t MAX_WIDTH = 640;
|
||||
int16_t curRowDelta[MAX_WIDTH + 1];
|
||||
int16_t nextRowDelta[MAX_WIDTH + 1];
|
||||
|
||||
// TODO auf das umbauen
|
||||
//uint8_t curRowDelta[640 / 8];
|
||||
|
||||
void setupImage()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user