Add simple calibration screen using lvg label

This commit is contained in:
Luc 2019-08-16 10:35:44 +02:00
parent e7fbfdc628
commit cecd0a9de0
3 changed files with 18 additions and 10 deletions

View File

@ -21,6 +21,5 @@
#define SCREEN_WIDTH 480 #define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 320 #define SCREEN_HEIGHT 320
#define CALIBRATION_BG TFT_BLACK #define CALIBRATION_BG TFT_WHITE
#define CALIBRATION_FG TFT_GREEN
#define CALIBRATION_CORNER TFT_RED #define CALIBRATION_CORNER TFT_RED

View File

@ -146,12 +146,13 @@ bool Display::startCalibration()
#if defined(DISPLAY_TOUCH_DRIVER) #if defined(DISPLAY_TOUCH_DRIVER)
#if DISPLAY_TOUCH_DRIVER == XPT2046_SPI #if DISPLAY_TOUCH_DRIVER == XPT2046_SPI
uint16_t calibrationData[5]; uint16_t calibrationData[5];
clear_screen(); show_screenID(CALIBRATION_SCREEN);
update_screen(true);
//display instructions //display instructions
/*uint size = getStringWidth("Touch corners as indicated"); /*uint size = getStringWidth("Touch corners as indicated");
setTextFont(FONTCALIBRATION); setTextFont(FONTCALIBRATION);
drawString("Touch corners as indicated", (SCREEN_WIDTH-size)/2, (SCREEN_HEIGHT-16)/2, CALIBRATION_FG);*/ drawString("Touch corners as indicated", (SCREEN_WIDTH-size)/2, (SCREEN_HEIGHT-16)/2, CALIBRATION_FG);*/
esp3d_screen.calibrateTouch(calibrationData, CALIBRATION_CORNER, CALIBRATION_BG, 15); esp3d_screen.calibrateTouch(calibrationData, CALIBRATION_CORNER, CALIBRATION_BG, 20);
res = true; res = true;
for (uint8_t i = 0; i < 5; i++) { for (uint8_t i = 0; i < 5; i++) {
if(!Settings_ESP3D::write_uint32 (ESP_CALIBRATION_1+(4*i), calibrationData[i])) { if(!Settings_ESP3D::write_uint32 (ESP_CALIBRATION_1+(4*i), calibrationData[i])) {
@ -161,13 +162,12 @@ bool Display::startCalibration()
if (!Settings_ESP3D::write_byte (ESP_CALIBRATION, 1)) { if (!Settings_ESP3D::write_byte (ESP_CALIBRATION, 1)) {
res= false; res= false;
} }
clear_screen();
if(res) { if(res) {
SetStatus("Calibration done"); SetStatus("Calibration done");
} else { } else {
SetStatus("Calibration error"); SetStatus("Calibration error");
} }
update_screen(true); show_screenID(MAIN_SCREEN);
#endif //XPT2046_SPI #endif //XPT2046_SPI
#endif //DISPLAY_TOUCH_DRIVER #endif //DISPLAY_TOUCH_DRIVER
@ -387,10 +387,17 @@ void Display::show_screenID(uint8_t screenID)
//status label //status label
esp_lv_status_label = lv_label_create(esp_lv_bottom_container, NULL); esp_lv_status_label = lv_label_create(esp_lv_bottom_container, NULL);
lv_label_set_text(esp_lv_status_label, _status.c_str()); lv_label_set_text(esp_lv_status_label, _status.c_str());
lv_obj_align(esp_lv_status_label, NULL, LV_ALIGN_OUT_LEFT_MID, 10,-5); lv_obj_align(esp_lv_status_label, NULL, LV_ALIGN_IN_LEFT_MID, 10,-5);
} }
break; break;
case CALIBRATION_SCREEN:
{
lv_obj_t * labeltouch = lv_label_create(esp_lv_screen, NULL);
lv_label_set_text(labeltouch, "Touch corners when requested.");
lv_obj_align(labeltouch, NULL, LV_ALIGN_CENTER, 0, 0);
}
break;
default: default:
break; break;
} }
@ -541,7 +548,7 @@ void Display::SetStatus(const char * status)
} }
} }
void Display::clear_screen() void Display::clear_screen(bool force)
{ {
//clear all objects on screen //clear all objects on screen
if(esp_lv_screen != nullptr){ if(esp_lv_screen != nullptr){
@ -559,7 +566,7 @@ void Display::clear_screen()
lv_obj_set_size(esp_lv_screen, SCREEN_WIDTH, SCREEN_HEIGHT); lv_obj_set_size(esp_lv_screen, SCREEN_WIDTH, SCREEN_HEIGHT);
lv_obj_set_style(esp_lv_screen, &lv_style_scr); lv_obj_set_style(esp_lv_screen, &lv_style_scr);
//update screen //update screen
update_screen(true); update_screen(force);
} }
void Display::update_screen(bool force) void Display::update_screen(bool force)
@ -577,6 +584,8 @@ void Display::update_screen(bool force)
#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106 #if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
esp3d_screen.display(); esp3d_screen.display();
#endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106 #endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
delay(100);
lv_task_handler();
} }
} }

View File

@ -38,7 +38,7 @@ public:
bool display_network_status(bool force = false); bool display_network_status(bool force = false);
void show_screenID(uint8_t screenID); void show_screenID(uint8_t screenID);
void update_screen(bool force=false); void update_screen(bool force=false);
void clear_screen(); void clear_screen(bool force=false);
void progress(uint8_t v); void progress(uint8_t v);
void SetStatus(const char * status); void SetStatus(const char * status);
bool startCalibration(); bool startCalibration();