forked from btclock/btclock_v3
Small improvements for epd
This commit is contained in:
parent
753838b122
commit
03dbb8add6
1 changed files with 40 additions and 101 deletions
141
src/lib/epd.cpp
141
src/lib/epd.cpp
|
@ -138,6 +138,9 @@ uint8_t qrcode[800];
|
||||||
#define EPD_TASK_STACK_SIZE 2048
|
#define EPD_TASK_STACK_SIZE 2048
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BUSY_TIMEOUT_COUNT 200
|
||||||
|
#define BUSY_RETRY_DELAY pdMS_TO_TICKS(10)
|
||||||
|
|
||||||
void forceFullRefresh()
|
void forceFullRefresh()
|
||||||
{
|
{
|
||||||
for (uint i = 0; i < NUM_SCREENS; i++)
|
for (uint i = 0; i < NUM_SCREENS; i++)
|
||||||
|
@ -417,89 +420,36 @@ void splitText(const uint dispNum, const String &top, const String &bottom,
|
||||||
displays[dispNum].print(bottom);
|
displays[dispNum].print(bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void showChars(const uint dispNum, const String &chars, bool partial,
|
// Consolidate common display setup code into a helper function
|
||||||
// const GFXfont *font)
|
void setupDisplay(const uint dispNum, const GFXfont *font) {
|
||||||
// {
|
displays[dispNum].setRotation(2);
|
||||||
// displays[dispNum].setRotation(2);
|
displays[dispNum].setFont(font);
|
||||||
// displays[dispNum].setFont(font);
|
displays[dispNum].setTextColor(getFgColor());
|
||||||
// displays[dispNum].setTextColor(getFgColor());
|
displays[dispNum].fillScreen(getBgColor());
|
||||||
// int16_t tbx, tby;
|
}
|
||||||
// uint16_t tbw, tbh;
|
|
||||||
|
|
||||||
// displays[dispNum].getTextBounds(chars, 0, 0, &tbx, &tby, &tbw, &tbh);
|
void showDigit(const uint dispNum, char chr, bool partial, const GFXfont *font) {
|
||||||
|
String str(chr);
|
||||||
|
if (chr == '.') {
|
||||||
|
str = "!";
|
||||||
|
}
|
||||||
|
|
||||||
|
setupDisplay(dispNum, font);
|
||||||
|
|
||||||
|
int16_t tbx, tby;
|
||||||
|
uint16_t tbw, tbh;
|
||||||
|
displays[dispNum].getTextBounds(str, 0, 0, &tbx, &tby, &tbw, &tbh);
|
||||||
|
|
||||||
// // center the bounding box by transposition of the origin:
|
uint16_t x = ((displays[dispNum].width() - tbw) / 2) - tbx;
|
||||||
// uint16_t x = ((displays[dispNum].width() - tbw) / 2) - tbx;
|
uint16_t y = ((displays[dispNum].height() - tbh) / 2) - tby;
|
||||||
// uint16_t y = ((displays[dispNum].height() - tbh) / 2) - tby;
|
|
||||||
|
|
||||||
// displays[dispNum].fillScreen(getBgColor());
|
displays[dispNum].setCursor(x, y);
|
||||||
|
displays[dispNum].print(str);
|
||||||
|
|
||||||
// displays[dispNum].setCursor(x, y);
|
if (chr == '.') {
|
||||||
// displays[dispNum].print(chars);
|
displays[dispNum].fillRect(x, y, displays[dispNum].width(),
|
||||||
|
round(displays[dispNum].height() * 0.9), getBgColor());
|
||||||
// // displays[dispNum].setCursor(10, 3);
|
}
|
||||||
// // displays[dispNum].setFont(&FONT_SMALL);
|
|
||||||
// // displays[dispNum].setTextColor(getFgColor());
|
|
||||||
// // displays[dispNum].println("Y = " + y);
|
|
||||||
// }
|
|
||||||
|
|
||||||
void showDigit(const uint dispNum, char chr, bool partial,
|
|
||||||
const GFXfont *font)
|
|
||||||
{
|
|
||||||
String str(chr);
|
|
||||||
|
|
||||||
if (chr == '.')
|
|
||||||
{
|
|
||||||
str = "!";
|
|
||||||
}
|
|
||||||
displays[dispNum].setRotation(2);
|
|
||||||
displays[dispNum].setFont(font);
|
|
||||||
displays[dispNum].setTextColor(getFgColor());
|
|
||||||
int16_t tbx, tby;
|
|
||||||
uint16_t tbw, tbh;
|
|
||||||
|
|
||||||
displays[dispNum].getTextBounds(str, 0, 0, &tbx, &tby, &tbw, &tbh);
|
|
||||||
|
|
||||||
// center the bounding box by transposition of the origin:
|
|
||||||
uint16_t x = ((displays[dispNum].width() - tbw) / 2) - tbx;
|
|
||||||
uint16_t y = ((displays[dispNum].height() - tbh) / 2) - tby;
|
|
||||||
|
|
||||||
// if (str.equals("."))
|
|
||||||
// {
|
|
||||||
// // int16_t yAdvance = font->yAdvance;
|
|
||||||
// // uint8_t charIndex = 46 - font->first;
|
|
||||||
// // GFXglyph *glyph = (&font->glyph)[charIndex];
|
|
||||||
// int16_t tbx2, tby2;
|
|
||||||
// uint16_t tbw2, tbh2;
|
|
||||||
// displays[dispNum].getTextBounds(".!", 0, 0, &tbx2, &tby2, &tbw2, &tbh2);
|
|
||||||
|
|
||||||
// y = ((displays[dispNum].height() - tbh2) / 2) - tby2;
|
|
||||||
// // Serial.print("yAdvance");
|
|
||||||
// // Serial.println(yAdvance);
|
|
||||||
// // if (glyph != nullptr) {
|
|
||||||
// // Serial.print("height");
|
|
||||||
// // Serial.println(glyph->height);
|
|
||||||
// // Serial.print("yOffset");
|
|
||||||
// // Serial.println(glyph->yOffset);
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // y = 250-99+18+19;
|
|
||||||
// }
|
|
||||||
|
|
||||||
displays[dispNum].fillScreen(getBgColor());
|
|
||||||
|
|
||||||
displays[dispNum].setCursor(x, y);
|
|
||||||
displays[dispNum].print(str);
|
|
||||||
|
|
||||||
if (chr == '.')
|
|
||||||
{
|
|
||||||
displays[dispNum].fillRect(x, y, displays[dispNum].width(), round(displays[dispNum].height() * 0.9), getBgColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
// displays[dispNum].setCursor(10, 3);
|
|
||||||
// displays[dispNum].setFont(&FONT_SMALL);
|
|
||||||
// displays[dispNum].setTextColor(getFgColor());
|
|
||||||
// displays[dispNum].println("Y = " + y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t calculateDescent(const GFXfont *font) {
|
int16_t calculateDescent(const GFXfont *font) {
|
||||||
|
@ -517,21 +467,16 @@ int16_t calculateDescent(const GFXfont *font) {
|
||||||
void showChars(const uint dispNum, const String &chars, bool partial,
|
void showChars(const uint dispNum, const String &chars, bool partial,
|
||||||
const GFXfont *font)
|
const GFXfont *font)
|
||||||
{
|
{
|
||||||
displays[dispNum].setRotation(2);
|
setupDisplay(dispNum, font);
|
||||||
displays[dispNum].setFont(font);
|
|
||||||
displays[dispNum].setTextColor(getFgColor());
|
|
||||||
int16_t tbx, tby;
|
int16_t tbx, tby;
|
||||||
uint16_t tbw, tbh;
|
uint16_t tbw, tbh;
|
||||||
displays[dispNum].getTextBounds(chars, 0, 0, &tbx, &tby, &tbw, &tbh);
|
displays[dispNum].getTextBounds(chars, 0, 0, &tbx, &tby, &tbw, &tbh);
|
||||||
|
|
||||||
int16_t descent = calculateDescent(font);
|
|
||||||
|
|
||||||
// center the bounding box by transposition of the origin:
|
// center the bounding box by transposition of the origin:
|
||||||
uint16_t x = ((displays[dispNum].width() - tbw) / 2) - tbx;
|
uint16_t x = ((displays[dispNum].width() - tbw) / 2) - tbx;
|
||||||
uint16_t y = ((displays[dispNum].height() - tbh) / 2) - tby;
|
uint16_t y = ((displays[dispNum].height() - tbh) / 2) - tby;
|
||||||
displays[dispNum].fillScreen(getBgColor());
|
|
||||||
// displays[dispNum].setCursor(x, y);
|
|
||||||
// displays[dispNum].print(chars);
|
|
||||||
|
|
||||||
for (int i = 0; i < chars.length(); i++) {
|
for (int i = 0; i < chars.length(); i++) {
|
||||||
char c = chars[i];
|
char c = chars[i];
|
||||||
|
@ -603,8 +548,8 @@ bool renderIcon(const uint dispNum, const String &text, bool partial)
|
||||||
|
|
||||||
displays[dispNum].setPartialWindow(0, 0, displays[dispNum].width(),
|
displays[dispNum].setPartialWindow(0, 0, displays[dispNum].width(),
|
||||||
displays[dispNum].height());
|
displays[dispNum].height());
|
||||||
displays[dispNum].fillScreen(getBgColor());
|
displays[dispNum].fillScreen(getBgColor());
|
||||||
displays[dispNum].setTextColor(getFgColor());
|
displays[dispNum].setTextColor(getFgColor());
|
||||||
|
|
||||||
uint iconIndex = 0;
|
uint iconIndex = 0;
|
||||||
uint width = 122;
|
uint width = 122;
|
||||||
|
@ -649,9 +594,6 @@ bool renderIcon(const uint dispNum, const String &text, bool partial)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void renderQr(const uint dispNum, const String &text, bool partial)
|
void renderQr(const uint dispNum, const String &text, bool partial)
|
||||||
{
|
{
|
||||||
#ifdef USE_QR
|
#ifdef USE_QR
|
||||||
|
@ -695,15 +637,12 @@ void waitUntilNoneBusy()
|
||||||
while (EPD_BUSY[i].digitalRead())
|
while (EPD_BUSY[i].digitalRead())
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
vTaskDelay(10);
|
vTaskDelay(BUSY_RETRY_DELAY);
|
||||||
if (count == 200)
|
|
||||||
{
|
if (count == BUSY_TIMEOUT_COUNT) {
|
||||||
// displays[i].init(0, false);
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
vTaskDelay(100);
|
} else if (count > BUSY_TIMEOUT_COUNT + 5) {
|
||||||
}
|
log_e("Display %d busy timeout", i);
|
||||||
else if (count > 205)
|
|
||||||
{
|
|
||||||
Serial.printf("Busy timeout %d", i);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue