2020-06-16 04:05:33 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-06-16 04:05:33 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "../../../../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#if HAS_TFT_LVGL_UI
|
2020-06-16 04:05:33 +02:00
|
|
|
|
|
|
|
#include "draw_ui.h"
|
2020-10-21 19:45:27 +02:00
|
|
|
#include <lv_conf.h>
|
2020-06-16 04:05:33 +02:00
|
|
|
//#include "../lvgl/src/lv_objx/lv_imgbtn.h"
|
|
|
|
//#include "../lvgl/src/lv_objx/lv_img.h"
|
|
|
|
//#include "../lvgl/src/lv_core/lv_disp.h"
|
|
|
|
//#include "../lvgl/src/lv_core/lv_refr.h"
|
|
|
|
|
2020-10-21 19:45:27 +02:00
|
|
|
#include "../../../../inc/MarlinConfig.h"
|
2020-06-16 04:05:33 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
//static lv_obj_t *buttonMoveZ,*buttonTest,*buttonZ0,*buttonStop,*buttonReturn;
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#define ID_CN 1
|
|
|
|
#define ID_T_CN 2
|
|
|
|
#define ID_EN 3
|
|
|
|
#define ID_RU 4
|
|
|
|
#define ID_ES 5
|
|
|
|
#define ID_FR 6
|
|
|
|
#define ID_IT 7
|
|
|
|
#define ID_L_RETURN 8
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#define SELECTED 1
|
|
|
|
#define UNSELECTED 0
|
2020-06-16 04:05:33 +02:00
|
|
|
|
|
|
|
static void disp_language(uint8_t language, uint8_t state);
|
|
|
|
|
2020-09-21 03:55:02 +02:00
|
|
|
extern lv_group_t * g;
|
2020-06-16 04:05:33 +02:00
|
|
|
static lv_obj_t * scr;
|
|
|
|
static lv_obj_t *buttonCN, *buttonT_CN, *buttonEN, *buttonRU;
|
|
|
|
static lv_obj_t *buttonES, *buttonFR, *buttonIT, *buttonBack;
|
|
|
|
|
|
|
|
static void event_handler(lv_obj_t * obj, lv_event_t event) {
|
|
|
|
switch (obj->mks_obj_id) {
|
|
|
|
case ID_CN:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(buttonCN, "F:/bmp_simplified_cn_sel.bin");
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(buttonCN);
|
2020-06-16 04:05:33 +02:00
|
|
|
gCfgItems.language = LANG_SIMPLE_CHINESE;
|
2020-09-21 03:55:02 +02:00
|
|
|
update_spi_flash();
|
2020-06-16 04:05:33 +02:00
|
|
|
disp_language_init();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_T_CN:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(buttonT_CN, "F:/bmp_traditional_cn_sel.bin");
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(buttonT_CN);
|
2020-06-16 04:05:33 +02:00
|
|
|
gCfgItems.language = LANG_COMPLEX_CHINESE;
|
2020-09-21 03:55:02 +02:00
|
|
|
update_spi_flash();
|
2020-06-16 04:05:33 +02:00
|
|
|
disp_language_init();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_EN:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(buttonEN, "F:/bmp_english_sel.bin");
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(buttonEN);
|
2020-06-16 04:05:33 +02:00
|
|
|
gCfgItems.language = LANG_ENGLISH;
|
2020-09-21 03:55:02 +02:00
|
|
|
update_spi_flash();
|
2020-06-16 04:05:33 +02:00
|
|
|
disp_language_init();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_RU:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(buttonRU, "F:/bmp_russian_sel.bin");
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(buttonRU);
|
2020-06-16 04:05:33 +02:00
|
|
|
gCfgItems.language = LANG_RUSSIAN;
|
2020-09-21 03:55:02 +02:00
|
|
|
update_spi_flash();
|
2020-06-16 04:05:33 +02:00
|
|
|
disp_language_init();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_ES:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(buttonES, "F:/bmp_spanish_sel.bin");
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(buttonES);
|
2020-06-16 04:05:33 +02:00
|
|
|
gCfgItems.language = LANG_SPANISH;
|
2020-09-21 03:55:02 +02:00
|
|
|
update_spi_flash();
|
2020-06-16 04:05:33 +02:00
|
|
|
disp_language_init();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_FR:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(buttonFR, "F:/bmp_french_sel.bin");
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(buttonFR);
|
2020-06-16 04:05:33 +02:00
|
|
|
gCfgItems.language = LANG_FRENCH;
|
2020-09-21 03:55:02 +02:00
|
|
|
update_spi_flash();
|
2020-06-16 04:05:33 +02:00
|
|
|
disp_language_init();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_IT:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(buttonIT, "F:/bmp_italy_sel.bin");
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(buttonIT);
|
2020-06-16 04:05:33 +02:00
|
|
|
gCfgItems.language = LANG_ITALY;
|
2020-09-21 03:55:02 +02:00
|
|
|
update_spi_flash();
|
2020-06-16 04:05:33 +02:00
|
|
|
disp_language_init();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_L_RETURN:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
2020-07-25 07:52:07 +02:00
|
|
|
buttonCN = NULL;
|
2020-06-16 04:05:33 +02:00
|
|
|
buttonT_CN = NULL;
|
2020-07-25 07:52:07 +02:00
|
|
|
buttonEN = NULL;
|
|
|
|
buttonRU = NULL;
|
|
|
|
buttonES = NULL;
|
|
|
|
buttonFR = NULL;
|
|
|
|
buttonFR = NULL;
|
|
|
|
buttonIT = NULL;
|
2020-06-16 04:05:33 +02:00
|
|
|
buttonBack = NULL;
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_clear_language();
|
2020-06-16 04:05:33 +02:00
|
|
|
lv_draw_set();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disp_language(uint8_t language, uint8_t state) {
|
|
|
|
uint16_t id;
|
|
|
|
lv_obj_t *obj;
|
|
|
|
|
|
|
|
public_buf_l[0] = '\0';
|
|
|
|
|
|
|
|
switch (language) {
|
|
|
|
case LANG_SIMPLE_CHINESE:
|
|
|
|
id = ID_CN;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_simplified_cn"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonCN;
|
|
|
|
break;
|
|
|
|
case LANG_COMPLEX_CHINESE:
|
|
|
|
id = ID_T_CN;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_traditional_cn"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonT_CN;
|
|
|
|
break;
|
|
|
|
case LANG_ENGLISH:
|
|
|
|
id = ID_EN;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_english"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonEN;
|
|
|
|
break;
|
|
|
|
case LANG_RUSSIAN:
|
|
|
|
id = ID_RU;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_russian"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonRU;
|
|
|
|
break;
|
|
|
|
case LANG_SPANISH:
|
|
|
|
id = ID_ES;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_spanish"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonES;
|
|
|
|
break;
|
|
|
|
case LANG_FRENCH:
|
|
|
|
id = ID_FR;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_french"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonFR;
|
|
|
|
break;
|
|
|
|
case LANG_ITALY:
|
|
|
|
id = ID_IT;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_italy"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonIT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
id = ID_CN;
|
2020-09-21 03:55:02 +02:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_simplified_cn"));
|
2020-06-16 04:05:33 +02:00
|
|
|
obj = buttonCN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
if (state == SELECTED) strcat_P(public_buf_l, PSTR("_sel"));
|
|
|
|
|
|
|
|
strcat_P(public_buf_l, PSTR(".bin"));
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-09-21 03:55:02 +02:00
|
|
|
lv_obj_set_event_cb_mks(obj, event_handler, id, NULL, 0);
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_imgbtn_set_src_both(obj, public_buf_l);
|
2020-06-16 04:05:33 +02:00
|
|
|
|
|
|
|
if (state == UNSELECTED) lv_obj_refresh_ext_draw_pad(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_draw_language(void) {
|
|
|
|
|
|
|
|
if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LANGUAGE_UI) {
|
|
|
|
disp_state_stack._disp_index++;
|
|
|
|
disp_state_stack._disp_state[disp_state_stack._disp_index] = LANGUAGE_UI;
|
|
|
|
}
|
|
|
|
disp_state = LANGUAGE_UI;
|
|
|
|
|
|
|
|
scr = lv_obj_create(NULL, NULL);
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
// static lv_style_t tool_style;
|
2020-06-16 04:05:33 +02:00
|
|
|
|
|
|
|
lv_obj_set_style(scr, &tft_style_scr);
|
|
|
|
lv_scr_load(scr);
|
|
|
|
lv_obj_clean(scr);
|
|
|
|
|
2020-10-23 03:22:17 +02:00
|
|
|
(void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text());
|
2020-06-16 04:05:33 +02:00
|
|
|
|
|
|
|
lv_refr_now(lv_refr_get_disp_refreshing());
|
|
|
|
|
2020-09-21 02:07:59 +02:00
|
|
|
// Create image buttons
|
2020-10-23 03:22:17 +02:00
|
|
|
buttonCN = lv_imgbtn_create(scr, "F:/bmp_simplified_cn.bin", INTERVAL_V, titleHeight, event_handler, ID_CN);
|
2020-06-16 04:05:33 +02:00
|
|
|
lv_obj_clear_protect(buttonCN, LV_PROTECT_FOLLOW);
|
2020-10-23 03:22:17 +02:00
|
|
|
buttonT_CN = lv_imgbtn_create(scr, "F:/bmp_traditional_cn.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_CN);
|
|
|
|
buttonEN = lv_imgbtn_create(scr, "F:/bmp_english.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_EN);
|
|
|
|
buttonRU = lv_imgbtn_create(scr, "F:/bmp_russian.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_RU);
|
|
|
|
buttonES = lv_imgbtn_create(scr, "F:/bmp_spanish.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_ES);
|
|
|
|
buttonFR = lv_imgbtn_create(scr, "F:/bmp_french.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FR);
|
|
|
|
buttonIT = lv_imgbtn_create(scr, "F:/bmp_italy.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_IT);
|
|
|
|
buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_L_RETURN);
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-09-21 02:07:59 +02:00
|
|
|
// Create labels on the image buttons
|
2020-10-23 03:22:17 +02:00
|
|
|
lv_obj_t *label_CN = lv_label_create_empty(buttonCN);
|
|
|
|
lv_obj_t *label_T_CN = lv_label_create_empty(buttonT_CN);
|
|
|
|
lv_obj_t *label_EN = lv_label_create_empty(buttonEN);
|
|
|
|
lv_obj_t *label_RU = lv_label_create_empty(buttonRU);
|
|
|
|
lv_obj_t *label_ES = lv_label_create_empty(buttonES);
|
|
|
|
lv_obj_t *label_FR = lv_label_create_empty(buttonFR);
|
|
|
|
lv_obj_t *label_IT = lv_label_create_empty(buttonIT);
|
|
|
|
lv_obj_t *label_Back = lv_label_create_empty(buttonBack);
|
2020-06-16 04:05:33 +02:00
|
|
|
|
|
|
|
disp_language(gCfgItems.language, SELECTED);
|
|
|
|
|
2020-10-21 19:45:27 +02:00
|
|
|
if (gCfgItems.multiple_language) {
|
2020-06-16 04:05:33 +02:00
|
|
|
lv_label_set_text(label_CN, language_menu.chinese_s);
|
|
|
|
lv_obj_align(label_CN, buttonCN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(label_T_CN, language_menu.chinese_t);
|
|
|
|
lv_obj_align(label_T_CN, buttonT_CN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(label_EN, language_menu.english);
|
|
|
|
lv_obj_align(label_EN, buttonEN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(label_RU, language_menu.russian);
|
|
|
|
lv_obj_align(label_RU, buttonRU, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(label_ES, language_menu.spanish);
|
|
|
|
lv_obj_align(label_ES, buttonES, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(label_FR, language_menu.french);
|
|
|
|
lv_obj_align(label_FR, buttonFR, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(label_IT, language_menu.italy);
|
|
|
|
lv_obj_align(label_IT, buttonIT, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(label_Back, common_menu.text_back);
|
|
|
|
lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
}
|
2020-09-21 03:55:02 +02:00
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) {
|
|
|
|
lv_group_add_obj(g, buttonCN);
|
|
|
|
lv_group_add_obj(g, buttonT_CN);
|
|
|
|
lv_group_add_obj(g, buttonEN);
|
|
|
|
lv_group_add_obj(g, buttonRU);
|
|
|
|
lv_group_add_obj(g, buttonES);
|
|
|
|
lv_group_add_obj(g, buttonFR);
|
|
|
|
lv_group_add_obj(g, buttonIT);
|
|
|
|
lv_group_add_obj(g, buttonBack);
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-16 04:05:33 +02:00
|
|
|
}
|
|
|
|
|
2020-09-21 03:55:02 +02:00
|
|
|
void lv_clear_language() {
|
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
|
|
|
|
#endif
|
|
|
|
lv_obj_del(scr);
|
|
|
|
}
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#endif // HAS_TFT_LVGL_UI
|