Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Display.cpp 4.1KB

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