diff --git a/boards/m5stack-tab5/platformio.ini b/boards/m5stack-tab5/platformio.ini index 2ecf75bdd1..1bf41509b0 100644 --- a/boards/m5stack-tab5/platformio.ini +++ b/boards/m5stack-tab5/platformio.ini @@ -15,9 +15,9 @@ board_upload.speed = 1500000 build_src_filter =${env.build_src_filter} +<../boards/m5stack-tab5> build_src_flags = ${env.build_src_flags} - -D FP=1 ;3 - -D FM=2 ;6 - -D FG=3 ;9 + -D FP=2 + -D FM=4 + -D FG=6 build_flags = ${env.build_flags} @@ -28,6 +28,8 @@ build_flags = -DDEVICE_NAME='"M5Stack Tab5"' + -DUSB_as_HID=1 + -DUSE_M5GFX=1 -DHAS_SCREEN=1 -DUSE_CARDKB2=1 diff --git a/include/precompiler_flags.h b/include/precompiler_flags.h index 43f2509b6c..78432b0d09 100644 --- a/include/precompiler_flags.h +++ b/include/precompiler_flags.h @@ -75,6 +75,9 @@ #ifndef FG // LArge Font -> Fonte Grande #define FG 3 #endif +#ifndef TOUCH_FOOTER_HEIGHT + #define TOUCH_FOOTER_HEIGHT (LH * FM + 2 * (FP + 4)) +#endif #ifndef ROTATION #define ROTATION 1 #endif diff --git a/src/core/configPins.cpp b/src/core/configPins.cpp index cefab9190c..a0c5dce88d 100644 --- a/src/core/configPins.cpp +++ b/src/core/configPins.cpp @@ -3,8 +3,8 @@ #include "sd_functions.h" #include String getMacAddress() { - uint8_t mac[6]; - esp_read_mac(mac, ESP_MAC_WIFI_STA); + uint8_t mac[6] = {0}; + esp_read_mac(mac, ESP_MAC_BASE); char macStr[18]; snprintf( @@ -212,7 +212,7 @@ void BruceConfigPins::fromJson(JsonObject obj) { // log_e("Fail"); // } if (!root["i2c_bus"].isNull()) { -#if defined(SOC_HP_I2C_NUM) && SOC_HP_I2C_NUM < 2 && SYS_I2C_SDA >= 0 && SYS_I2C_SCL >= 0 && \ +#if defined(SOC_HP_I2C_NUM) && SOC_HP_I2C_NUM < 2 && SYS_I2C_SDA >= 0 && SYS_I2C_SCL >= 0 && \ !defined(BRUCE_BOARD_HAS_SOFTWARE_I2C) log_e("I2C Pins cannot be changed on this board, using default values"); i2c_bus = sys_i2c; diff --git a/src/core/display.cpp b/src/core/display.cpp index 3c5267b9c5..4c384ed068 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -68,12 +68,19 @@ void displayScrollingText(const String &text, Opt_Coord &coord, bool highlight) ***************************************************************************************/ void TouchFooter(uint16_t color) { #if defined(HAS_TOUCH) - tft.drawRoundRect(5, tftHeight + 2, tftWidth - 10, 43, 5, color); + tft.drawRoundRect( + BORDER_OFFSET_FROM_SCREEN_EDGE, + tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 3, + tftWidth - 2 * BORDER_OFFSET_FROM_SCREEN_EDGE, + TOUCH_FOOTER_HEIGHT - BORDER_OFFSET_FROM_SCREEN_EDGE + 3, + FP + 4, + color + ); tft.setTextColor(color); tft.setTextSize(FM); - tft.drawCentreString("PREV", tftWidth / 6, tftHeight + 4, 1); - tft.drawCentreString("SEL", tftWidth / 2, tftHeight + 4, 1); - tft.drawCentreString("NEXT", 5 * tftWidth / 6, tftHeight + 4, 1); + tft.drawCentreString("PREV", tftWidth / 6, tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 1, 1); + tft.drawCentreString("SEL", tftWidth / 2, tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 1, 1); + tft.drawCentreString("NEXT", 5 * tftWidth / 6, tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 1, 1); #endif } /*************************************************************************************** @@ -81,12 +88,19 @@ void TouchFooter(uint16_t color) { ** Description: Draw touch screen footer ***************************************************************************************/ void MegaFooter(uint16_t color) { - tft.drawRoundRect(5, tftHeight + 2, tftWidth - 10, 43, 5, color); + tft.drawRoundRect( + BORDER_OFFSET_FROM_SCREEN_EDGE, + tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 3, + tftWidth - 2 * BORDER_OFFSET_FROM_SCREEN_EDGE, + TOUCH_FOOTER_HEIGHT - BORDER_OFFSET_FROM_SCREEN_EDGE + 3, + FP + 4, + color + ); tft.setTextColor(color); tft.setTextSize(FM); - tft.drawCentreString("Exit", tftWidth / 6, tftHeight + 4, 1); - tft.drawCentreString("UP", tftWidth / 2, tftHeight + 4, 1); - tft.drawCentreString("DOWN", 5 * tftWidth / 6, tftHeight + 4, 1); + tft.drawCentreString("Exit", tftWidth / 6, tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 1, 1); + tft.drawCentreString("UP", tftWidth / 2, tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 1, 1); + tft.drawCentreString("DOWN", 5 * tftWidth / 6, tftHeight + BORDER_OFFSET_FROM_SCREEN_EDGE - 1, 1); } /*************************************************************************************** @@ -176,12 +190,11 @@ void displayRedStripe(const String &text, uint16_t fgcolor, uint16_t bgcolor) { if (fgcolor == bgcolor && fgcolor == TFT_WHITE) fgcolor = TFT_BLACK; // Calculate max chars per line based on font size - int maxCharsFM = (tftWidth - 20) / (LW * FM); - int maxCharsFP = (tftWidth - 20) / (LW * FP); + int maxCharsFM = (tftWidth - 2 * BORDER_PAD_X) / (LW * FM); + int maxCharsFP = (tftWidth - 2 * BORDER_PAD_X) / (LW * FP); // Determine if we need to wrap the text std::vector wrappedLines; - int boxHeight = 26; // Default height for single line if (text.length() * LW * FM < (tftWidth - 2 * FM * LW)) { // Text fits with FM font @@ -193,16 +206,18 @@ void displayRedStripe(const String &text, uint16_t fgcolor, uint16_t bgcolor) { wrappedLines = wrapText(text, maxCharsFP); } - // Adjust box height based on number of lines - if (wrappedLines.size() > 1) { boxHeight = 13 + (wrappedLines.size() * (size == FM ? 8 : 10)); } + // Line pitch must fit the actual glyph height at this size, or wrapped lines overlap. + int lineHeight = LH * size + 2; + int boxHeight = wrappedLines.size() * lineHeight + 8; tft.drawPixel(0, 0, 0); - tft.fillRoundRect(10, tftHeight / 2 - boxHeight / 2, tftWidth - 20, boxHeight, 7, bgcolor); + tft.fillRoundRect( + BORDER_PAD_X, tftHeight / 2 - boxHeight / 2, tftWidth - 2 * BORDER_PAD_X, boxHeight, 7, bgcolor + ); tft.setTextColor(fgcolor, bgcolor); tft.setTextSize(size); // Draw each line centered - int lineHeight = size == FM ? 8 : 10; int startY = tftHeight / 2 - (wrappedLines.size() * lineHeight) / 2; for (size_t i = 0; i < wrappedLines.size(); i++) { tft.drawCentreString(wrappedLines[i], tftWidth / 2, startY + i * lineHeight); @@ -242,16 +257,16 @@ int8_t displayMessage( while (end != -1) { tft.drawString(msg.substring(start, end), tftWidth / 2, y); - y += FM * 8; + y += FM * LH; start = end + 1; end = msg.indexOf('\n', start); } tft.drawString(msg.substring(start), tftWidth / 2, y); tft.setTextDatum(BC_DATUM); - int16_t buttonHeight = 20; - int16_t buttonY = tftHeight - buttonHeight - 5; - int16_t buttonWidth = tftWidth / 3 - 10; + int16_t buttonHeight = LH * FM + 4; + int16_t buttonY = tftHeight - buttonHeight - BORDER_OFFSET_FROM_SCREEN_EDGE; + int16_t buttonWidth = tftWidth / 3 - BORDER_PAD_X; int8_t totalButtons = (leftButton ? 1 : 0) + (centerButton ? 1 : 0) + (rightButton ? 1 : 0); int8_t selected = 0; // Start at first available button @@ -273,13 +288,21 @@ int8_t displayMessage( if (redraw) { if (leftButton) { - drawButton(5, buttonY, buttonWidth, buttonHeight, color, leftButton, selected == index); + drawButton( + BORDER_OFFSET_FROM_SCREEN_EDGE, + buttonY, + buttonWidth, + buttonHeight, + color, + leftButton, + selected == index + ); index++; } if (centerButton) { drawButton( - tftWidth / 3 + 5, + tftWidth / 3 + BORDER_OFFSET_FROM_SCREEN_EDGE, buttonY, buttonWidth, buttonHeight, @@ -292,7 +315,7 @@ int8_t displayMessage( if (rightButton) { drawButton( - tftWidth * 2 / 3 + 5, + tftWidth * 2 / 3 + BORDER_OFFSET_FROM_SCREEN_EDGE, buttonY, buttonWidth, buttonHeight, @@ -777,13 +800,23 @@ int loopOptions( ** Dependencia: prog_handler =>> 0 - Flash, 1 - LittleFS ***************************************************************************************/ void progressHandler(int progress, size_t total, const String &message) { - int barWidth = map(progress, 0, total, 0, tftWidth - 40); + int barHeight = LH * FP + 5; + int barY = tftHeight - barHeight - BORDER_PAD_Y; + int barWidth = map(progress, 0, total, 0, tftWidth - 4 * BORDER_PAD_X); if (barWidth < 3) { - tft.fillRect(6, 27, tftWidth - 12, tftHeight - 33, bruceConfig.bgColor); - tft.drawRect(18, tftHeight - 47, tftWidth - 36, 17, bruceConfig.priColor); + tft.fillRect( + BORDER_OFFSET_FROM_SCREEN_EDGE + 1, + STATUS_BAR_HEIGHT - 3, + tftWidth - 2 * (BORDER_OFFSET_FROM_SCREEN_EDGE + 1), + tftHeight - STATUS_BAR_HEIGHT - BORDER_OFFSET_FROM_SCREEN_EDGE, + bruceConfig.bgColor + ); + tft.drawRect( + 2 * BORDER_PAD_X, barY - 2, tftWidth - 4 * BORDER_PAD_X, barHeight + 4, bruceConfig.priColor + ); displayRedStripe(message, TFT_WHITE, bruceConfig.priColor); } - tft.fillRect(20, tftHeight - 45, barWidth, 13, bruceConfig.priColor); + tft.fillRect(2 * BORDER_PAD_X, barY, barWidth, barHeight, bruceConfig.priColor); } /*************************************************************************************** @@ -803,24 +836,26 @@ Opt_Coord drawOptions( // Uncomment to update the statusBar (causes flickering) // drawStatusBar(); - int32_t optionsTopY = tftHeight / 2 - menuSize * (FM * 8 + 4) / 2 - 5; + int32_t optionsTopY = tftHeight / 2 - menuSize * (FM * LH + 4) / 2 - BORDER_OFFSET_FROM_SCREEN_EDGE; tft.drawPixel(0, 0, bruceConfig.bgColor); if (firstRender) { tft.fillRoundRect( - tftWidth * 0.10, optionsTopY, tftWidth * 0.8, (FM * 8 + 4) * menuSize + 10, 5, bgcolor + tftWidth * 0.10, optionsTopY, tftWidth * 0.8, (FM * LH + 4) * menuSize + 10, 5, bgcolor ); tft.drawRoundRect( tftWidth * 0.10, - tftHeight / 2 - menuSize * (FM * 8 + 4) / 2 - 5, + tftHeight / 2 - menuSize * (FM * LH + 4) / 2 - BORDER_OFFSET_FROM_SCREEN_EDGE, tftWidth * 0.8, - (FM * 8 + 4) * menuSize + 10, + (FM * LH + 4) * menuSize + 10, 5, fgcolor ); } tft.setTextColor(fgcolor, bgcolor); tft.setTextSize(FM); - tft.setCursor(tftWidth * 0.10 + 5, tftHeight / 2 - menuSize * (FM * 8 + 4) / 2); + tft.setCursor( + tftWidth * 0.10 + BORDER_OFFSET_FROM_SCREEN_EDGE, tftHeight / 2 - menuSize * (FM * LH + 4) / 2 + ); int i = 0; int init = 0; @@ -857,14 +892,14 @@ Opt_Coord drawOptions( String text = ""; if (i == index) { text += ">"; - coord.x = tftWidth * 0.10 + 5 + FM * LW; + coord.x = tftWidth * 0.10 + BORDER_OFFSET_FROM_SCREEN_EDGE + FM * LW; coord.y = tft.getCursorY() + 4; coord.size = (tftWidth * 0.8 - 10) / (LW * FM) - 1; coord.fgcolor = fgcolor; coord.bgcolor = bgcolor; } else text += " "; text += String(options[i].label) + " "; - tft.setCursor(tftWidth * 0.10 + 5, tft.getCursorY() + 4); + tft.setCursor(tftWidth * 0.10 + BORDER_OFFSET_FROM_SCREEN_EDGE, tft.getCursorY() + 4); // Draw text with appropriate colors for selection if (i == index) { tft.setTextColor(bgcolor, bruceConfig.priColor); } @@ -895,15 +930,22 @@ void drawSubmenu(int index, std::vector