diff --git a/src/boards_pinout.h b/src/boards_pinout.h index 501c66c..340a23f 100644 --- a/src/boards_pinout.h +++ b/src/boards_pinout.h @@ -152,6 +152,7 @@ #define BOARD_POWERON 10 #define BOARD_SDCARD_CS 39 #define BATTERY_PIN 4 + #define BOARD_BL_PIN 42 #define BOARD_I2C_SDA 18 #define BOARD_I2C_SCL 8 #define RADIO_SCLK_PIN 40 diff --git a/src/display.cpp b/src/display.cpp index 6959c52..27e5f70 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -11,7 +11,8 @@ String currentSymbol, lastSymbol, lastHeader; #ifdef HAS_TFT #include - TFT_eSPI tft = TFT_eSPI(); + TFT_eSPI tft = TFT_eSPI(); + TFT_eSprite sprite = TFT_eSprite(&tft); #ifdef HELTEC_WIRELESS_TRACKER #define bigSizeFont 2 @@ -19,6 +20,16 @@ String currentSymbol, lastSymbol, lastHeader; #define lineSpacing 12 #endif #if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS) + + int brightnessValues[6] = {70, 90, 120, 160, 200, 250}; + int tftBrightness = 5; + unsigned short grays[13]; + + #define color1 TFT_BLACK + #define color2 0x0249 + #define red 0xB061 + #define green 0x1B08 + #define bigSizeFont 4 #define smallSizeFont 2 #define lineSpacing 22 @@ -70,6 +81,116 @@ bool symbolAvailable = true; extern logging::Logger logger; +void drawTop(const String& header, const String& datetime, const String& location) { + sprite.fillSprite(TFT_BLACK); + sprite.fillRect(0, 0, 320, 38, red); + sprite.setTextFont(0); + sprite.setTextSize(4); + sprite.setTextColor(TFT_WHITE, red); + sprite.drawString(currentBeacon->callsign, 3, 5); + + sprite.setTextSize(1); + sprite.setTextColor(TFT_WHITE, red); + String date = datetime.substring(0, datetime.indexOf(" ")); + sprite.drawString(date, 258, 5); + String time = datetime.substring(datetime.indexOf(" ") + 3); + sprite.drawString("UTC:" + time, 246, 15); + + sprite.fillRect(0, 38, 320, 2, TFT_ORANGE); + + sprite.fillRect(0, 40, 320, 22, TFT_DARKGREY); + sprite.setTextSize(2); + sprite.setTextColor(TFT_WHITE, TFT_DARKGREY); + sprite.drawString(location, 8, 44); +} + + void drawBody(const String& linea1, const String& linea2, const String& linea3, const String& linea4, const String& linea5, const String& linea6) { + sprite.setTextSize(2); + sprite.setTextColor(TFT_WHITE, TFT_BLACK); + + sprite.drawString(linea1, 3, 70); + sprite.drawString(linea2, 3, 90); + sprite.drawString(linea3, 3, 110); + sprite.drawString(linea4, 3, 130); + sprite.drawString(linea5, 3, 150); + sprite.drawString(linea6, 3, 170); + } + + /*String lat = location.substring(0, location.indexOf(" ")); + sprite.drawString(lat, 3, 46); + String temp = location.substring(location.indexOf(" ") + 1); + String lng = temp.substring(0, temp.indexOf(" ")); + sprite.drawString(lng, 126, 46); + String sat = temp.substring(temp.indexOf(" ") + 1); + sprite.setTextSize(1); + sprite.drawString(sat, 290, 25);*/ + + + //sprite.fillRect(0, 38, 320, 2, TFT_DARKGREY); + //sprite.fillRect(0, 20, 320, 2, color2); // linea bajo techo + //sprite.fillRect(0, 202, 320, 2, 0xBC81); // linea abajo amarilla + + //sprite.fillSmoothRoundRect( 0, 218, 320, 22 , 2, red, TFT_BLACK); // piso + + //sprite.fillSmoothRoundRect( 4, 2, 56, 14 , 2, grays[6], grays[9]); // cuadrado gris izquierda arriba + //sprite.fillSmoothRoundRect( 2, 2, 16, 14 , 2, TFT_BLUE, grays[9]); // cuadrado rojo izquierda arriba + + //sprite.fillSmoothRoundRect(272, 2, 40, 16 , 2, green, grays[9]); // bateria + //sprite.fillSmoothRoundRect(308, 6, 8, 8 , 2, green, grays[9]); // bateria + //sprite.fillSmoothRoundRect(275, 4, 34, 12 , 2, TFT_BLACK, green); // centro bateria + + /*for (int i = 0; i < 5; i++) { // cubos que muestran el brillo (abajo a la derecha) + if(i < tftBrightness) { + sprite.fillRect(282+(i*8), 207, 5, 8, grays[3]); + } else { + sprite.fillRect(282+(i*8), 207, 5, 8, grays[7]); + } + }*/ + + //for (int i = 0; i < 9; i++) sprite.drawFastHLine(4, 38+(i*18), 312, grays[8]); // draw horizonatl lines + + + /*sprite.setTextFont(0); + sprite.setTextSize(1); + sprite.setTextColor(TFT_WHITE, TFT_BLUE); + sprite.drawString("LoRa", 6, 4); + sprite.setTextColor(TFT_BLACK, grays[6]); + sprite.drawString("APRS", 21, 4); // escribir DECK en x=21 , y=4*/ + + + + /*sprite.setTextColor(grays[1],c olor2); + sprite.drawString(notice, 6, 223, 2); + + for (int i = 0; i < nMsg + 1; i++) { + if (msg[i].length() > 0) { + if (writer[i] == 1) { + sprite.setTextColor(grays[1], color1); else sprite.setTextColor(0x663C, color1); + sprite.drawString(msg[i], 6, 25 + (i*18), 2); + } + } + } + + sprite.setTextColor(grays[5], TFT_BLACK); + sprite.unloadFont(); + sprite.drawString("Your ID: " + name, 2, 208); + sprite.setTextColor(grays[4],grays[9]); + sprite.drawString("VOLOS", 210, 2); + sprite.setTextColor(grays[5], grays[9]); + sprite.drawString("projects", 210, 9); + sprite.setTextColor(grays[2], TFT_BLACK); + sprite.drawString(String(analogRead(4)), 280, 7); + + sprite.setTextColor(grays[8], color2); + sprite.drawString("ENTER YOUR MESSAGE", 200, 226); + + sprite.setTextColor(grays[7], TFT_BLACK); + sprite.drawString("SND:", 120, 208); + sprite.drawString(String(sndN), 145, 8); + + sprite.drawString("REC:",190,208); + sprite.drawString(String(recN), 215, 208);*/ + void cleanTFT() { #ifdef HAS_TFT tft.fillScreen(TFT_BLACK); @@ -87,15 +208,36 @@ String fillStringLength(const String& line, uint8_t length) { void displaySetup() { delay(500); #ifdef HAS_TFT - tft.init(); - tft.begin(); - if (Config.display.turn180) { - tft.setRotation(3); - } else { - tft.setRotation(1); - } - tft.setTextFont(0); - tft.fillScreen(TFT_BLACK); + #if defined(TTGO_T_DECK_PLUS) + tft.init(); + tft.begin(); + if (Config.display.turn180) { + tft.setRotation(3); + } else { + tft.setRotation(1); + } + analogWrite(BOARD_BL_PIN, brightnessValues[tftBrightness]); + tft.setTextFont(0); + tft.fillScreen(TFT_BLACK); + + sprite.createSprite(320,240); + + int co = 210; + for (int i = 0; i < 13; i++) { + grays[i] = tft.color565(co, co, co); + co = co - 20; + } + #else + tft.init(); + tft.begin(); + if (Config.display.turn180) { + tft.setRotation(3); + } else { + tft.setRotation(1); + } + tft.setTextFont(0); + tft.fillScreen(TFT_BLACK); + #endif #else #ifdef OLED_DISPLAY_HAS_RST_PIN pinMode(OLED_RST, OUTPUT); @@ -163,27 +305,32 @@ void displayToggle(bool toggle) { void displayShow(const String& header, const String& line1, const String& line2, int wait) { #ifdef HAS_TFT - String filledLine1 = fillStringLength(line1, 22); - String filledLine2 = fillStringLength(line2, 22); - const String* const lines[] = {&filledLine1, &filledLine2}; - - cleanTFT(); - tft.setTextColor(TFT_WHITE,TFT_BLACK); - tft.setTextSize(bigSizeFont); - tft.setCursor(0, 0); + #if defined(TTGO_T_DECK_PLUS) + drawTop(header, line1, line2); + sprite.pushSprite(0,0); + #else + String filledLine1 = fillStringLength(line1, 22); + String filledLine2 = fillStringLength(line2, 22); + const String* const lines[] = {&filledLine1, &filledLine2}; + + cleanTFT(); + tft.setTextColor(TFT_WHITE,TFT_BLACK); + tft.setTextSize(bigSizeFont); + tft.setCursor(0, 0); - if (header != lastHeader) { - tft.print(fillStringLength(header, 11)); - lastHeader = header; - } else { - tft.print(header); - } + if (header != lastHeader) { + tft.print(fillStringLength(header, 11)); + lastHeader = header; + } else { + tft.print(header); + } - tft.setTextSize(smallSizeFont); - for (int i = 0; i < 2; i++) { - tft.setCursor(0, ((lineSpacing * (2 + i)) - 2)); - tft.print(*lines[i]); - } + tft.setTextSize(smallSizeFont); + for (int i = 0; i < 2; i++) { + tft.setCursor(0, ((lineSpacing * (2 + i)) - 2)); + tft.print(*lines[i]); + } + #endif #else const String* const lines[] = {&line1, &line2}; @@ -214,76 +361,81 @@ void displayShow(const String& header, const String& line1, const String& line2, void displayShow(const String& header, const String& line1, const String& line2, const String& line3, const String& line4, const String& line5, int wait) { #ifdef HAS_TFT - String filledLine1 = fillStringLength(line1, 22); - String filledLine2 = fillStringLength(line2, 22); - String filledLine3 = fillStringLength(line3, 22); - String filledLine4 = fillStringLength(line4, 22); - String filledLine5 = fillStringLength(line5, 22); - const String* const lines[] = {&filledLine1, &filledLine2, &filledLine3, &filledLine4, &filledLine5}; + #if defined(TTGO_T_DECK_PLUS) + drawTop(header, line1, line2); + drawBody(header, line1, line2, line3, line4, line5); + sprite.pushSprite(0,0); + #else + String filledLine1 = fillStringLength(line1, 22); + String filledLine2 = fillStringLength(line2, 22); + String filledLine3 = fillStringLength(line3, 22); + String filledLine4 = fillStringLength(line4, 22); + String filledLine5 = fillStringLength(line5, 22); + const String* const lines[] = {&filledLine1, &filledLine2, &filledLine3, &filledLine4, &filledLine5}; - if (menuDisplay != lastMenuDisplay) { - lastMenuDisplay = menuDisplay; - cleanTFT(); - } - //tft.setTextColor(TFT_RED,TFT_BLACK); - tft.setTextColor(TFT_WHITE,TFT_BLACK); - tft.setTextSize(bigSizeFont); - tft.setCursor(0, 0); + if (menuDisplay != lastMenuDisplay) { + lastMenuDisplay = menuDisplay; + cleanTFT(); + } + //tft.setTextColor(TFT_RED,TFT_BLACK); + tft.setTextColor(TFT_WHITE,TFT_BLACK); + tft.setTextSize(bigSizeFont); + tft.setCursor(0, 0); - if (header != lastHeader) { - tft.print(fillStringLength(header, 11)); - lastHeader = header; - } else { - tft.print(header); - } - - tft.setTextSize(smallSizeFont); - for (int i = 0; i < 5; i++) { - tft.setCursor(0, ((lineSpacing * (2 + i)) - 2)); - tft.print(*lines[i]); - } - if (menuDisplay == 0 && Config.display.showSymbol) { - int symbol = 100; - for (int i = 0; i < symbolArraySize; i++) { - if (currentBeacon->symbol == symbolArray[i]) { - symbol = i; - break; - } + if (header != lastHeader) { + tft.print(fillStringLength(header, 11)); + lastHeader = header; + } else { + tft.print(header); } - symbolAvailable = symbol != 100; + tft.setTextSize(smallSizeFont); + for (int i = 0; i < 5; i++) { + tft.setCursor(0, ((lineSpacing * (2 + i)) - 2)); + tft.print(*lines[i]); + } + if (menuDisplay == 0 && Config.display.showSymbol) { + int symbol = 100; + for (int i = 0; i < symbolArraySize; i++) { + if (currentBeacon->symbol == symbolArray[i]) { + symbol = i; + break; + } + } - /* - * Symbol alternate every 5s - * If bluetooth is disconnected or if we are in the first part of the clock, then we show the APRS symbol - * Otherwise, we are in the second part of the clock, then we show BT connected - */ + symbolAvailable = symbol != 100; - const auto time_now = now(); - if (!bluetoothConnected || time_now % 10 < 5) { - if (symbolAvailable) { - currentSymbol = symbolArray[symbol]; + /* + * Symbol alternate every 5s + * If bluetooth is disconnected or if we are in the first part of the clock, then we show the APRS symbol + * Otherwise, we are in the second part of the clock, then we show BT connected + */ + + const auto time_now = now(); + if (!bluetoothConnected || time_now % 10 < 5) { + if (symbolAvailable) { + currentSymbol = symbolArray[symbol]; + #if defined(HELTEC_WIRELESS_TRACKER) + if (currentSymbol != lastSymbol) { + tft.fillRect((TFT_WIDTH - SYMBOL_WIDTH + (128 - TFT_WIDTH)), 0, SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_BLACK); + lastSymbol = currentSymbol; + } + tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH + (128 - TFT_WIDTH)), 0, symbolsAPRS[symbol], SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE);//, TFT_RED); + #endif + #if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS) + tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH), 0, symbolsAPRS[symbol], SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE);//, TFT_RED); + #endif + } + } else if (bluetoothConnected) { // TODO In this case, the text symbol stay displayed due to symbolAvailable false in menu_utils #if defined(HELTEC_WIRELESS_TRACKER) - if (currentSymbol != lastSymbol) { - tft.fillRect((TFT_WIDTH - SYMBOL_WIDTH + (128 - TFT_WIDTH)), 0, SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_BLACK); - lastSymbol = currentSymbol; - } - tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH + (128 - TFT_WIDTH)), 0, symbolsAPRS[symbol], SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE);//, TFT_RED); + tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH + (128 - TFT_WIDTH)), 0, bluetoothSymbol, SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE); #endif #if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS) - tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH), 0, symbolsAPRS[symbol], SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE);//, TFT_RED); + tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH), 0, bluetoothSymbol, SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE); #endif } - } else if (bluetoothConnected) { // TODO In this case, the text symbol stay displayed due to symbolAvailable false in menu_utils - #if defined(HELTEC_WIRELESS_TRACKER) - tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH + (128 - TFT_WIDTH)), 0, bluetoothSymbol, SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE); - #endif - #if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS) - tft.drawBitmap((TFT_WIDTH - SYMBOL_WIDTH), 0, bluetoothSymbol, SYMBOL_WIDTH, SYMBOL_HEIGHT, TFT_WHITE); - #endif } - } - + #endif #else const String* const lines[] = {&line1, &line2, &line3, &line4, &line5};