/* * Display.cpp * * Created on: 05.01.2026 * Author: FSmilari */ #include "Display.h" #include "Adafruit_ST7735.h" #include "images/SFToolsLogo.h" #include "fonts/titillium_web_regular16pt7b.h" // Add a custom font #include "fonts/titillium_web_regular12pt7b.h" // Add a custom font //#include "fonts/titillium_web_regular8pt7b.h" // Add a custom font #include // Add a custom font #include "images/stm32duino_logo.h" #include "images/thermometer_32.h" #include "images/gear.h" #include "images/zzz.h" #include "images/ruler.h" #include "images/air.h" #include "images/water.h" #include "images/water_s.h" //#define LED -1 // to +5v //#define SCK PA5 //#define SDA PA7 //#define MISO -1 //#define MOSI SDA #define CS PA2 #define DC PA1 #define RST PA0 #define ST7735_ARDUINOGREEN 0x04b3 #define ST7735_STM32BLUE 0x03d6 /***************** ** Constructors. ****************/ Display::Display() : tft(Adafruit_ST7735(CS, DC, RST)) { // @suppress("Abstract class cannot be instantiated") angle = 0; starttime = millis(); refreshScreen = true; configValue = 0.0; configUnit = "m/s"; } void Display::init(void) { tft.initR(INITR_BLACKTAB); tft.fillScreen(ST7735_BLACK); tft.setRotation(1); tft.setTextWrap(false); tft.setTextColor(ST7735_WHITE); refreshScreen = true; } void Display::display(void) { if (!refreshScreen) { return; } // redrawFrame(); refreshScreen = false; } void Display::drawXCenteredText(String txt, const GFXfont *font, uint8_t size, uint16_t col, int16_t y) { int16_t x1, y1; // Top-left corner of text uint16_t w, h; // Width and height tft.setFont(font); tft.setTextSize(size); // Set text size. Goes from 0 (the smallest) to 20 (very big) tft.setTextColor(col); // Get bounds starting from (0, 0) tft.getTextBounds(txt, 0, 0, &x1, &y1, &w, &h); // Calculate centered position int16_t centered_x = (SCREEN_WIDTH - w) / 2 - 3; // Set cursor and print tft.setCursor(centered_x, y); tft.print(txt); } void Display::drawText(String txt, const GFXfont *font, uint8_t size, uint16_t col, int16_t x, int16_t y) { tft.setFont(font); tft.setTextSize(size); // Set text size. Goes from 0 (the smallest) to 20 (very big) tft.setTextColor(col); tft.setCursor(x, y); tft.print(txt); } void Display::clearDisplay(void) { tft.fillScreen(ST7735_BLACK); } void Display::showBrand(int16_t x, int16_t y) { drawBitmap(x, y, 128, 34, SFTools_Logo, ST7735_ORANGE); } void Display::showInitialization(void) { redrawFrame(); drawXCenteredText("EchoLoT", &titillium_web_regular16pt7b, 1, ST7735_CYAN, 36); drawXCenteredText("designed by", &FreeSans9pt7b, 1, ST7735_WHITE, 64); showBrand(16, 84); delay(3000); redrawFrame(); drawText("powered by", &FreeSans9pt7b, 1, ST7735_CYAN, 35, 30); tft.fillRoundRect(46, 42, 68, 68, 7, ST7735_STM32BLUE); drawBitmap(48, 44, 64, 64, epd_bitmap_stm32duino_logo_icon, ST7735_WHITE); // tft.drawBitmap(5, 100, epd_bitmap_gear, 24, 24, ST7735_YELLOW); // tft.drawBitmap(40, 100, epd_bitmap_Zzz_24, 24, 24, ST7735_CYAN); // tft.drawBitmap(75, 100, epd_bitmap_Measure_25, 25, 25, ST7735_RED); // tft.fillTriangle(75, 98, 80, 102, 75, 107, ST7735_RED); // tft.fillTriangle(82, 98, 87, 102, 82, 107, ST7735_RED); // tft.fillTriangle(89, 98, 94, 102, 89, 107, ST7735_RED); // tft.fillTriangle(96, 98, 101, 102, 96, 107, ST7735_RED); // // tft.drawBitmap(110, 100, epd_bitmap_air, 24, 24, ST7735_CYAN); // tft.drawBitmap(110, 100, epd_bitmap_water, 24, 24, ST7735_BLUE); // tft.drawBitmap(110, 100, epd_bitmap_water_s, 24, 24, ST7735_BLUE); // tft.drawBitmap(1, 160 - 32, thermometer_icon_32, 32, 32, 0xE71C); delay(3000); } void Display::showFrame(Status status) { redrawFrame(); switch (status) { case Status::IDLE: break; // case Status::TOOLCHANGE: // drawStatusText(STATUS_TXT_TOOLCHG); // break; // case Status::CONFIG: // drawStatusText(STATUS_TXT_CFG); // break; // case Status::NULLING: // drawStatusText(STATUS_TXT_NULLING); // break; // case Status::DIVING: // drawStatusText(STATUS_TXT_DIVING); // break; default: break; } } /* ===== Private methods ===== */ void Display::drawBitmap(int x, int y, int w, int h, const uint8_t bitmap[], uint16_t col) { tft.drawBitmap(x, y, bitmap, w, h, col); } void Display::drawRGBBitmap(int x, int y, int w, int h, const uint16_t bitmap[]) { tft.drawRGBBitmap(x, y, bitmap, w, h); } void Display::redrawFrame() { clearDisplay(); tft.drawRoundRect(0, 0, 160, 128, 9, ST7735_CYAN); tft.drawRoundRect(1, 1, 158, 126, 8, ST7735_CYAN); }