M5 display support fixes

This commit is contained in:
Klaus K Wilting 2020-04-10 18:40:40 +02:00
parent 4584a5a34b
commit bdcd05cb21
3 changed files with 47 additions and 24 deletions

View File

@ -83,7 +83,6 @@ void dp_println(int lines = 1);
void dp_printf(const char *format, ...); void dp_printf(const char *format, ...);
void dp_setFont(int font, int inv = 0); void dp_setFont(int font, int inv = 0);
void dp_dump(uint8_t *pBuffer); void dp_dump(uint8_t *pBuffer);
void dp_setCursor(int x, int y);
void dp_setTextCursor(int col, int row); void dp_setTextCursor(int col, int row);
void dp_contrast(uint8_t contrast); void dp_contrast(uint8_t contrast);
void dp_clear(void); void dp_clear(void);

View File

@ -75,6 +75,7 @@ void dp_setup(int contrast) {
tft.setRotation(MY_DISPLAY_FLIP ? 3 : 1); tft.setRotation(MY_DISPLAY_FLIP ? 3 : 1);
tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); tft.invertDisplay(MY_DISPLAY_INVERT ? true : false);
tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR);
//tft.setTextPadding(MY_DISPLAY_WIDTH);
#endif #endif
@ -139,7 +140,7 @@ void dp_init(bool verbose) {
dp_printqr(3, 3, deveui); dp_printqr(3, 3, deveui);
// display DEVEUI as plain text on the right // display DEVEUI as plain text on the right
const int x_offset = (QR_SCALEFACTOR * 29 + 4) / 8 + 2; const int x_offset = QR_SCALEFACTOR * 29 + 14;
dp_setTextCursor(x_offset, 0); dp_setTextCursor(x_offset, 0);
dp_setFont(MY_FONT_NORMAL); dp_setFont(MY_FONT_NORMAL);
dp_printf("DEVEUI"); dp_printf("DEVEUI");
@ -235,7 +236,7 @@ start:
if (DisplayPage < 6) { if (DisplayPage < 6) {
dp_setFont(MY_FONT_STRETCHED); dp_setFont(MY_FONT_STRETCHED);
dp_printf("PAX:%-4d", macs.size()); dp_printf("PAX:%-4d", macs.size());
dp_println(3); dp_setTextCursor(0, 2);
} }
switch (DisplayPage) { switch (DisplayPage) {
@ -379,7 +380,6 @@ start:
// page 3: BME280/680 // page 3: BME280/680
case 3: case 3:
dp_setFont(MY_FONT_STRETCHED); dp_setFont(MY_FONT_STRETCHED);
dp_setTextCursor(0, 2);
#if (HAS_BME) #if (HAS_BME)
// line 2-3: Temp // line 2-3: Temp
dp_printf("TMP:%-2.1f", bme_status.temperature); dp_printf("TMP:%-2.1f", bme_status.temperature);
@ -453,21 +453,38 @@ start:
// ------------- display helper functions ----------------- // ------------- display helper functions -----------------
void dp_setTextCursor(int col, int row) { void dp_setTextCursor(int x, int y) {
dp_col = col; // x represents the pixel column
dp_row = row; // y represents the text row
#if (HAS_DISPLAY) == 1
oledSetCursor(&ssoled, dp_col * 8, dp_row); dp_col = x;
#elif (HAS_DISPLAY) == 2
tft.setCursor(dp_row, dp_col);
#endif
}
void dp_setCursor(int x, int y) {
#if (HAS_DISPLAY) == 1 #if (HAS_DISPLAY) == 1
oledSetCursor(&ssoled, x, y); switch (dp_font >> 1) {
case MY_FONT_STRETCHED: // 16x16 on OLED
case MY_FONT_LARGE: // 16x32 on OLED
dp_row = y * 2;
break;
case MY_FONT_SMALL: // 6x8 on OLED
case MY_FONT_NORMAL: // 8x8 on OLED
default:
dp_row = y;
break;
}
oledSetCursor(&ssoled, dp_col, dp_row);
#elif (HAS_DISPLAY) == 2 #elif (HAS_DISPLAY) == 2
tft.setCursor(x, y); switch (dp_font >> 1) {
case MY_FONT_STRETCHED:
case MY_FONT_LARGE:
dp_row = y * 26;
break;
case MY_FONT_SMALL:
case MY_FONT_NORMAL:
default:
dp_row = y * 16;
break;
}
tft.setCursor(dp_col, dp_row);
#endif #endif
} }
@ -497,6 +514,7 @@ void dp_println(int lines) {
#if (HAS_DISPLAY) == 1 #if (HAS_DISPLAY) == 1
dp_setTextCursor(dp_col, dp_row); dp_setTextCursor(dp_col, dp_row);
#elif (HAS_DISPLAY) == 2 #elif (HAS_DISPLAY) == 2
for (int i = 1; i <= lines; i++)
tft.println(); tft.println();
#endif #endif
}; };

View File

@ -47,12 +47,17 @@ void start_ota_update() {
dp_setup(); dp_setup();
dp_printf(0, 0, 0, 1, "SOFTWARE UPDATE"); dp_printf("SOFTWARE UPDATE");
dp_printf(0, 1, 0, 0, "WiFi connect .."); dp_println();
dp_printf(0, 2, 0, 0, "Has Update? .."); dp_printf("WiFi connect ..");
dp_printf(0, 3, 0, 0, "Fetching .."); dp_println();
dp_printf(0, 4, 0, 0, "Downloading .."); dp_printf("Has Update? ..");
dp_printf(0, 5, 0, 0, "Rebooting .."); dp_println();
dp_printf("Fetching ..");
dp_println();
dp_printf("Downloading ..");
dp_println();
dp_printf("Rebooting ..");
dp_dump(displaybuf); dp_dump(displaybuf);
#endif #endif
@ -302,11 +307,12 @@ void ota_display(const uint8_t row, const std::string status,
const std::string msg) { const std::string msg) {
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
dp_setFont(MY_FONT_SMALL); dp_setFont(MY_FONT_SMALL);
dp_setTextCursor(0, row); dp_setTextCursor(14, row);
dp_printf(status.substr(0, 2).c_str()); dp_printf(status.substr(0, 2).c_str());
if (!msg.empty()) { if (!msg.empty()) {
dp_printf(" "); dp_printf(" ");
dp_printf(msg.substr(0, 16).c_str()); dp_printf(msg.substr(0, 16).c_str());
dp_println();
} }
dp_dump(displaybuf); dp_dump(displaybuf);
#endif #endif