Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MKS LVGL UI bug fix and add #22783

Merged
merged 21 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -56,9 +56,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 @@ -54,7 +54,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 @@ -123,9 +123,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 @@ -43,9 +43,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 @@ -55,14 +57,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 @@ -77,7 +80,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 @@ -51,7 +51,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 @@ -114,9 +115,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 @@ -29,7 +29,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 @@ -58,7 +58,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 @@ -68,17 +68,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 @@ -66,10 +66,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