21 #include "../../include/esp3d_config.h"
22 #if defined (DISPLAY_DEVICE) && (DISPLAY_UI_TYPE == UI_TYPE_ADVANCED)
29 #define SNAPFILENAME "/snapshot.bin"
32 #include "../../core/settings_esp3d.h"
33 #include "../../core/esp3doutput.h"
34 #include "../filesystem/esp_filesystem.h"
39 lv_obj_t * esp_lv_screen;
40 lv_obj_t * esp_lv_bar_progression;
41 lv_obj_t * esp_lv_status_label;
42 lv_obj_t * esp_lv_IP_label;
43 lv_obj_t * esp_lv_network_label;
45 #if defined(DISPLAY_SNAPSHOT_FEATURE)
47 static bool bSnapshot;
48 #endif //DISPLAY_SNAPSHOT_FEATURE
50 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
52 #if DISPLAY_DEVICE == OLED_I2C_SSD1306
53 #include <SSD1306Wire.h>
54 SSD1306Wire esp3d_screen(DISPLAY_I2C_ADDR, DISPLAY_I2C_PIN_SDA, DISPLAY_I2C_PIN_SCL);
55 #include "advanced_SSD1306.h"
56 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306
57 #if DISPLAY_DEVICE == OLED_I2C_SSDSH1106
58 #include <SH1106Wire.h>
59 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);
61 #endif //DISPLAY_DEVICE == OLED_I2C_SSDSH1106
62 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
63 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
65 TFT_eSPI esp3d_screen = TFT_eSPI();
66 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240)
68 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240)
69 #if (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
71 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
72 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
73 #if defined (WIFI_FEATURE)
74 #include "../wifi/wificonfig.h"
75 #endif // WIFI_FEATURE
76 #if defined (ETH_FEATURE)
77 #include "../ethernet/ethconfig.h"
79 #if defined (BLUETOOTH_FEATURE)
80 #include "../bluetooth/BT_service.h"
81 #endif //BLUETOOTH_FEATURE
82 #if defined (WIFI_FEATURE) || defined (ETH_FEATURE) || defined (BLUETOOTH_FEATURE)
83 #include "../network/netconfig.h"
84 #endif //WIFI_FEATURE || ETH_FEATURE) ||BLUETOOTH_FEATURE
89 static lv_disp_buf_t esp_lv_disp_buf;
90 static lv_color_t lv_buf1[LV_HOR_RES_MAX * 10];
91 static lv_color_t lv_buf2[LV_HOR_RES_MAX * 10];
92 #if defined(DISPLAY_SNAPSHOT_FEATURE)
93 static uint8_t error_snapshot = 0;
94 #endif //DISPLAY_SNAPSHOT_FEATURE
96 #define LVGL_TICK_PERIOD 10
97 #define ESP_FLASH_LETTER_DRIVE 'F'
101 LV_IMG_DECLARE(esplogo)
104 void esp_lv_disp_flush(lv_disp_drv_t *disp,
const lv_area_t *area, lv_color_t *color_p)
108 esp3d_screen.startWrite();
109 esp3d_screen.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1));
110 for (
int y = area->y1; y <= area->y2; y++) {
111 for (
int x = area->x1; x <= area->x2; x++) {
113 esp3d_screen.writeColor(c, 1);
114 #if defined(DISPLAY_SNAPSHOT_FEATURE)
116 uint32_t data = lv_color_to32(*color_p);
118 if (fsSnapFile.
write((
const uint8_t *)(&data),
sizeof(uint32_t)) !=
sizeof(uint32_t)) {
125 #endif //DISPLAY_SNAPSHOT_FEATURE
129 esp3d_screen.endWrite();
130 lv_disp_flush_ready(disp);
134 static void esp_lv_tick_handler(
void)
136 lv_tick_inc(LVGL_TICK_PERIOD);
141 void esp_lv_print(lv_log_level_t level,
const char *
file, uint32_t line,
const char * dsc)
144 Serial.printf(
"%s@%d->%s\r\n",
file, line, dsc);
149 #if defined(DISPLAY_TOUCH_DRIVER)
150 bool esp_lv_touch_read(lv_indev_drv_t * indev, lv_indev_data_t * data)
153 uint8_t bPressed = 0;
156 static lv_coord_t last_x = 0;
157 static lv_coord_t last_y = 0;
158 if (esp3d_screen.getTouch(&nX,&nY) > 0) {
161 data->state = LV_INDEV_STATE_PR;
163 data->state = LV_INDEV_STATE_REL;
165 data->point.x = last_x;
166 data->point.y = last_y;
169 #endif //DISPLAY_TOUCH_DRIVER
175 #if defined(DISPLAY_TOUCH_DRIVER)
176 #if DISPLAY_TOUCH_DRIVER == XPT2046_SPI
177 uint16_t calibrationData[5];
182 for (uint8_t i = 0; i < 5; i++) {
198 #endif //DISPLAY_TOUCH_DRIVER
205 if (esp_lv_network_label ==
nullptr) {
209 bool refresh_signal =
false;
210 bool refresh_label =
false;
212 #if defined (WIFI_FEATURE)
215 if (WiFi.getMode() == WIFI_AP) {
218 refresh_signal =
true;
222 refresh_label =
true;
225 if (WiFi.isConnected()) {
228 refresh_signal =
true;
230 if (label != WiFi.SSID()) {
232 refresh_label =
true;
237 refresh_signal =
true;
241 refresh_label =
true;
245 if ( force || refresh_signal || refresh_label) {
251 s+= String(sig) +
"%";
253 lv_label_set_text(esp_lv_network_label, s.c_str());
254 lv_coord_t w = lv_obj_get_width(esp_lv_network_label);
255 lv_obj_set_pos(esp_lv_network_label,
SCREEN_WIDTH-w-5,+15);
258 #endif // WIFI_FEATURE
260 #if defined (ETH_FEATURE)
264 refresh_signal =
true;
268 String tmp = String(ETH.linkSpeed());
272 refresh_label =
true;
277 refresh_label =
true;
280 if (refresh_label || force) {
281 lv_label_set_text(esp_lv_network_label, label.c_str());
286 #if defined (BLUETOOTH_FEATURE)
290 refresh_signal =
true;
295 refresh_label =
true;
298 if( refresh_label || force) {
299 if (label.length()>0) {
300 lv_label_set_text(esp_lv_network_label, label.c_str());
304 #endif //BLUETOOTH_FEATURE
311 if (esp_lv_IP_label !=
nullptr) {
312 bool refresh_label = force;
314 #if defined (WIFI_FEATURE) || defined (ETH_FEATURE) || defined (BLUETOOTH_FEATURE)
318 #if defined (WIFI_FEATURE)
320 s = WiFi.localIP().toString();
323 s = WiFi.softAPIP().toString();
325 #endif //WIFI_FEATURE
326 #if defined (ETH_FEATURE)
328 s = ETH.localIP().toString();
331 #if defined (BLUETOOTH_FEATURE)
335 #endif //BLUETOOTH_FEATURE
342 refresh_label =
true;
345 if (label.length()>0) {
346 lv_label_set_text(esp_lv_IP_label, label.c_str());
351 lv_label_set_text(esp_lv_IP_label,
"");
354 #endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
355 return refresh_label;
362 if (_screenID != screenID) {
363 #if defined(AUTO_SNAPSHOT_FEATURE)
364 if (_screenID != -1) {
365 String s =
"/snap" + String(_screenID);
369 #endif //AUTO_SNAPSHOT_FEATURE
370 _screenID = screenID;
374 lv_obj_t * img_splash = lv_img_create(esp_lv_screen, NULL);
375 lv_img_set_src(img_splash, &esplogo);
376 lv_obj_align(img_splash, NULL, LV_ALIGN_CENTER, 0, -20);
377 esp_lv_bar_progression = lv_bar_create(esp_lv_screen, NULL);
378 lv_obj_set_size(esp_lv_bar_progression, 200, 30);
379 lv_obj_align(esp_lv_bar_progression, NULL, LV_ALIGN_CENTER, 0, 80);
380 lv_bar_set_range(esp_lv_bar_progression, 0, 90);
381 lv_obj_t * labelsplash = lv_label_create(esp_lv_screen, NULL);
382 lv_label_set_text(labelsplash,
"Please wait...");
383 lv_obj_align(labelsplash, NULL, LV_ALIGN_CENTER, 0, 120);
387 lv_obj_t * esp_lv_top_container;
388 lv_obj_t * esp_lv_main_container;
389 lv_obj_t * esp_lv_bottom_container;
391 esp_lv_top_container = lv_obj_create(esp_lv_screen, NULL);
392 lv_obj_set_pos(esp_lv_top_container, 0,-10);
393 lv_obj_set_size(esp_lv_top_container,
SCREEN_WIDTH, 40);
394 lv_obj_set_style(esp_lv_top_container, &lv_style_pretty_color);
396 esp_lv_IP_label = lv_label_create(esp_lv_top_container, NULL);
397 lv_label_set_text(esp_lv_IP_label,
"0.0.0.0");
398 lv_obj_align(esp_lv_IP_label, NULL, LV_ALIGN_IN_LEFT_MID, 10,+5);
401 esp_lv_network_label = lv_label_create(esp_lv_top_container, NULL);
402 lv_label_set_text(esp_lv_network_label, LV_SYMBOL_CLOSE);
403 lv_coord_t w = lv_obj_get_width(esp_lv_network_label);
404 lv_obj_set_pos(esp_lv_network_label,
SCREEN_WIDTH-w-5,+15);
408 esp_lv_main_container = lv_obj_create(esp_lv_screen, NULL);
409 lv_obj_set_pos(esp_lv_main_container, 0,30);
411 lv_obj_set_style(esp_lv_main_container, &lv_style_scr);
414 esp_lv_bottom_container = lv_obj_create(esp_lv_screen, NULL);
416 lv_obj_set_size(esp_lv_bottom_container,
SCREEN_WIDTH, 40);
417 lv_obj_set_style(esp_lv_bottom_container, &lv_style_pretty_color);
420 esp_lv_status_label = lv_label_create(esp_lv_bottom_container, NULL);
421 lv_label_set_text(esp_lv_status_label, _status.c_str());
422 lv_obj_align(esp_lv_status_label, NULL, LV_ALIGN_IN_LEFT_MID, 10,-5);
427 lv_obj_t * labeltouch = lv_label_create(esp_lv_screen, NULL);
428 lv_label_set_text(labeltouch,
"Touch corners when requested.");
429 lv_obj_align(labeltouch, NULL, LV_ALIGN_CENTER, 0, 0);
447 esp_lv_screen =
nullptr;
448 esp_lv_status_label =
nullptr;
449 esp_lv_bar_progression =
nullptr;
450 esp_lv_IP_label =
nullptr;
451 esp_lv_network_label =
nullptr;
465 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
466 #if defined(DISPLAY_I2C_PIN_RST)
467 pinMode(DISPLAY_I2C_PIN_RST,OUTPUT);
468 digitalWrite(DISPLAY_I2C_PIN_RST, LOW);
470 digitalWrite(DISPLAY_I2C_PIN_RST, HIGH);
471 #endif //DISPLAY_I2C_PIN_RST
473 esp3d_screen.clear();
474 #if defined(DISPLAY_FLIP_VERTICALY)
475 esp3d_screen.flipScreenVertically();
477 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
478 #if (DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
479 #if defined (DISPLAY_LED_PIN) && (DISPLAY_LED_PIN!=-1)
480 pinMode(DISPLAY_LED_PIN, OUTPUT);
481 digitalWrite(DISPLAY_LED_PIN, HIGH);
482 #endif //DISPLAY_LED_PIN
486 lv_log_register_print(esp_lv_print);
488 esp3d_screen.begin();
489 #if defined(DISPLAY_FLIP_VERTICALY)
490 esp3d_screen.setRotation(3);
492 esp3d_screen.setRotation(1);
496 lv_disp_buf_init(&esp_lv_disp_buf, lv_buf1, lv_buf2, LV_HOR_RES_MAX * 10);
499 lv_disp_drv_t esp_lv_disp_drv;
500 lv_disp_drv_init(&esp_lv_disp_drv);
504 esp_lv_disp_drv.flush_cb = esp_lv_disp_flush;
505 esp_lv_disp_drv.buffer = &esp_lv_disp_buf;
506 lv_disp_drv_register(&esp_lv_disp_drv);
509 lv_fs_drv_t esp_lv_flash_drv;
510 memset(&esp_lv_flash_drv, 0,
sizeof(lv_fs_drv_t));
511 esp_lv_flash_drv.file_size =
sizeof(
file_t);
512 esp_lv_flash_drv.letter = ESP_FLASH_LETTER_DRIVE;
518 lv_fs_drv_register(&esp_lv_flash_drv);
522 #if defined(DISPLAY_LED_PIN) && (DISPLAY_LED_PIN != -1)
523 pinMode(DISPLAY_LED_PIN, OUTPUT);
524 digitalWrite(DISPLAY_LED_PIN, HIGH);
525 #endif //DISPLAY_LED_PIN
526 #endif //(DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240) || (DISPLAY_DEVICE == TFT_SPI_ILI9488_480X320)
527 #if defined(DISPLAY_TOUCH_DRIVER)
529 uint16_t calibrationData[5];
530 for (uint8_t i = 0; i < 5; i++) {
533 esp3d_screen.setTouch(calibrationData);
537 lv_indev_drv_t esp_lv_indev_drv;
538 lv_indev_drv_init(&esp_lv_indev_drv);
539 esp_lv_indev_drv.type = LV_INDEV_TYPE_POINTER;
540 esp_lv_indev_drv.read_cb = esp_lv_touch_read;
541 lv_indev_drv_register(&esp_lv_indev_drv);
542 #endif //DISPLAY_TOUCH_DRIVER
544 #if DISPLAY_UI_COLOR == UI_MONOCHROME
545 lv_theme_t *th = lv_theme_mono_init(0, NULL);
546 lv_theme_set_current(th);
547 #endif //DISPLAY_UI_COLOR == UI_MONOCHROME
550 esp_lv_tick.attach_ms(LVGL_TICK_PERIOD, esp_lv_tick_handler);
577 if (esp_lv_status_label !=
nullptr) {
578 lv_label_set_text(esp_lv_status_label, status);
586 if(esp_lv_screen !=
nullptr) {
587 lv_obj_del(esp_lv_screen);
590 esp_lv_status_label =
nullptr;
591 esp_lv_bar_progression =
nullptr;
592 esp_lv_IP_label =
nullptr;
593 esp_lv_network_label =
nullptr;
596 esp_lv_screen = lv_obj_create(lv_scr_act(), NULL);
597 lv_obj_set_pos(esp_lv_screen, 0,0);
599 lv_obj_set_style(esp_lv_screen, &lv_style_scr);
606 static uint32_t last_update;
610 if ((millis() - last_update) > 1000) {
611 last_update = millis();
616 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
617 esp3d_screen.display();
618 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
636 if (esp_lv_bar_progression) {
637 lv_bar_set_value(esp_lv_bar_progression, v, LV_ANIM_OFF);
647 #if defined(DISPLAY_SNAPSHOT_FEATURE)
663 lv_obj_invalidate(lv_scr_act());
664 lv_refr_now(lv_disp_get_default());
668 if (error_snapshot == 0) {
671 #endif //DISPLAY_SNAPSHOT_FEATURE
675 #endif //DISPLAY_DEVICE