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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. }
  16. /******************
  17. ** Public methods
  18. *****************/
  19. void Display::init() {
  20. if (!ssd1306.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) {
  21. Serial.println(F("SSD1306 allocation failed"));
  22. for (;;)
  23. ; // Don't proceed, loop forever
  24. }
  25. }
  26. void Display::display() {
  27. ssd1306.display();
  28. }
  29. void Display::clearDisplay() {
  30. ssd1306.clearDisplay();
  31. }
  32. void Display::showBrand() {
  33. ssd1306.clearDisplay();
  34. ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, 128, 34, SSD1306_WHITE);
  35. ssd1306.setFont(&titillium_web_semibold12pt7b);
  36. ssd1306.setTextSize(1);
  37. ssd1306.setTextColor(SSD1306_WHITE);
  38. uint16_t w = 0, h = 0;
  39. calculateWH("Fraestisch N172", w, h);
  40. ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 63 - (30 - h) / 2);
  41. ssd1306.println("Fraestisch N172");
  42. display();
  43. }
  44. void Display::showInitialization() {
  45. ssd1306.clearDisplay();
  46. ssd1306.setFont(&titillium_web_semibold12pt7b);
  47. ssd1306.setTextSize(1);
  48. ssd1306.setTextColor(SSD1306_WHITE);
  49. uint16_t w = 0, h = 0;
  50. calculateWH("Initialisieren", w, h);
  51. ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 30);
  52. ssd1306.println("Initialisieren");
  53. calculateWH(". . . . .", w, h);
  54. ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 50);
  55. String s = "";
  56. for (int i = 0; i < 6; i++) {
  57. ssd1306.print(s);
  58. display();
  59. delay(500);
  60. if (i < 5) {
  61. ssd1306.print(s + ". ");
  62. } else {
  63. ssd1306.println(s + ".");
  64. }
  65. }
  66. }
  67. void Display::showFrame(Status status) {
  68. ssd1306.clearDisplay();
  69. ssd1306.drawRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 3, SSD1306_WHITE);
  70. ssd1306.drawLine(37, 0, 37, SCREEN_HEIGHT - 1, SSD1306_WHITE);
  71. ssd1306.drawLine(0, 15, 37, 15, SSD1306_WHITE);
  72. switch (status) {
  73. case TOOL_CHANGE:
  74. drawStatusText(STATUS_TXT_TOOLCHG);
  75. break;
  76. case CONFIGURATION:
  77. ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE);
  78. drawStatusText (STATUS_TXT_CFG);
  79. drawConfigText("Steigung");
  80. drawConfigOption("03.00 mm");
  81. break;
  82. case IDLE:
  83. ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE);
  84. drawStatusText(STATUS_TXT_IDLE);
  85. break;
  86. default:
  87. break;
  88. }
  89. display();
  90. }
  91. /********************************
  92. ** Private methods
  93. *******************************/
  94. void Display::calculateWH(String units, uint16_t &w, uint16_t &h) {
  95. int x = 0;
  96. int y = 0;
  97. int16_t x1, y1;
  98. uint16_t w1, h1;
  99. ssd1306.getTextBounds(units, x, y, &x1, &y1, &w1, &h1);
  100. w = w1;
  101. h = h1;
  102. }
  103. void Display::drawStatusText(String txt) {
  104. uint16_t w = 0, h = 0;
  105. ssd1306.setFont(&titillium_web_regular8pt7b);
  106. calculateWH(txt, w, h);
  107. ssd1306.setCursor((37 - w) / 2, 11);
  108. ssd1306.println(txt);
  109. }
  110. void Display::drawConfigText(String txt) {
  111. uint16_t w = 0, h = 0;
  112. ssd1306.setFont(&titillium_web_semibold12pt7b);
  113. calculateWH(txt, w, h);
  114. ssd1306.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1);
  115. ssd1306.println(txt);
  116. }
  117. void Display::drawConfigOption(String txt) {
  118. uint16_t w = 0, h = 0;
  119. ssd1306.setFont(&titillium_web_semibold12pt7b);
  120. calculateWH(txt, w, h);
  121. ssd1306.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1);
  122. ssd1306.println(txt);
  123. }