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

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