Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Display.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. wlsConnected = false;
  17. }
  18. /******************
  19. ** Public methods
  20. *****************/
  21. void Display::init() {
  22. if (!ssd1306.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) {
  23. Serial.println(F("SSD1306 allocation failed"));
  24. for (;;)
  25. ; // Don't proceed, loop forever
  26. }
  27. }
  28. void Display::display() {
  29. ssd1306.display();
  30. }
  31. void Display::clearDisplay() {
  32. ssd1306.clearDisplay();
  33. }
  34. void Display::showBrand() {
  35. ssd1306.clearDisplay();
  36. ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, imageWidth, imageHeight, SSD1306_WHITE);
  37. char *s = &String("Frästisch N172")[0];
  38. int16_t w = 0, h = 0;
  39. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  40. w = u8g2_gfx.getUTF8Width(s);
  41. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  42. u8g2_gfx.setForegroundColor(SSD1306_WHITE);
  43. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 63 - (30 - h) / 2);
  44. u8g2_gfx.println(F(s));
  45. display();
  46. }
  47. void Display::showInitialization() {
  48. ssd1306.clearDisplay();
  49. char *s = &String("Initialisieren")[0];
  50. int16_t w = 0;
  51. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  52. w = u8g2_gfx.getUTF8Width(s);
  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. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 50);
  59. String gauge = "";
  60. for (int i = 0; i < 6; i++) {
  61. g = &gauge[0];
  62. u8g2_gfx.print(g);
  63. display();
  64. delay(500);
  65. if (i < 4) {
  66. gauge = ". ";
  67. g = &gauge[0];
  68. } else {
  69. gauge = ".";
  70. g = &gauge[0];
  71. }
  72. }
  73. }
  74. void Display::showFrame(Status status) {
  75. switch (status) {
  76. case MOVING_ELEVATOR:
  77. drawBitmap((37 - imageSide_R) / 2, 30, imageSide_R, imageSide_R, epd_bitmap_Rotate);
  78. drawBitmap((37 - imageSide_R) / 2, 47, imageSide_R, imageSide_R, epd_bitmap_Dive);
  79. break;
  80. case TOOL_CHANGE:
  81. redrawFrame();
  82. drawStatusText(STATUS_TXT_TOOLCHG);
  83. drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Tools);
  84. break;
  85. case CONFIGURATION:
  86. redrawFrame();
  87. ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE);
  88. drawStatusText (STATUS_TXT_CFG);
  89. drawConfigText(this->configText);
  90. drawConfigOption(this->configOption);
  91. break;
  92. case IDLE:
  93. redrawFrame();
  94. ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE);
  95. drawStatusText(STATUS_TXT_IDLE);
  96. break;
  97. case NULLING:
  98. case NULLING_TLS:
  99. redrawFrame();
  100. drawStatusText(STATUS_TXT_NULLING);
  101. drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Nulling);
  102. break;
  103. default:
  104. break;
  105. }
  106. display();
  107. }
  108. void Display::drawConfigText(String txt) {
  109. char *s = &txt[0];
  110. int16_t w = 0, h = 0;
  111. u8g2_gfx.setFont(u8g2_font_helvB12_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  112. w = u8g2_gfx.getUTF8Width(s);
  113. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  114. u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1); // start writing at this position
  115. u8g2_gfx.println(F(s));
  116. }
  117. void Display::drawConfigOption(String txt) {
  118. char *s = &txt[0];
  119. int16_t w = 0, h = 0;
  120. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  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 * 3 + h / 2 - 1);
  124. u8g2_gfx.println(F(s));
  125. }
  126. const String& Display::getConfigOption() const {
  127. return configOption;
  128. }
  129. void Display::setConfigOption(const String &configOption) {
  130. this->configOption = configOption;
  131. }
  132. const String& Display::getConfigText() const {
  133. return configText;
  134. }
  135. void Display::setWlsConnected(bool wlsConnected) {
  136. this->wlsConnected = wlsConnected;
  137. }
  138. void Display::setConfigText(const String &configText) {
  139. this->configText = configText;
  140. }
  141. void Display::drawWLSStatus() {
  142. String txt = wlsConnected ? "WLS" : "";
  143. char *s = &txt[0];
  144. int16_t w = 0;
  145. u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  146. w = u8g2_gfx.getUTF8Width(s);
  147. u8g2_gfx.setCursor((37 - w) / 2, 27);
  148. u8g2_gfx.println(F(s));
  149. }
  150. /********************************
  151. ** Private methods
  152. *******************************/
  153. void Display::drawStatusText(String txt) {
  154. char *s = &txt[0];
  155. int16_t w = 0;
  156. u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  157. w = u8g2_gfx.getUTF8Width(s);
  158. u8g2_gfx.setCursor((37 - w) / 2, 12);
  159. u8g2_gfx.println(F(s));
  160. }
  161. void Display::drawBitmap(int x, int y, int w, int h, const uint8_t bitmap[]) {
  162. ssd1306.drawBitmap(x, y, bitmap, w, h, SSD1306_WHITE);
  163. }
  164. void Display::redrawFrame() {
  165. ssd1306.clearDisplay();
  166. ssd1306.drawRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 3, SSD1306_WHITE);
  167. ssd1306.drawLine(37, 0, 37, SCREEN_HEIGHT - 1, SSD1306_WHITE);
  168. ssd1306.drawLine(0, 15, 37, 15, SSD1306_WHITE);
  169. drawWLSStatus();
  170. }