Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Display.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Display.cpp
  3. *
  4. * Wrapper class for Adafruit OLED display.
  5. *
  6. * Created on: 28.01.2022
  7. * Author: FSmilari
  8. */
  9. #include "Display.h"
  10. /*****************
  11. ** Constructors.
  12. ****************/
  13. Display::Display() {
  14. ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT);
  15. u8g2_gfx.begin(ssd1306);
  16. }
  17. /******************
  18. ** Public methods
  19. *****************/
  20. void Display::init() {
  21. if (!ssd1306.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) {
  22. Serial.println(F("SSD1306 allocation failed"));
  23. for (;;)
  24. ; // Don't proceed, loop forever
  25. }
  26. }
  27. void Display::display() {
  28. ssd1306.display();
  29. }
  30. void Display::clearDisplay() {
  31. ssd1306.clearDisplay();
  32. }
  33. void Display::showBrand() {
  34. ssd1306.clearDisplay();
  35. ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, 128, 34, SSD1306_WHITE);
  36. ssd1306.setFont(&titillium_web_semibold12pt7b);
  37. ssd1306.setTextSize(1);
  38. ssd1306.setTextColor(SSD1306_WHITE);
  39. uint16_t w = 0, h = 0;
  40. calculateWH("Fraestisch N172", w, h);
  41. ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 63 - (30 - h) / 2);
  42. ssd1306.println("Fraestisch N172");
  43. display();
  44. }
  45. void Display::showInitialization() {
  46. ssd1306.clearDisplay();
  47. ssd1306.setFont(&titillium_web_semibold12pt7b);
  48. ssd1306.setTextSize(1);
  49. ssd1306.setTextColor(SSD1306_WHITE);
  50. uint16_t w = 0, h = 0;
  51. calculateWH("Initialisieren", w, h);
  52. ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 30);
  53. ssd1306.println("Initialisieren");
  54. calculateWH(". . . . .", w, h);
  55. ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 50);
  56. String s = "";
  57. for (int i = 0; i < 6; i++) {
  58. ssd1306.print(s);
  59. display();
  60. delay(500);
  61. if (i < 5) {
  62. ssd1306.print(s + ". ");
  63. } else {
  64. ssd1306.println(s + ".");
  65. }
  66. }
  67. }
  68. void Display::showFrame(Status status) {
  69. ssd1306.clearDisplay();
  70. ssd1306.drawRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 3, SSD1306_WHITE);
  71. ssd1306.drawLine(37, 0, 37, SCREEN_HEIGHT - 1, SSD1306_WHITE);
  72. ssd1306.drawLine(0, 15, 37, 15, SSD1306_WHITE);
  73. switch (status) {
  74. case TOOL_CHANGE:
  75. drawStatusText(STATUS_TXT_TOOLCHG);
  76. break;
  77. case CONFIGURATION:
  78. ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE);
  79. drawStatusText (STATUS_TXT_CFG);
  80. drawConfigText("Höhe WLS");
  81. drawConfigOption("03.00 mm");
  82. break;
  83. case IDLE:
  84. ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE);
  85. drawStatusText(STATUS_TXT_IDLE);
  86. break;
  87. default:
  88. break;
  89. }
  90. display();
  91. }
  92. /********************************
  93. ** Private methods
  94. *******************************/
  95. void Display::calculateWH(String units, uint16_t &w, uint16_t &h) {
  96. int x = 0;
  97. int y = 0;
  98. int16_t x1, y1;
  99. uint16_t w1, h1;
  100. ssd1306.getTextBounds(units, x, y, &x1, &y1, &w1, &h1);
  101. w = w1;
  102. h = h1;
  103. }
  104. void Display::drawStatusText(String txt) {
  105. char *s;
  106. s = &txt[0];
  107. int16_t w = 0;
  108. u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  109. w = u8g2_gfx.getUTF8Width(s);
  110. u8g2_gfx.setCursor((37 - w) / 2, 12);
  111. u8g2_gfx.println(F(s));
  112. }
  113. void Display::drawConfigText(String txt) {
  114. char *s;
  115. s = &txt[0];
  116. int16_t w = 0, h = 0;
  117. u8g2_gfx.setFont(u8g2_font_helvB12_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  118. w = u8g2_gfx.getUTF8Width(s);
  119. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  120. u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1); // start writing at this position
  121. u8g2_gfx.println(F(s));
  122. }
  123. void Display::drawConfigOption(String txt) {
  124. char *s;
  125. s = &txt[0];
  126. int16_t w = 0, h = 0;
  127. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  128. w = u8g2_gfx.getUTF8Width(s);
  129. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  130. u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1);
  131. u8g2_gfx.println(F(s));
  132. }