21 #include "../../include/esp3d_config.h"
22 #if defined (DISPLAY_DEVICE) && (DISPLAY_UI_TYPE == UI_TYPE_BASIC)
25 #include "../../core/settings_esp3d.h"
26 #include "../../core/esp3doutput.h"
28 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
31 #if DISPLAY_DEVICE == OLED_I2C_SSD1306
32 #include <SSD1306Wire.h>
33 SSD1306Wire esp3d_screen(DISPLAY_I2C_ADDR, DISPLAY_I2C_PIN_SDA, DISPLAY_I2C_PIN_SCL);
35 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306
36 #if DISPLAY_DEVICE == OLED_I2C_SSDSH1106
37 #include <SH1106Wire.h>
38 SH1106Wire esp3d_screen(DISPLAY_I2C_ADDR, (DISPLAY_I2C_PIN_SDA==-1)?SDA:DISPLAY_I2C_PIN_SDA, (DISPLAY_I2C_PIN_SCL==-1)?SCL:DISPLAY_I2C_PIN_SCL);
40 #endif //DISPLAY_DEVICE == OLED_I2C_SSDSH1106
41 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
42 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
44 TFT_eSPI esp3d_screen = TFT_eSPI();
46 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240)
48 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240)
49 #if (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
51 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
52 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
53 #if defined (WIFI_FEATURE)
54 #include "../wifi/wificonfig.h"
55 #endif // WIFI_FEATURE
56 #if defined (ETH_FEATURE)
57 #include "../ethernet/ethconfig.h"
59 #if defined (BLUETOOTH_FEATURE)
60 #include "../bluetooth/BT_service.h"
61 #endif //BLUETOOTH_FEATURE
62 #if defined (WIFI_FEATURE) || defined (ETH_FEATURE) || defined (BLUETOOTH_FEATURE)
63 #include "../network/netconfig.h"
64 #endif //WIFI_FEATURE || ETH_FEATURE) ||BLUETOOTH_FEATURE
65 #define DISPLAY_REFRESH_TIME 1000
71 #if defined(DISPLAY_TOUCH_DRIVER)
72 #if DISPLAY_TOUCH_DRIVER == XPT2046_SPI
73 uint16_t calibrationData[5];
76 uint size = getStringWidth(
"Touch corners as indicated");
81 for (uint8_t i = 0; i < 5; i++) {
98 #endif //DISPLAY_TOUCH_DRIVER
104 bool Display::splash()
110 if (!_splash_displayed) {
113 _splash_displayed =
true;
119 bool Display::showStatus(
bool force)
122 bool refresh_status = force;
123 static String status;
124 if (status != _status) {
126 refresh_status =
true;
130 uint16_t size = sizetoFitSpace(status.c_str(),
STATUS_AREA_W);
132 if (size < status.length()) {
133 static int status_shift = -1;
134 refresh_status =
true;
137 if (status_shift != -1) {
138 if( (uint16_t)(status_shift)> status.length()) {
143 if (status_shift > 0) {
144 status.remove(0,status_shift);
149 if (size < status.length()) {
151 status = status.substring(0,size);
158 if (refresh_status) {
163 return refresh_status;
166 bool Display::display_signal(
bool force)
169 bool refresh_signal =
false;
170 bool refresh_label =
false;
172 #if defined (WIFI_FEATURE)
175 if (WiFi.getMode() == WIFI_AP) {
178 refresh_signal =
true;
182 refresh_label =
true;
185 if (WiFi.isConnected()) {
188 refresh_signal =
true;
190 if (label != WiFi.SSID()) {
192 refresh_label =
true;
197 refresh_signal =
true;
201 refresh_label =
true;
207 uint16_t size = sizetoFitSpace(label.c_str(),
SSID_AREA_W);
209 if (size < label.length()) {
210 refresh_label =
true;
211 static int label_shift = -1;
214 if (label_shift != -1) {
215 if((uint16_t)(label_shift)> label.length()) {
220 if (label_shift > 0) {
221 label.remove(0,label_shift);
226 if (size < label.length()) {
228 label = label.substring(0,size);
235 if (refresh_label || force) {
241 #endif // WIFI_FEATURE
243 #if defined (ETH_FEATURE)
247 refresh_signal =
true;
251 String tmp = ETH.linkSpeed();
255 refresh_label =
true;
260 refresh_label =
true;
263 if (refresh_label || force) {
272 #if defined (BLUETOOTH_FEATURE)
276 refresh_signal =
true;
281 refresh_label =
true;
285 uint16_t size = sizetoFitSpace(label.c_str(),
SSID_AREA_W);
287 if (size < label.length()) {
288 refresh_label =
true;
289 static int label_shift = -1;
292 if (label_shift > label.length()) {
296 if (label_shift > 0) {
297 label.remove(0,label_shift);
302 if (size < label.length()) {
304 label = label.substring(0,size);
311 if( refresh_label || force) {
314 if (label.length()>0) {
319 #endif //BLUETOOTH_FEATURE
321 if (refresh_signal || force) {
372 if (refresh_signal || refresh_label || force) {
381 bool refresh_label = force;
383 #if defined (WIFI_FEATURE) || defined (ETH_FEATURE) || defined (BLUETOOTH_FEATURE)
387 #if defined (WIFI_FEATURE)
389 s = WiFi.localIP().toString();
392 s = WiFi.softAPIP().toString();
394 #endif //WIFI_FEATURE
395 #if defined (ETH_FEATURE)
397 s = ETH.localIP().toString();
400 #if defined (BLUETOOTH_FEATURE)
404 #endif //BLUETOOTH_FEATURE
411 refresh_label =
true;
414 if (label.length()>0) {
423 refresh_label =
true;
427 #endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
428 return refresh_label;
431 bool Display::main_screen(
bool force)
434 if (display_signal(force)) {
440 if (showStatus(force)) {
450 uint16_t Display::sizetoFitSpace(
const char *
string, uint16_t maxwidth)
453 while (getStringWidth(s.c_str()) > maxwidth) {
454 if (s.length() > 0) {
455 s.remove(s.length()-1);
466 _screenID = screenID;
474 _splash_displayed=
false;
489 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
490 #if defined(DISPLAY_I2C_PIN_RST)
491 pinMode(DISPLAY_I2C_PIN_RST,OUTPUT);
492 digitalWrite(DISPLAY_I2C_PIN_RST, LOW);
494 digitalWrite(DISPLAY_I2C_PIN_RST, HIGH);
495 #endif //DISPLAY_I2C_PIN_RST
497 esp3d_screen.clear();
498 #if defined(DISPLAY_FLIP_VERTICALY)
499 esp3d_screen.flipScreenVertically();
501 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
502 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
503 #if defined (DISPLAY_LED_PIN) && (DISPLAY_LED_PIN!=-1)
504 pinMode(DISPLAY_LED_PIN, OUTPUT);
505 digitalWrite(DISPLAY_LED_PIN, HIGH);
506 #endif //DISPLAY_LED_PIN
507 esp3d_screen.begin();
508 #if defined(DISPLAY_FLIP_VERTICALY)
509 esp3d_screen.setRotation(3);
511 esp3d_screen.setRotation(1);
514 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
517 #if defined(DISPLAY_TOUCH_DRIVER)
519 uint16_t calibrationData[5];
520 for (uint8_t i = 0; i < 5; i++) {
523 esp3d_screen.setTouch(calibrationData);
525 #endif //DISPLAY_TOUCH_DRIVER
542 _splash_displayed=
false;
554 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
555 esp3d_screen.clear();
556 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
557 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
560 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
568 static uint32_t last_update = millis();
569 bool need_update = force;
570 if (((millis()- last_update) > DISPLAY_REFRESH_TIME) || force) {
571 last_update = millis();
575 if (!_splash_displayed) {
576 need_update = splash();
580 need_update = main_screen(force);
586 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
587 esp3d_screen.display();
589 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
606 void Display::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t color)
611 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
612 esp3d_screen.setColor((color ==
TFT_BLACK)?BLACK:WHITE);
613 esp3d_screen.drawLine(x0, y0, x1, y1);
614 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
615 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
616 esp3d_screen.drawLine(x0, y0, x1, y1, color);
617 #endif (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
621 void Display::drawRect(int16_t x, int16_t y, int16_t width, int16_t height, int16_t color)
626 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
627 esp3d_screen.setColor((color ==
TFT_BLACK)?BLACK:WHITE);
628 esp3d_screen.drawRect(x, y, width, height);
629 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
630 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
631 esp3d_screen.drawRect(x, y, width, height, color);
632 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
636 void Display::fillRect(int16_t x, int16_t y, int16_t width, int16_t height, int16_t color)
641 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
642 esp3d_screen.setColor((color ==
TFT_BLACK)?BLACK:WHITE);
643 esp3d_screen.fillRect(x, y, width, height);
644 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
645 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
646 esp3d_screen.fillRect(x, y, width, height, color);
647 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
650 void Display::setTextFont(uint8_t font)
652 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
655 esp3d_screen.setFont(ArialMT_Plain_16);
659 esp3d_screen.setFont(ArialMT_Plain_10);
661 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
662 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
663 esp3d_screen.setTextFont(font);
664 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
667 void Display::drawString(
const char *
string, int32_t poX, int32_t poY, int16_t color)
672 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
673 esp3d_screen.setColor((color ==
TFT_BLACK)?BLACK:WHITE);
674 esp3d_screen.drawString(poX, poY,
string);
675 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
676 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
677 esp3d_screen.setTextColor(color);
678 esp3d_screen.drawString(
string, poX, poY);
679 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
683 void Display::drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, int16_t color,
const uint8_t *xbm)
688 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
690 esp3d_screen.drawXbm(x, y, width, height, xbm);
691 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
692 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
693 esp3d_screen.drawXBitmap(x, y, xbm, width, height,color);
694 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
697 void Display::drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, uint16_t fgcolor, uint16_t bgcolor,
const uint8_t *xbm)
702 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
705 esp3d_screen.drawXbm(x, y, width, height, xbm);
706 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
707 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
708 esp3d_screen.drawXBitmap(x, y, xbm, width, height, fgcolor, bgcolor);
709 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
712 uint16_t Display::getStringWidth(
const char* text)
714 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
715 return esp3d_screen.getStringWidth(text, strlen(text));
716 #endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
717 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
718 return esp3d_screen.textWidth(text);
719 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
727 static uint8_t previous = 0;
730 fillRect(10, _screenheight-2, _screenwidth-20, 2,
SCREEN_BG);
735 drawRect(10, _screenheight-2, ((_screenwidth-20) * v)/100, 2,
PROGRESS_FG);
745 #endif //DISPLAY_DEVICE