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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. angle = 0;
  18. starttime = millis();
  19. }
  20. /******************
  21. ** Public methods
  22. *****************/
  23. void Display::init() {
  24. if (!ssd1306.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) {
  25. Serial.println(F("SSD1306 allocation failed"));
  26. for (;;)
  27. ; // Don't proceed, loop forever
  28. }
  29. }
  30. void Display::display() {
  31. ssd1306.display();
  32. }
  33. void Display::clearDisplay() {
  34. ssd1306.clearDisplay();
  35. }
  36. void Display::showBrand() {
  37. ssd1306.clearDisplay();
  38. ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, imageWidth, imageHeight, SSD1306_WHITE);
  39. char *s = &String("Frästisch N172")[0];
  40. int16_t w = 0, h = 0;
  41. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  42. w = u8g2_gfx.getUTF8Width(s);
  43. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  44. u8g2_gfx.setForegroundColor(SSD1306_WHITE);
  45. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 63 - (30 - h) / 2);
  46. u8g2_gfx.println(F(s));
  47. display();
  48. }
  49. void Display::showInitialization() {
  50. ssd1306.clearDisplay();
  51. char *s = &String("Initialisieren")[0];
  52. int16_t w = 0;
  53. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  54. w = u8g2_gfx.getUTF8Width(s);
  55. u8g2_gfx.setForegroundColor(SSD1306_WHITE);
  56. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 30);
  57. u8g2_gfx.println(F(s));
  58. char *g;
  59. w = u8g2_gfx.getUTF8Width(". . . . .");
  60. u8g2_gfx.setCursor((SCREEN_WIDTH - w) / 2, 50);
  61. String gauge = "";
  62. for (int i = 0; i < 6; i++) {
  63. g = &gauge[0];
  64. u8g2_gfx.print(g);
  65. display();
  66. delay(500);
  67. if (i < 4) {
  68. gauge = ". ";
  69. g = &gauge[0];
  70. } else {
  71. gauge = ".";
  72. g = &gauge[0];
  73. }
  74. }
  75. }
  76. void Display::showFrame(Status status) {
  77. switch (status) {
  78. case MOVING_ELEVATOR:
  79. rotateAndDrawRotationBitmap();
  80. drawBitmap((37 - imageSide_R) / 2, 47, imageSide_D, imageSide_D, epd_bitmap_Dive);
  81. break;
  82. case TOOL_CHANGE:
  83. redrawFrame();
  84. drawStatusText(STATUS_TXT_TOOLCHG);
  85. drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Tools);
  86. break;
  87. case CONFIGURATION:
  88. redrawFrame();
  89. ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE);
  90. drawStatusText (STATUS_TXT_CFG);
  91. drawConfigText(this->configText);
  92. drawConfigOption(this->configOption);
  93. break;
  94. case IDLE:
  95. redrawFrame();
  96. ssd1306.drawLine(37, 43, SCREEN_WIDTH - 1, 43, SSD1306_WHITE);
  97. drawStatusText(STATUS_TXT_IDLE);
  98. break;
  99. case NULLING:
  100. case NULLING_TLS:
  101. redrawFrame();
  102. drawStatusText(STATUS_TXT_NULLING);
  103. drawBitmap(37 + (SCREEN_WIDTH - 37 - imageSide) / 2, (SCREEN_HEIGHT - imageSide) / 2, imageSide, imageSide, epd_bitmap_Nulling);
  104. break;
  105. default:
  106. break;
  107. }
  108. display();
  109. }
  110. void Display::drawConfigText(String txt) {
  111. char *s = &txt[0];
  112. int16_t w = 0, h = 0;
  113. u8g2_gfx.setFont(u8g2_font_helvB12_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  114. w = u8g2_gfx.getUTF8Width(s);
  115. h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
  116. u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1); // start writing at this position
  117. u8g2_gfx.println(F(s));
  118. }
  119. void Display::drawConfigOption(String txt) {
  120. char *s = &txt[0];
  121. int16_t w = 0, h = 0;
  122. u8g2_gfx.setFont(u8g2_font_helvB12_tf);
  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 * 3 + h / 2 - 1);
  126. u8g2_gfx.println(F(s));
  127. }
  128. const String& Display::getConfigOption() const {
  129. return configOption;
  130. }
  131. void Display::setConfigOption(const String &configOption) {
  132. this->configOption = configOption;
  133. }
  134. const String& Display::getConfigText() const {
  135. return configText;
  136. }
  137. void Display::setWlsConnected(bool wlsConnected) {
  138. this->wlsConnected = wlsConnected;
  139. }
  140. void Display::setConfigText(const String &configText) {
  141. this->configText = configText;
  142. }
  143. void Display::drawWLSStatus() {
  144. String txt = wlsConnected ? "WLS" : "";
  145. char *s = &txt[0];
  146. int16_t w = 0;
  147. u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  148. w = u8g2_gfx.getUTF8Width(s);
  149. u8g2_gfx.setCursor((37 - w) / 2, 27);
  150. u8g2_gfx.println(F(s));
  151. }
  152. /********************************
  153. ** Private methods
  154. *******************************/
  155. void Display::drawStatusText(String txt) {
  156. char *s = &txt[0];
  157. int16_t w = 0;
  158. u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  159. w = u8g2_gfx.getUTF8Width(s);
  160. u8g2_gfx.setCursor((37 - w) / 2, 12);
  161. u8g2_gfx.println(F(s));
  162. }
  163. void Display::drawBitmap(int x, int y, int w, int h, const uint8_t bitmap[]) {
  164. ssd1306.drawBitmap(x, y, bitmap, w, h, SSD1306_WHITE);
  165. }
  166. void Display::redrawFrame() {
  167. ssd1306.clearDisplay();
  168. ssd1306.drawRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 3, SSD1306_WHITE);
  169. ssd1306.drawLine(37, 0, 37, SCREEN_HEIGHT - 1, SSD1306_WHITE);
  170. ssd1306.drawLine(0, 15, 37, 15, SSD1306_WHITE);
  171. drawWLSStatus();
  172. }
  173. void Display::rotateAndDrawRotationBitmap() {
  174. if (millis() - starttime >= 125) {
  175. int xOffset = 0;
  176. int yOffset = 0;
  177. switch (angle) {
  178. case 0:
  179. xOffset = imageSide_R / 2;
  180. yOffset = 0;
  181. break;
  182. case 1:
  183. xOffset = imageSide_R / 2;
  184. yOffset = imageSide_R / 4;
  185. break;
  186. case 2:
  187. xOffset = imageSide_R / 2;
  188. yOffset = imageSide_R / 2;
  189. break;
  190. case 3:
  191. xOffset = imageSide_R / 4;
  192. yOffset = imageSide_R / 2;
  193. break;
  194. case 4:
  195. xOffset = 0;
  196. yOffset = imageSide_R / 2;
  197. break;
  198. case 5:
  199. xOffset = 0;
  200. yOffset = imageSide_R / 4;
  201. break;
  202. case 6:
  203. xOffset = 0;
  204. yOffset = 0;
  205. break;
  206. case 7:
  207. xOffset = imageSide_R / 4;
  208. yOffset = 0;
  209. break;
  210. default:
  211. break;
  212. }
  213. ssd1306.fillRect((37 - imageSide_R) / 2 + xOffset, 30 + yOffset, imageSide_R / 2 + 1, imageSide_R / 2 + 1, SSD1306_BLACK);
  214. ssd1306.display();
  215. drawBitmap((37 - imageSide_R) / 2, 30, imageSide_R, imageSide_R, epd_rotate_bitmap_allArray[angle]);
  216. angle = (angle + 1) % 8;
  217. starttime = millis();
  218. }
  219. }