Skip to content

Commit

Permalink
🚸 Fix and improve MKS LVGL UI (#22783)
Browse files Browse the repository at this point in the history
Co-authored-by: makerbase <[email protected]>
Co-authored-by: MKS-Sean <[email protected]>
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
4 people authored Sep 16, 2021
1 parent 323b38e commit 8df3e62
Show file tree
Hide file tree
Showing 38 changed files with 321 additions and 284 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/SPIFlashStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ uint32_t SPIFlashStorage::m_startAddress;
static uint32_t rle_compress(T *output, uint32_t outputLength, T *input, uint32_t inputLength, uint32_t& inputProcessed) {
uint32_t count = 0, out = 0, index, i;
T pixel;
//32767 for uint16_t
//127 for uint16_t
//calculated at compile time
// 32767 for uint16_t
// 127 for uint16_t
// calculated at compile time
constexpr T max = (0xFFFFFFFF >> (8 * (4 - sizeof(T)))) / 2;

inputProcessed = 0;
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/SPI_TFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ void TFT::LCD_init() {
}

void TFT::LCD_clear(uint16_t color) {
setWindow(0, 0, (TFT_WIDTH), (TFT_HEIGHT));
tftio.WriteMultiple(color, (uint32_t)(TFT_WIDTH) * (TFT_HEIGHT));
setWindow(0, 0, TFT_WIDTH, TFT_HEIGHT);
tftio.WriteMultiple(color, uint32_t(TFT_WIDTH) * uint32_t(TFT_HEIGHT));
}

void TFT::LCD_Draw_Logo() {
#if HAS_LOGO_IN_FLASH
setWindow(0, 0, TFT_WIDTH, TFT_HEIGHT);
for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) {
for (uint16_t i = 0; i < (TFT_HEIGHT); i++) {
Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2);
tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH);
}
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/draw_advance_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
break;
#if ENABLED(MKS_WIFI_MODULE)
case ID_WIFI_PARA:
lv_clear_advance_settings();
lv_draw_wifi_settings();
break;
lv_clear_advance_settings();
lv_draw_wifi_settings();
break;
#endif
#if HAS_ROTARY_ENCODER
case ID_ENCODER_SETTINGS:
Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/draw_baby_stepping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum {
ID_BABY_STEP_RETURN
};

static float babystep_dist=0.01;
static float babystep_dist = 0.01;
static uint8_t has_adjust_z = 0;

static void event_handler(lv_obj_t *obj, lv_event_t event) {
Expand Down Expand Up @@ -124,9 +124,8 @@ void lv_draw_baby_stepping() {
buttonV = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_BABY_STEP_DIST);
labelV = lv_label_create_empty(buttonV);
#if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) {
if (gCfgItems.encoder_enable)
lv_group_add_obj(g, buttonV);
}
#endif

lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_RETURN);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/mks_ui/draw_cloud_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#pragma once

#ifdef __cplusplus
extern "C" { /* C-declarations for C++ */
extern "C" { /* C-declarations for C++ */
#endif

void lv_draw_cloud_bind();
Expand Down
26 changes: 12 additions & 14 deletions Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
if (card.isFileOpen()) {
feedrate_percentage = 100;
planner.flow_percentage[0] = 100;
planner.e_factor[0] = planner.flow_percentage[0] * 0.01f;
planner.e_factor[0] = planner.flow_percentage[0] * 0.01f;
#if HAS_MULTI_EXTRUDER
planner.flow_percentage[1] = 100;
planner.e_factor[1] = planner.flow_percentage[1] * 0.01f;
planner.e_factor[1] = planner.flow_percentage[1] * 0.01f;
#endif
card.startOrResumeFilePrinting();
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.prepare();
#endif
TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
once_flag = false;
}
}
Expand Down Expand Up @@ -229,14 +227,14 @@ void lv_draw_dialog(uint8_t type) {
lv_obj_t *labelDialog = lv_label_create(scr, "");

if (DIALOG_IS(TYPE_FINISH_PRINT, PAUSE_MESSAGE_RESUME)) {
btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb);
lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button
lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb);
lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button
lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
}
else if (DIALOG_IS(PAUSE_MESSAGE_WAITING, PAUSE_MESSAGE_INSERT, PAUSE_MESSAGE_HEAT)) {
btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb);
lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button
lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button
lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
}
else if (DIALOG_IS(PAUSE_MESSAGE_PARKING, PAUSE_MESSAGE_CHANGING, PAUSE_MESSAGE_UNLOAD, PAUSE_MESSAGE_LOAD, PAUSE_MESSAGE_PURGE, PAUSE_MESSAGE_RESUME, PAUSE_MESSAGE_HEATING)) {
// nothing to do
Expand Down Expand Up @@ -269,7 +267,7 @@ void lv_draw_dialog(uint8_t type) {
}
#endif
else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT)) {
btnCancel = lv_button_btn_create(scr, BTN_OK_X+90, BTN_OK_Y, 100, 50, btn_cancel_event_cb);
btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb);
lv_obj_t *labelCancel = lv_label_create_empty(btnCancel);
lv_label_set_text(labelCancel, print_file_dialog_menu.cancel);

Expand All @@ -287,7 +285,7 @@ void lv_draw_dialog(uint8_t type) {
lv_label_set_text(labelCancel, print_file_dialog_menu.cancel);

filament_bar = lv_bar_create(scr, nullptr);
lv_obj_set_pos(filament_bar, (TFT_WIDTH-400)/2, ((TFT_HEIGHT - titleHeight)-40)/2);
lv_obj_set_pos(filament_bar, (TFT_WIDTH - 400) / 2, ((TFT_HEIGHT - titleHeight) - 40) / 2);
lv_obj_set_size(filament_bar, 400, 25);
lv_bar_set_style(filament_bar, LV_BAR_STYLE_INDIC, &lv_bar_style_indic);
lv_bar_set_anim_time(filament_bar, 1000);
Expand All @@ -301,11 +299,11 @@ void lv_draw_dialog(uint8_t type) {
lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); // Add a label to the button

if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) {
lv_label_set_text(labelOk, pause_msg_menu.purgeMore); // Set the labels text
lv_label_set_text(labelOk, pause_msg_menu.purgeMore); // Set the labels text
lv_label_set_text(labelCancel, pause_msg_menu.continuePrint);
}
else {
lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
lv_label_set_text(labelCancel, print_file_dialog_menu.cancel);
}
}
Expand Down
9 changes: 6 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/draw_fan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ enum {
ID_F_RETURN
};

uint8_t fanPercent = 0;
static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
uint8_t fanPercent = map(thermalManager.fan_speed[0], 0, 255, 0, 100);
const uint8_t temp = map(thermalManager.fan_speed[0], 0, 255, 0, 100);
if (abs(fanPercent - temp) > 2) fanPercent = temp;
switch (obj->mks_obj_id) {
case ID_F_ADD: if (fanPercent < 100) fanPercent++; break;
case ID_F_DEC: if (fanPercent != 0) fanPercent--; break;
Expand All @@ -56,14 +58,15 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_F_RETURN: clear_cur_ui(); draw_return_ui(); return;
}
thermalManager.set_fan_speed(0, map(fanPercent, 0, 100, 0, 255));
if (obj->mks_obj_id != ID_F_RETURN) disp_fan_value();
}

void lv_draw_fan() {
lv_obj_t *buttonAdd;

scr = lv_screen_create(FAN_UI);
// Create an Image button
buttonAdd = lv_big_button_create(scr, "F:/bmp_Add.bin", fan_menu.add, INTERVAL_V, titleHeight, event_handler, ID_F_ADD);
buttonAdd = lv_big_button_create(scr, "F:/bmp_Add.bin", fan_menu.add, INTERVAL_V, titleHeight, event_handler, ID_F_ADD);
lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW);
lv_big_button_create(scr, "F:/bmp_Dec.bin", fan_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_F_DEC);
lv_big_button_create(scr, "F:/bmp_speed255.bin", fan_menu.full, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_HIGH);
Expand All @@ -78,7 +81,7 @@ void lv_draw_fan() {

void disp_fan_value() {
#if HAS_FAN
sprintf_P(public_buf_l, PSTR("%s: %3d%%"), fan_menu.state, (int)map(thermalManager.fan_speed[0], 0, 255, 0, 100));
sprintf_P(public_buf_l, PSTR("%s: %3d%%"), fan_menu.state, fanPercent);
#else
sprintf_P(public_buf_l, PSTR("%s: ---"), fan_menu.state);
#endif
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/draw_filament_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_FILAMNT_IN:
uiCfg.filament_load_heat_flg = true;
if (ABS(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.wholeDegHotend(uiCfg.extruderIndex)) <= 1
|| gCfgItems.filament_limit_temp <= thermalManager.wholeDegHotend(uiCfg.extruderIndex)) {
|| gCfgItems.filament_limit_temp <= thermalManager.wholeDegHotend(uiCfg.extruderIndex)
) {
lv_clear_filament_change();
lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED);
}
Expand Down Expand Up @@ -115,9 +116,8 @@ void lv_draw_filament_change() {

buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_TYPE);
#if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) {
if (gCfgItems.encoder_enable)
lv_group_add_obj(g, buttonType);
}
#endif

lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_RETURN);
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/lcd/extui/mks_ui/draw_gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "../../../inc/MarlinConfig.h"

extern lv_group_t *g;
static lv_obj_t *scr,*outL,*outV = 0;
static lv_obj_t *scr, *outL, *outV = 0;
static int currentWritePos = 0;
extern uint8_t public_buf[513];
extern "C" { extern char public_buf_m[100]; }
Expand Down Expand Up @@ -59,7 +59,7 @@ void lv_show_gcode_output(void * that, const char * txt) {
if (!memcmp(txt, "echo:", 5)) {
public_buf[0] = 0; // Clear output buffer
return;
}
}

// Avoid overflow if the answer is too large
size_t len = strlen((const char*)public_buf), tlen = strlen(txt);
Expand All @@ -69,17 +69,17 @@ void lv_show_gcode_output(void * that, const char * txt) {
}
}

void lv_serial_capt_hook(void * userPointer, uint8_t c)
{
void lv_serial_capt_hook(void * userPointer, uint8_t c) {
if (c == '\n' || currentWritePos == sizeof(public_buf_m) - 1) { // End of line, probably end of command anyway
public_buf_m[currentWritePos] = 0;
lv_show_gcode_output(userPointer, public_buf_m);
currentWritePos = 0;
}
else public_buf_m[currentWritePos++] = c;
else
public_buf_m[currentWritePos++] = c;
}
void lv_eom_hook(void *)
{

void lv_eom_hook(void *) {
// Message is done, let's remove the hook now
MYSERIAL1.setHook();
// We are back from the keyboard, so let's redraw ourselves
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
break;
#if Z2_SENSORLESS
case ID_SENSITIVITY_Z2:
value = z2_sensitivity;
lv_clear_homing_sensitivity_settings();
lv_draw_number_key();
break;
value = z2_sensitivity;
lv_clear_homing_sensitivity_settings();
lv_draw_number_key();
break;
#endif
}
}
Expand Down
Loading

0 comments on commit 8df3e62

Please sign in to comment.