ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
advanceddisplay.cpp
Go to the documentation of this file.
1 /*
2  advanceddisplay.cpp - display functions class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #include "../../include/esp3d_config.h"
22 #if defined (DISPLAY_DEVICE) && (DISPLAY_UI_TYPE == UI_TYPE_ADVANCED)
23 
24 //to get bmp file use ImageMagick
25 //Under Windows:
26 //ImageMagick-7.0.8-Q16>magick.exe -size 480x320 -depth 8 bgra:snapshot.bin snap.bmp
27 //On others systems:
28 //convert -size 480x320 -depth 8 bgra:snapshot.bin snap.bmp
29 #define SNAPFILENAME "/snapshot.bin"
30 
31 #include "advanceddisplay.h"
32 #include "../../core/settings_esp3d.h"
33 #include "../../core/esp3doutput.h"
34 #include "../filesystem/esp_filesystem.h"
35 #include <lvgl.h>
36 #include <Ticker.h>
37 #include "lv_flash_drv.h"
38 //screen object
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;
44 
45 #if defined(DISPLAY_SNAPSHOT_FEATURE)
46 static ESP_File fsSnapFile;
47 static bool bSnapshot;
48 #endif //DISPLAY_SNAPSHOT_FEATURE
49 
50 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
51 #include "Wire.h"
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);
60 #include "advanced_SSDSH1106.h"
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)
64 #include <TFT_eSPI.h>
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"
78 #endif //ETH_FEATURE
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
85 
86 
88 
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
95 Ticker esp_lv_tick; /* timer for interrupt handler */
96 #define LVGL_TICK_PERIOD 10
97 #define ESP_FLASH_LETTER_DRIVE 'F'
98 //#define ESP_SD_LETTER_DRIVE 'S'
99 
100 //Logo
101 LV_IMG_DECLARE(esplogo)
102 
103 /* Display flushing */
104 void esp_lv_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
105 {
106  //TODO: need to write version for oled with big resolution
107  uint16_t c;
108  esp3d_screen.startWrite(); /* Start new TFT transaction */
109  esp3d_screen.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1)); /* set the working window */
110  for (int y = area->y1; y <= area->y2; y++) {
111  for (int x = area->x1; x <= area->x2; x++) {
112  c = color_p->full;
113  esp3d_screen.writeColor(c, 1);
114 #if defined(DISPLAY_SNAPSHOT_FEATURE)
115  if(bSnapshot) {
116  uint32_t data = lv_color_to32(*color_p);
117  //to handle any write issue
118  if (fsSnapFile.write((const uint8_t *)(&data), sizeof(uint32_t)) != sizeof(uint32_t)) {
119  //if error we stop to dump
120  bSnapshot = false;
121  //raise error
122  error_snapshot = 1;
123  }
124  }
125 #endif //DISPLAY_SNAPSHOT_FEATURE
126  color_p++;
127  }
128  }
129  esp3d_screen.endWrite(); /* terminate TFT transaction */
130  lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */
131 }
132 
133 /* Interrupt driven periodic handler */
134 static void esp_lv_tick_handler(void)
135 {
136  lv_tick_inc(LVGL_TICK_PERIOD);
137 }
138 
139 #if USE_LV_LOG != 0
140 /* Serial debugging */
141 void esp_lv_print(lv_log_level_t level, const char * file, uint32_t line, const char * dsc)
142 {
143 
144  Serial.printf("%s@%d->%s\r\n", file, line, dsc);
145  delay(100);
146 }
147 #endif
148 
149 #if defined(DISPLAY_TOUCH_DRIVER)
150 bool esp_lv_touch_read(lv_indev_drv_t * indev, lv_indev_data_t * data)
151 {
152 // Use TFT_eSPI for touch events
153  uint8_t bPressed = 0;
154  uint16_t nX=0;
155  uint16_t nY=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) {
159  last_x = nX;
160  last_y = nY;
161  data->state = LV_INDEV_STATE_PR;
162  } else {
163  data->state = LV_INDEV_STATE_REL;
164  }
165  data->point.x = last_x;
166  data->point.y = last_y;
167  return false;
168 }
169 #endif //DISPLAY_TOUCH_DRIVER
170 
172 {
173  //TODO add better calibration page with sound and contextual text
174  bool res = false;
175 #if defined(DISPLAY_TOUCH_DRIVER)
176 #if DISPLAY_TOUCH_DRIVER == XPT2046_SPI
177  uint16_t calibrationData[5];
179  update_screen(true);
180  esp3d_screen.calibrateTouch(calibrationData, CALIBRATION_CORNER, CALIBRATION_BG, 20);
181  res = true;
182  for (uint8_t i = 0; i < 5; i++) {
183  if(!Settings_ESP3D::write_uint32 (ESP_CALIBRATION_1+(4*i), calibrationData[i])) {
184  res= false;
185  }
186  }
188  res= false;
189  }
190  if(res) {
191  SetStatus("Calibration done");
192  } else {
193  SetStatus("Calibration error");
194  }
196 #endif //XPT2046_SPI
197 
198 #endif //DISPLAY_TOUCH_DRIVER
199  return res;
200 }
201 
202 
203 bool Display::display_network_status(bool force)
204 {
205  if (esp_lv_network_label == nullptr) {
206  return false;
207  }
208  static int sig = -1;
209  bool refresh_signal = false;
210  bool refresh_label = false;
211  static String label;
212 #if defined (WIFI_FEATURE)
213  if (WiFiConfig::started()) {
214 
215  if (WiFi.getMode() == WIFI_AP) {
216  if (sig != 100) {
217  sig = 100;
218  refresh_signal = true;
219  }
220  if (label != WiFiConfig::AP_SSID()) {
221  label = WiFiConfig::AP_SSID();
222  refresh_label = true;
223  }
224  } else {
225  if (WiFi.isConnected()) {
226  if (sig != WiFiConfig::getSignal (WiFi.RSSI ())) {
227  sig = WiFiConfig::getSignal (WiFi.RSSI ());
228  refresh_signal = true;
229  }
230  if (label != WiFi.SSID()) {
231  label = WiFi.SSID();
232  refresh_label = true;
233  }
234  } else {
235  if (sig != -1) {
236  sig = -1;
237  refresh_signal = true;
238  }
239  if (label != "") {
240  label = "";
241  refresh_label = true;
242  }
243  }
244  }
245  if ( force || refresh_signal || refresh_label) {
246  String s ;
247  if (sig == -1) {
248  s = LV_SYMBOL_CLOSE;
249  } else {
250  s = LV_SYMBOL_WIFI;
251  s+= String(sig) + "%";
252  }
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);
256  }
257  }
258 #endif // WIFI_FEATURE
259 
260 #if defined (ETH_FEATURE)
261  if (EthConfig::started()) {
262  if (sig != -2) {
263  sig = -2;
264  refresh_signal = true;
265  }
266  //display connection speed
267  if(ETH.linkUp()) {
268  String tmp = String(ETH.linkSpeed());
269  tmp+= "Mbps";
270  if (label != tmp) {
271  label = tmp;
272  refresh_label = true;
273  }
274  } else {
275  if (label !="") {
276  label ="";
277  refresh_label = true;
278  }
279  }
280  if (refresh_label || force) {
281  lv_label_set_text(esp_lv_network_label, label.c_str());
282  }
283  }
284 #endif //ETH_FEATURE
285 
286 #if defined (BLUETOOTH_FEATURE)
287  if (bt_service.started()) {
288  if (sig!=-3) {
289  sig = -3;
290  refresh_signal = true;
291  }
292 
293  //Display hostname
294  if (label != bt_service.hostname()) {
295  refresh_label = true;
296  label = bt_service.hostname();
297  }
298  if( refresh_label || force) {
299  if (label.length()>0) {
300  lv_label_set_text(esp_lv_network_label, label.c_str());
301  }
302  }
303  }
304 #endif //BLUETOOTH_FEATURE
305 
306  return true;
307 }
308 
309 bool Display::display_IP(bool force)
310 {
311  if (esp_lv_IP_label != nullptr) {
312  bool refresh_label = force;
313  static String label;
314 #if defined (WIFI_FEATURE) || defined (ETH_FEATURE) || defined (BLUETOOTH_FEATURE)
315  if (NetConfig::started()) {
316  String s;
317  switch(NetConfig::getMode()) {
318 #if defined (WIFI_FEATURE)
319  case ESP_WIFI_STA:
320  s = WiFi.localIP().toString();
321  break;
322  case ESP_WIFI_AP:
323  s = WiFi.softAPIP().toString();
324  break;
325 #endif //WIFI_FEATURE
326 #if defined (ETH_FEATURE)
327  case ESP_ETH_STA:
328  s = ETH.localIP().toString();
329  break;
330 #endif //ETH_FEATURE
331 #if defined (BLUETOOTH_FEATURE)
332  case ESP_BT:
333  s = bt_service.isConnected()?"Connected":"";
334  break;
335 #endif //BLUETOOTH_FEATURE
336  default:
337  s="";
338  break;
339  }
340  if (s!= label) {
341  label = s;
342  refresh_label = true;
343  }
344  if (refresh_label) {
345  if (label.length()>0) {
346  lv_label_set_text(esp_lv_IP_label, label.c_str());
347  }
348  }
349  } else {
350  if (label != "") {
351  lv_label_set_text(esp_lv_IP_label, "");
352  }
353  }
354 #endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
355  return refresh_label;
356  }
357  return false;
358 }
359 
360 void Display::show_screenID(uint8_t screenID)
361 {
362  if (_screenID != screenID) {
363 #if defined(AUTO_SNAPSHOT_FEATURE)
364  if (_screenID != -1) {
365  String s = "/snap" + String(_screenID);
366  s+=".bin";
367  snapshot((char *)s.c_str());
368  }
369 #endif //AUTO_SNAPSHOT_FEATURE
370  _screenID = screenID;
371  clear_screen();
372  switch (screenID) {
373  case SPLASH_SCREEN: {
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);
384  }
385  break;
386  case MAIN_SCREEN: {
387  lv_obj_t * esp_lv_top_container;
388  lv_obj_t * esp_lv_main_container;
389  lv_obj_t * esp_lv_bottom_container;
390  //top
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);
395 
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);
399  display_IP(true);
400 
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);
406 
407  //main window
408  esp_lv_main_container = lv_obj_create(esp_lv_screen, NULL);
409  lv_obj_set_pos(esp_lv_main_container, 0,30);
410  lv_obj_set_size(esp_lv_main_container, SCREEN_WIDTH, SCREEN_HEIGHT - (2*30));
411  lv_obj_set_style(esp_lv_main_container, &lv_style_scr);
412 
413  //bottom
414  esp_lv_bottom_container = lv_obj_create(esp_lv_screen, NULL);
415  lv_obj_set_pos(esp_lv_bottom_container, 0,SCREEN_HEIGHT-30);
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);
418 
419  //status label
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);
423 
424  }
425  break;
426  case CALIBRATION_SCREEN: {
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);
430  }
431  break;
432  default:
433  break;
434  }
435  } else {
436  }
437 
438  update_screen(true);
439 }
440 
442 {
443  _started = false;
444  _screenID = -1;
445  _screenwidth = SCREEN_WIDTH;
446  _screenheight = SCREEN_HEIGHT;
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;
452  bSnapshot = false;
453 }
454 
456 {
457  end();
458 }
459 
460 bool Display::begin()
461 {
462  bool res = true;
463  _started = false;
464  //log_esp3d("Init Display");
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); // turn the LED on (HIGH is the voltage level)
469  delay(10); // wait for a second
470  digitalWrite(DISPLAY_I2C_PIN_RST, HIGH); // turn the LED off by making the voltage LOW
471 #endif //DISPLAY_I2C_PIN_RST
472  esp3d_screen.init();
473  esp3d_screen.clear();
474 #if defined(DISPLAY_FLIP_VERTICALY)
475  esp3d_screen.flipScreenVertically();
476 #endif
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); // sets the digital pin 13 as output
481  digitalWrite(DISPLAY_LED_PIN, HIGH);
482 #endif //DISPLAY_LED_PIN
483  //init lvg
484  lv_init();
485 #if USE_LV_LOG != 0
486  lv_log_register_print(esp_lv_print); /* register print function for debugging */
487 #endif
488  esp3d_screen.begin(); // Initialise the tft display
489 #if defined(DISPLAY_FLIP_VERTICALY)
490  esp3d_screen.setRotation(3);
491 #else
492  esp3d_screen.setRotation(1);
493 #endif
494  //init lvg related functions
495  //double buffer
496  lv_disp_buf_init(&esp_lv_disp_buf, lv_buf1, lv_buf2, LV_HOR_RES_MAX * 10);
497 
498  /*Initialize the display*/
499  lv_disp_drv_t esp_lv_disp_drv;
500  lv_disp_drv_init(&esp_lv_disp_drv);
501  //resolution
502  esp_lv_disp_drv.hor_res = SCREEN_WIDTH;
503  esp_lv_disp_drv.ver_res = SCREEN_HEIGHT;
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);
507 
508  //Register Flash driver for images
509  lv_fs_drv_t esp_lv_flash_drv; /*A driver descriptor*/
510  memset(&esp_lv_flash_drv, 0, sizeof(lv_fs_drv_t)); /*Initialization*/
511  esp_lv_flash_drv.file_size = sizeof(file_t); /*Set up fields...*/
512  esp_lv_flash_drv.letter = ESP_FLASH_LETTER_DRIVE;
513  esp_lv_flash_drv.open_cb = esp_flash_open;
514  esp_lv_flash_drv.close_cb = esp_flash_close;
515  esp_lv_flash_drv.read_cb = esp_flash_read;
516  esp_lv_flash_drv.seek_cb = esp_flash_seek;
517  esp_lv_flash_drv.tell_cb = esp_flash_tell;
518  lv_fs_drv_register(&esp_lv_flash_drv);
519 
520  //TODO: Register SD card driver for images
521 
522 #if defined(DISPLAY_LED_PIN) && (DISPLAY_LED_PIN != -1)
523  pinMode(DISPLAY_LED_PIN, OUTPUT); // sets the digital pin as output
524  digitalWrite(DISPLAY_LED_PIN, HIGH); //switch on the led
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++) {
531  calibrationData[i] = Settings_ESP3D::read_uint32 (ESP_CALIBRATION_1+(4*i));
532  }
533  esp3d_screen.setTouch(calibrationData);
534  }
535 
536  /*Register the touch pad*/
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;//LV_INDEV_TYPE_ENCODER;
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
543 
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
548 
549  /*Initialize the graphics library's tick*/
550  esp_lv_tick.attach_ms(LVGL_TICK_PERIOD, esp_lv_tick_handler);
552  res = true;
553  if (!res) {
554  end();
555  }
556  _started = res;
557  return _started;
558 }
559 
560 void Display::end()
561 {
562  if(!_started) {
563  return;
564  }
565  _status ="";
566  _started = false;
567  _screenID = -1;
568  clear_screen();
569 }
570 
571 void Display::SetStatus(const char * status)
572 {
573  _status = status;
575  return;
576  }
577  if (esp_lv_status_label != nullptr) {
578  lv_label_set_text(esp_lv_status_label, status);
579  update_screen();
580  }
581 }
582 
583 void Display::clear_screen(bool force)
584 {
585  //clear all objects on screen
586  if(esp_lv_screen != nullptr) {
587  lv_obj_del(esp_lv_screen);
588  }
589  //reset global object
590  esp_lv_status_label = nullptr;
591  esp_lv_bar_progression = nullptr;
592  esp_lv_IP_label = nullptr;
593  esp_lv_network_label = nullptr;
594 
595  //create enpty screen
596  esp_lv_screen = lv_obj_create(lv_scr_act(), NULL);
597  lv_obj_set_pos(esp_lv_screen, 0,0);
598  lv_obj_set_size(esp_lv_screen, SCREEN_WIDTH, SCREEN_HEIGHT);
599  lv_obj_set_style(esp_lv_screen, &lv_style_scr);
600  //update screen
601  update_screen(force);
602 }
603 
604 void Display::update_screen(bool force)
605 {
606  static uint32_t last_update;
608  return;
609  }
610  if ((millis() - last_update) > 1000) {
611  last_update = millis();
613  }
614  lv_task_handler();
615  if(force) {
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
619  delay(100);
620  lv_task_handler();
621  }
622 }
623 
624 void Display::handle()
625 {
626  if (_started) {
627  update_screen();
628  }
629 }
630 
631 void Display::progress(uint8_t v)
632 {
634  return;
635  }
636  if (esp_lv_bar_progression) {
637  lv_bar_set_value(esp_lv_bar_progression, v, LV_ANIM_OFF);
638  update_screen();
639  }
640 }
641 
642 
643 
644 bool Display::snapshot(char * filename)
645 {
646  bool res = false;
647 #if defined(DISPLAY_SNAPSHOT_FEATURE)
648  //sanity check to avoid to corrupt FS with capacity overload
649  error_snapshot = 0;
651  return false;
652  }
653  if(filename) {
654  fsSnapFile = ESP_FileSystem::open(filename, ESP_FILE_WRITE);
655  } else {
656  fsSnapFile = ESP_FileSystem::open(SNAPFILENAME, ESP_FILE_WRITE);
657  }
658  if (!fsSnapFile) {
659  return false;
660  }
661 
662  bSnapshot = true;
663  lv_obj_invalidate(lv_scr_act());
664  lv_refr_now(lv_disp_get_default()); /* Will call our disp_drv.disp_flush function */
665  bSnapshot = false;
666  fsSnapFile.close();
667  //if any snapshot error
668  if (error_snapshot == 0) {
669  res = true;
670  }
671 #endif //DISPLAY_SNAPSHOT_FEATURE
672  return res;
673 }
674 
675 #endif //DISPLAY_DEVICE
Settings_ESP3D::write_byte
static bool write_byte(int pos, const uint8_t value)
Definition: settings_esp3d.cpp:749
advanced_ILI9341_320X240.h
ESP_File::close
void close()
Display::show_screenID
void show_screenID(uint8_t screenID)
ESP3DOutput::isOutput
static bool isOutput(uint8_t flag, bool fromsettings=false)
Definition: esp3doutput.cpp:78
Display::end
void end()
SCREEN_HEIGHT
#define SCREEN_HEIGHT
Definition: advanced_ILI9341_320X240.h:22
ESP_WIFI_STA
#define ESP_WIFI_STA
Definition: netconfig.h:41
ESP_FILE_WRITE
#define ESP_FILE_WRITE
Definition: defines.h:121
advanced_SSDSH1106.h
file
FTPFile file
Definition: FtpServer.cpp:104
SPLASH_SCREEN
#define SPLASH_SCREEN
Definition: advanceddisplay.h:21
Display::begin
bool begin()
Display::~Display
~Display()
Display::snapshot
bool snapshot(char *filename=nullptr)
Display::SetStatus
void SetStatus(const char *status)
Settings_ESP3D::write_uint32
static bool write_uint32(int pos, const uint32_t value)
Definition: settings_esp3d.cpp:970
lv_flash_drv.h
Display
Definition: advanceddisplay.h:29
WiFiConfig::getSignal
static int32_t getSignal(int32_t RSSI)
Definition: wificonfig.cpp:107
EthConfig::started
static bool started()
NetConfig::getMode
static uint8_t getMode()
Definition: netconfig.cpp:207
CALIBRATION_BG
#define CALIBRATION_BG
Definition: advanced_ILI9341_320X240.h:25
ESP_CALIBRATION_1
#define ESP_CALIBRATION_1
Definition: settings_esp3d.h:84
ESP_File
Definition: esp_filesystem.h:30
Display::display_network_status
bool display_network_status(bool force=false)
CALIBRATION_CORNER
#define CALIBRATION_CORNER
Definition: advanced_ILI9341_320X240.h:26
ESP_CALIBRATION
#define ESP_CALIBRATION
Definition: settings_esp3d.h:48
Display::Display
Display()
file_t
Definition: lv_flash_drv.h:28
MAIN_SCREEN
#define MAIN_SCREEN
Definition: advanceddisplay.h:23
ESP_FileSystem::freeBytes
static size_t freeBytes()
Display::update_screen
void update_screen(bool force=false)
ESP_BT
#define ESP_BT
Definition: netconfig.h:43
Settings_ESP3D::read_uint32
static uint32_t read_uint32(int pos, bool *haserror=NULL)
Definition: settings_esp3d.cpp:919
esp_flash_tell
lv_fs_res_t esp_flash_tell(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p)
esp_flash_seek
lv_fs_res_t esp_flash_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos)
advanceddisplay.h
ESP_ETH_STA
#define ESP_ETH_STA
Definition: netconfig.h:44
CALIBRATION_SCREEN
#define CALIBRATION_SCREEN
Definition: advanceddisplay.h:22
ESP_SCREEN_CLIENT
#define ESP_SCREEN_CLIENT
Definition: esp3doutput.h:28
esp_flash_read
lv_fs_res_t esp_flash_read(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br)
BTService::started
bool started()
esp_flash_open
lv_fs_res_t esp_flash_open(lv_fs_drv_t *drv, void *file_p, const char *fn, lv_fs_mode_t mode)
NetConfig::started
static bool started()
Definition: netconfig.h:74
SNAP_SIZE
#define SNAP_SIZE
Definition: advanced_ILI9341_320X240.h:23
Display::progress
void progress(uint8_t v)
Settings_ESP3D::read_byte
static uint8_t read_byte(int pos, bool *haserror=NULL)
Definition: settings_esp3d.cpp:715
esp_flash_close
lv_fs_res_t esp_flash_close(lv_fs_drv_t *drv, void *file_p)
ESP_File::write
size_t write(uint8_t i)
Definition: esp_filesystem.cpp:156
esp3d_display
Display esp3d_display
bt_service
BTService bt_service
Display::display_IP
bool display_IP(bool force=false)
Display::handle
void handle()
BTService::isConnected
bool isConnected()
Display::startCalibration
bool startCalibration()
ESP_WIFI_AP
#define ESP_WIFI_AP
Definition: netconfig.h:42
BTService::hostname
const char * hostname()
Display::clear_screen
void clear_screen()
WiFiConfig::started
static bool started()
Definition: wificonfig.cpp:270
WiFiConfig::AP_SSID
static const char * AP_SSID()
Definition: wificonfig.cpp:387
SCREEN_WIDTH
#define SCREEN_WIDTH
Definition: advanced_ILI9341_320X240.h:21
advanced_ILI9488_480X320.h
ESP_FileSystem::open
static ESP_File open(const char *path, uint8_t mode=ESP_FILE_READ)