2020-06-16 02:05:33 +00: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 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-06-16 02:05:33 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "../../../../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#if HAS_TFT_LVGL_UI
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-21 17:45:27 +00:00
|
|
|
#include "draw_ui.h"
|
|
|
|
#include <lv_conf.h>
|
2020-06-16 02:05:33 +00: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 17:45:27 +00:00
|
|
|
|
2020-06-16 02:05:33 +00:00
|
|
|
#include "../../../../module/temperature.h"
|
|
|
|
#include "../../../../gcode/queue.h"
|
2020-07-25 05:52:07 +00:00
|
|
|
#include "../../../../gcode/gcode.h"
|
2020-10-21 17:45:27 +00:00
|
|
|
#include "../../../../inc/MarlinConfig.h"
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-09-21 01:55:02 +00:00
|
|
|
extern lv_group_t * g;
|
2020-06-16 02:05:33 +00:00
|
|
|
static lv_obj_t * scr;
|
|
|
|
static lv_obj_t * fanText;
|
|
|
|
|
|
|
|
#define ID_F_ADD 1
|
|
|
|
#define ID_F_DEC 2
|
|
|
|
#define ID_F_HIGH 3
|
|
|
|
#define ID_F_MID 4
|
|
|
|
#define ID_F_OFF 5
|
|
|
|
#define ID_F_RETURN 6
|
|
|
|
|
|
|
|
static uint8_t fanSpeed;
|
|
|
|
|
|
|
|
static void event_handler(lv_obj_t * obj, lv_event_t event) {
|
|
|
|
switch (obj->mks_obj_id) {
|
|
|
|
case ID_F_ADD:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
if (fanSpeed + 1 <= 255) {
|
|
|
|
fanSpeed++;
|
2020-07-25 05:52:07 +00:00
|
|
|
ZERO(public_buf_l);
|
|
|
|
sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
|
|
|
|
gcode.process_subcommands_now(public_buf_l);
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_F_DEC:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
if (fanSpeed > 0) {
|
|
|
|
fanSpeed--;
|
2020-07-25 05:52:07 +00:00
|
|
|
ZERO(public_buf_l);
|
|
|
|
sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
|
|
|
|
gcode.process_subcommands_now(public_buf_l);
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case ID_F_HIGH:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
2020-07-25 05:52:07 +00:00
|
|
|
gcode.process_subcommands_now_P(PSTR("M106 S255"));
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_F_MID:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
2020-07-25 05:52:07 +00:00
|
|
|
gcode.process_subcommands_now_P(PSTR("M106 S127"));
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_F_OFF:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
2020-07-25 05:52:07 +00:00
|
|
|
gcode.process_subcommands_now_P(PSTR("M107"));
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_F_RETURN:
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (event == LV_EVENT_RELEASED) {
|
|
|
|
clear_cur_ui();
|
|
|
|
draw_return_ui();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_draw_fan(void) {
|
|
|
|
lv_obj_t *buttonAdd, *buttonDec, *buttonHigh, *buttonMid;
|
|
|
|
lv_obj_t *buttonOff, *buttonBack;
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#if HAS_FAN
|
|
|
|
fanSpeed = thermalManager.fan_speed[0];
|
|
|
|
#endif
|
2020-06-16 02:05:33 +00:00
|
|
|
if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FAN_UI) {
|
|
|
|
disp_state_stack._disp_index++;
|
|
|
|
disp_state_stack._disp_state[disp_state_stack._disp_index] = FAN_UI;
|
|
|
|
}
|
|
|
|
disp_state = FAN_UI;
|
|
|
|
|
|
|
|
scr = lv_obj_create(NULL, NULL);
|
|
|
|
|
|
|
|
lv_obj_set_style(scr, &tft_style_scr);
|
|
|
|
lv_scr_load(scr);
|
|
|
|
lv_obj_clean(scr);
|
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
(void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text());
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
lv_refr_now(lv_refr_get_disp_refreshing());
|
|
|
|
|
2020-09-21 00:07:59 +00:00
|
|
|
// Create an Image button
|
2020-10-23 01:22:17 +00:00
|
|
|
buttonAdd = lv_imgbtn_create(scr, "F:/bmp_Add.bin", INTERVAL_V, titleHeight, event_handler, ID_F_ADD);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW);
|
2020-09-21 00:07:59 +00:00
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
buttonDec = lv_imgbtn_create(scr, "F:/bmp_Dec.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_F_DEC);
|
|
|
|
buttonHigh = lv_imgbtn_create(scr, "F:/bmp_speed255.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_HIGH);
|
|
|
|
buttonMid = lv_imgbtn_create(scr, "F:/bmp_speed127.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_MID);
|
|
|
|
buttonOff = lv_imgbtn_create(scr, "F:/bmp_speed0.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_OFF);
|
|
|
|
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_F_RETURN);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-09-21 00:07:59 +00:00
|
|
|
// Create labels on the image buttons
|
2020-10-23 01:22:17 +00:00
|
|
|
lv_obj_t *labelAdd = lv_label_create_empty(buttonAdd);
|
|
|
|
lv_obj_t *labelDec = lv_label_create_empty(buttonDec);
|
|
|
|
lv_obj_t *labelHigh = lv_label_create_empty(buttonHigh);
|
|
|
|
lv_obj_t *labelMid = lv_label_create_empty(buttonMid);
|
|
|
|
lv_obj_t *labelOff = lv_label_create_empty(buttonOff);
|
|
|
|
lv_obj_t *label_Back = lv_label_create_empty(buttonBack);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-21 17:45:27 +00:00
|
|
|
if (gCfgItems.multiple_language) {
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_label_set_text(labelAdd, fan_menu.add);
|
|
|
|
lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(labelDec, fan_menu.dec);
|
|
|
|
lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(labelHigh, fan_menu.full);
|
|
|
|
lv_obj_align(labelHigh, buttonHigh, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(labelMid, fan_menu.half);
|
|
|
|
lv_obj_align(labelMid, buttonMid, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
|
|
|
|
|
|
|
|
lv_label_set_text(labelOff, fan_menu.off);
|
|
|
|
lv_obj_align(labelOff, buttonOff, 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 01:55:02 +00:00
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) {
|
|
|
|
lv_group_add_obj(g, buttonAdd);
|
|
|
|
lv_group_add_obj(g, buttonDec);
|
|
|
|
lv_group_add_obj(g, buttonHigh);
|
|
|
|
lv_group_add_obj(g, buttonMid);
|
|
|
|
lv_group_add_obj(g, buttonOff);
|
|
|
|
lv_group_add_obj(g, buttonBack);
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
fanText = lv_label_create_empty(scr);
|
2020-07-25 05:52:07 +00:00
|
|
|
lv_obj_set_style(fanText, &tft_style_label_rel);
|
2020-06-16 02:05:33 +00:00
|
|
|
disp_fan_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void disp_fan_value() {
|
|
|
|
char buf1[10] = {0};
|
|
|
|
public_buf_l[0] = '\0';
|
|
|
|
strcat(public_buf_l, fan_menu.state);
|
2020-07-25 05:52:07 +00:00
|
|
|
strcat_P(public_buf_l, PSTR(": "));
|
|
|
|
sprintf_P(buf1, PSTR("%3d"), thermalManager.fan_speed[0]);
|
2020-06-16 02:05:33 +00:00
|
|
|
strcat(public_buf_l, buf1);
|
|
|
|
lv_label_set_text(fanText, public_buf_l);
|
|
|
|
lv_obj_align(fanText, NULL, LV_ALIGN_CENTER, 0, -65);
|
|
|
|
}
|
|
|
|
|
2020-09-21 01:55:02 +00:00
|
|
|
void lv_clear_fan() {
|
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
|
|
|
|
#endif
|
|
|
|
lv_obj_del(scr);
|
|
|
|
}
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#endif // HAS_TFT_LVGL_UI
|