Distanz-/Tiefenmesser mit JSN-SR40T
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Display.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Display.cpp
  3. *
  4. * Created on: 05.01.2026
  5. * Author: FSmilari
  6. */
  7. #include "Display.h"
  8. #include "Adafruit_ST7735.h"
  9. #include "images/SFToolsLogo.h"
  10. #include "fonts/titillium_web_regular16pt7b.h" // Add a custom font
  11. #include "fonts/titillium_web_regular12pt7b.h" // Add a custom font
  12. //#include "fonts/titillium_web_regular8pt7b.h" // Add a custom font
  13. #include <Fonts/FreeSans9pt7b.h> // Add a custom font
  14. #include "images/stm32duino_logo.h"
  15. #include "images/thermometer_32.h"
  16. #include "images/gear.h"
  17. #include "images/zzz.h"
  18. #include "images/ruler.h"
  19. #include "images/air.h"
  20. #include "images/water.h"
  21. #include "images/water_s.h"
  22. //#define LED -1 // to +5v
  23. //#define SCK PA5
  24. //#define SDA PA7
  25. //#define MISO -1
  26. //#define MOSI SDA
  27. #define CS PA2
  28. #define DC PA1
  29. #define RST PA0
  30. #define ST7735_ARDUINOGREEN 0x04b3
  31. #define ST7735_STM32BLUE 0x03d6
  32. /*****************
  33. ** Constructors.
  34. ****************/
  35. Display::Display() : tft(Adafruit_ST7735(CS, DC, RST)) { // @suppress("Abstract class cannot be instantiated")
  36. angle = 0;
  37. starttime = millis();
  38. refreshScreen = true;
  39. configValue = 0.0;
  40. configUnit = "m/s";
  41. }
  42. void Display::init(void) {
  43. tft.initR(INITR_BLACKTAB);
  44. tft.fillScreen(ST7735_BLACK);
  45. tft.setRotation(1);
  46. tft.setTextWrap(false);
  47. tft.setTextColor(ST7735_WHITE);
  48. refreshScreen = true;
  49. }
  50. void Display::display(void) {
  51. if (!refreshScreen) {
  52. return;
  53. }
  54. // redrawFrame();
  55. refreshScreen = false;
  56. }
  57. void Display::drawXCenteredText(String txt, const GFXfont *font, uint8_t size, uint16_t col, int16_t y) {
  58. int16_t x1, y1; // Top-left corner of text
  59. uint16_t w, h; // Width and height
  60. tft.setFont(font);
  61. tft.setTextSize(size); // Set text size. Goes from 0 (the smallest) to 20 (very big)
  62. tft.setTextColor(col);
  63. // Get bounds starting from (0, 0)
  64. tft.getTextBounds(txt, 0, 0, &x1, &y1, &w, &h);
  65. // Calculate centered position
  66. int16_t centered_x = (SCREEN_WIDTH - w) / 2 - 3;
  67. // Set cursor and print
  68. tft.setCursor(centered_x, y);
  69. tft.print(txt);
  70. }
  71. void Display::drawText(String txt, const GFXfont *font, uint8_t size, uint16_t col, int16_t x, int16_t y) {
  72. tft.setFont(font);
  73. tft.setTextSize(size); // Set text size. Goes from 0 (the smallest) to 20 (very big)
  74. tft.setTextColor(col);
  75. tft.setCursor(x, y);
  76. tft.print(txt);
  77. }
  78. void Display::clearDisplay(void) {
  79. tft.fillScreen(ST7735_BLACK);
  80. }
  81. void Display::showBrand(int16_t x, int16_t y) {
  82. drawBitmap(x, y, 128, 34, SFTools_Logo, ST7735_ORANGE);
  83. }
  84. void Display::showInitialization(void) {
  85. redrawFrame();
  86. drawXCenteredText("EchoLoT", &titillium_web_regular16pt7b, 1, ST7735_CYAN, 36);
  87. drawXCenteredText("designed by", &FreeSans9pt7b, 1, ST7735_WHITE, 64);
  88. showBrand(16, 84);
  89. delay(3000);
  90. redrawFrame();
  91. drawText("powered by", &FreeSans9pt7b, 1, ST7735_CYAN, 35, 30);
  92. tft.fillRoundRect(46, 42, 68, 68, 7, ST7735_STM32BLUE);
  93. drawBitmap(48, 44, 64, 64, epd_bitmap_stm32duino_logo_icon, ST7735_WHITE);
  94. // tft.drawBitmap(5, 100, epd_bitmap_gear, 24, 24, ST7735_YELLOW);
  95. // tft.drawBitmap(40, 100, epd_bitmap_Zzz_24, 24, 24, ST7735_CYAN);
  96. // tft.drawBitmap(75, 100, epd_bitmap_Measure_25, 25, 25, ST7735_RED);
  97. // tft.fillTriangle(75, 98, 80, 102, 75, 107, ST7735_RED);
  98. // tft.fillTriangle(82, 98, 87, 102, 82, 107, ST7735_RED);
  99. // tft.fillTriangle(89, 98, 94, 102, 89, 107, ST7735_RED);
  100. // tft.fillTriangle(96, 98, 101, 102, 96, 107, ST7735_RED);
  101. //
  102. // tft.drawBitmap(110, 100, epd_bitmap_air, 24, 24, ST7735_CYAN);
  103. // tft.drawBitmap(110, 100, epd_bitmap_water, 24, 24, ST7735_BLUE);
  104. // tft.drawBitmap(110, 100, epd_bitmap_water_s, 24, 24, ST7735_BLUE);
  105. // tft.drawBitmap(1, 160 - 32, thermometer_icon_32, 32, 32, 0xE71C);
  106. delay(3000);
  107. }
  108. void Display::showFrame(Status status) {
  109. redrawFrame();
  110. switch (status) {
  111. case Status::IDLE:
  112. break;
  113. // case Status::TOOLCHANGE:
  114. // drawStatusText(STATUS_TXT_TOOLCHG);
  115. // break;
  116. // case Status::CONFIG:
  117. // drawStatusText(STATUS_TXT_CFG);
  118. // break;
  119. // case Status::NULLING:
  120. // drawStatusText(STATUS_TXT_NULLING);
  121. // break;
  122. // case Status::DIVING:
  123. // drawStatusText(STATUS_TXT_DIVING);
  124. // break;
  125. default:
  126. break;
  127. }
  128. }
  129. /* ===== Private methods ===== */
  130. void Display::drawBitmap(int x, int y, int w, int h, const uint8_t bitmap[], uint16_t col) {
  131. tft.drawBitmap(x, y, bitmap, w, h, col);
  132. }
  133. void Display::drawRGBBitmap(int x, int y, int w, int h, const uint16_t bitmap[]) {
  134. tft.drawRGBBitmap(x, y, bitmap, w, h);
  135. }
  136. void Display::redrawFrame() {
  137. clearDisplay();
  138. tft.drawRoundRect(0, 0, 160, 128, 9, ST7735_CYAN);
  139. tft.drawRoundRect(1, 1, 158, 126, 8, ST7735_CYAN);
  140. }