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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. char *s = &String("Frästisch N172")[0];
  37. int16_t w = 0, h = 0;
  38. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  39. w = u8g2_gfx.getUTF8Width(s);
  40. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  41. u8g2_gfx.setForegroundColor(SSD1306_WHITE);
  42. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 63 - (30 - h) / 2);
  43. u8g2_gfx.println(F(s));
  44. display();
  45. }
  46. void Display::showInitialization() {
  47. ssd1306.clearDisplay();
  48. char *s = &String("Initialisieren")[0];
  49. int16_t w = 0;
  50. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  51. w = u8g2_gfx.getUTF8Width(s);
  52. u8g2_gfx.setForegroundColor(SSD1306_WHITE);
  53. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 30);
  54. u8g2_gfx.println(F(s));
  55. char *g;
  56. w = u8g2_gfx.getUTF8Width(". . . . .");
  57. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 50);
  58. String gauge = "";
  59. for (int i = 0; i < 6; i++) {
  60. g = &gauge[0];
  61. u8g2_gfx.print(g);
  62. display();
  63. delay(500);
  64. if (i < 4) {
  65. gauge = ". ";
  66. g = &gauge[0];
  67. } else {
  68. gauge = ".";
  69. g = &gauge[0];
  70. }
  71. }
  72. }
  73. void Display::showFrame(Status status) {
  74. ssd1306.clearDisplay();
  75. ssd1306.drawRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 3, SSD1306_WHITE);
  76. ssd1306.drawLine(37, 0, 37, SCREEN_HEIGHT - 1, SSD1306_WHITE);
  77. ssd1306.drawLine(0, 15, 37, 15, SSD1306_WHITE);
  78. switch (status) {
  79. case TOOL_CHANGE:
  80. drawStatusText(STATUS_TXT_TOOLCHG);
  81. break;
  82. case CONFIGURATION:
  83. ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE);
  84. drawStatusText (STATUS_TXT_CFG);
  85. drawConfigText("Höhe WLS");
  86. drawConfigOption("03.00 mm");
  87. break;
  88. case IDLE:
  89. ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE);
  90. drawStatusText(STATUS_TXT_IDLE);
  91. break;
  92. default:
  93. break;
  94. }
  95. display();
  96. }
  97. /********************************
  98. ** Private methods
  99. *******************************/
  100. void Display::calculateWH(String units, uint16_t &w, uint16_t &h) {
  101. int x = 0;
  102. int y = 0;
  103. int16_t x1, y1;
  104. uint16_t w1, h1;
  105. ssd1306.getTextBounds(units, x, y, &x1, &y1, &w1, &h1);
  106. w = w1;
  107. h = h1;
  108. }
  109. void Display::drawStatusText(String txt) {
  110. char *s = &txt[0];
  111. int16_t w = 0;
  112. u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  113. w = u8g2_gfx.getUTF8Width(s);
  114. u8g2_gfx.setCursor((37 - w) / 2, 12);
  115. u8g2_gfx.println(F(s));
  116. }
  117. void Display::drawConfigText(String txt) {
  118. char *s = &txt[0];
  119. int16_t w = 0, h = 0;
  120. u8g2_gfx.setFont(u8g2_font_helvB12_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  121. w = u8g2_gfx.getUTF8Width(s);
  122. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  123. u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1); // start writing at this position
  124. u8g2_gfx.println(F(s));
  125. }
  126. void Display::drawConfigOption(String txt) {
  127. char *s = &txt[0];
  128. int16_t w = 0, h = 0;
  129. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  130. w = u8g2_gfx.getUTF8Width(s);
  131. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  132. u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1);
  133. u8g2_gfx.println(F(s));
  134. }