From 3a457c9d13701428a4a276aaf43eb7961e9503a1 Mon Sep 17 00:00:00 2001 From: tome9111991 <57866234+tome9111991@users.noreply.github.com> Date: Sun, 12 Sep 2021 21:56:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20JyersUI=20for=20LPC176x=20?= =?UTF-8?q?(#22745)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/src/HAL/LPC1768/HAL.h | 2 +- Marlin/src/HAL/LPC1768/MarlinSerial.h | 2 ++ Marlin/src/lcd/e3v2/jyersui/dwin.cpp | 43 ++++++++++++------------ Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index fc2fc57378..ca4e2decab 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -107,7 +107,7 @@ extern DefaultSerial1 USBSerial; #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB." #endif #if HAS_DGUS_LCD - #define SERIAL_GET_TX_BUFFER_FREE() MSerial0.available() + #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.available() #endif #endif diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.h b/Marlin/src/HAL/LPC1768/MarlinSerial.h index 808d19f8c5..3e6848a1e3 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.h +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.h @@ -46,6 +46,8 @@ public: void end() {} + uint8_t availableForWrite(void) { /* flushTX(); */ return TX_BUFFER_SIZE; } + #if ENABLED(EMERGENCY_PARSER) bool recv_callback(const char c) override; #endif diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index 6f76fe3d32..c02aa48b1a 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -307,16 +307,16 @@ CrealityDWINClass CrealityDWIN; const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x; const uint16_t cell_width_px = total_width_px / GRID_MAX_POINTS_X; const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y; - const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = max(v_min, v_max); + const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max); // Clear background from previous selection and select new square - DWIN_Draw_Rectangle(1, Color_Bg_Black, max(0, padding_x - gridline_width), max(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px); + DWIN_Draw_Rectangle(1, Color_Bg_Black, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px); if (selected >= 0) { const auto selected_y = selected / GRID_MAX_POINTS_X; const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y); const auto start_y_px = padding_y_top + selected_y * cell_height_px; const auto start_x_px = padding_x + selected_x * cell_width_px; - DWIN_Draw_Rectangle(1, Color_White, max(0, start_x_px - gridline_width), max(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px); + DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px); } // Draw value square grid @@ -326,21 +326,20 @@ CrealityDWINClass CrealityDWIN; const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width; const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px; const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width; - DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/ - isnan(mesh_z_values[x][y]) ? Color_Grey : ( // gray if undefined + DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/ + isnan(mesh_z_values[x][y]) ? Color_Grey : ( // gray if undefined (mesh_z_values[x][y] < 0 ? - (uint16_t)round(0b11111 * -mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative - (uint16_t)round(0b111111 * mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive - min(0b11111, (((uint8_t)abs(mesh_z_values[x][y]) / 10) * 4))), // + blue stepping for every mm - start_x_px, start_y_px, end_x_px, end_y_px); - while (LCD_SERIAL.availableForWrite() < 32) { // wait for serial to be available without blocking and resetting the MCU - gcode.process_subcommands_now_P("G4 P10"); - planner.synchronize(); - } + (uint16_t)round(0x1F * -mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative + (uint16_t)round(0x3F * mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive + _MIN(0x1F, (((uint8_t)abs(mesh_z_values[x][y]) / 10) * 4))), // + blue stepping for every mm + start_x_px, start_y_px, end_x_px, end_y_px + ); + + safe_delay(10); + LCD_SERIAL.flushTX(); + // Draw value text on if (viewer_print_value) { - gcode.process_subcommands_now_P("G4 P10"); // still fails without additional delay... - planner.synchronize(); int8_t offset_x, offset_y = cell_height_px / 2 - 6; if (isnan(mesh_z_values[x][y])) { // undefined DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X")); @@ -355,12 +354,14 @@ CrealityDWINClass CrealityDWIN; DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F(".")); DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px + 1 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, buf); } + safe_delay(10); + LCD_SERIAL.flushTX(); } } } void Set_Mesh_Viewer_Status() { // TODO: draw gradient with values as a legend instead - float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = max(v_min, v_max); + float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max); if (v_min > 3e+10F) v_min = 0.0000001; if (v_max > 3e+10F) v_max = 0.0000001; if (range > 3e+10F) range = 0.0000001; @@ -470,8 +471,8 @@ void CrealityDWINClass::Draw_Title(const char * title) { void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, const char * label1, const char * label2, bool more/*=false*/, bool centered/*=false*/) { const uint8_t label_offset_y = !(label1 && label2) ? 0 : MENU_CHR_H * 3 / 5; - const uint8_t label1_offset_x = !centered ? LBLX : LBLX * 4/5 + max(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label1 ? strlen(label1) : 0) * MENU_CHR_W) / 2); - const uint8_t label2_offset_x = !centered ? LBLX : LBLX * 4/5 + max(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label2 ? strlen(label2) : 0) * MENU_CHR_W) / 2); + const uint8_t label1_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label1 ? strlen(label1) : 0) * MENU_CHR_W) / 2); + const uint8_t label2_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label2 ? strlen(label2) : 0) * MENU_CHR_W) / 2); if (label1) DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label1_offset_x, MBASE(row) - 1 - label_offset_y, label1); // Draw Label if (label2) DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label2_offset_x, MBASE(row) - 1 + label_offset_y, label2); // Draw Label if (icon) DWIN_ICON_Show(ICON, icon, 26, MBASE(row) - 3); //Draw Menu Icon @@ -501,7 +502,7 @@ void CrealityDWINClass::Draw_Menu(uint8_t menu, uint8_t select/*=0*/, uint8_t sc last_menu = active_menu; if (process == Menu) last_selection = selection; } - selection = min(select, Get_Menu_Size(menu)); + selection = _MIN(select, Get_Menu_Size(menu)); scrollpos = scroll; if (selection - scrollpos > MROWS) scrollpos = selection - MROWS; @@ -4975,11 +4976,11 @@ void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) { void CrealityDWINClass::Save_Settings(char *buff) { TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = mesh_conf.tilt_grid - 1); eeprom_settings.corner_pos = corner_pos * 10; - memcpy(buff, &eeprom_settings, min(sizeof(eeprom_settings), eeprom_data_size)); + memcpy(buff, &eeprom_settings, _MIN(sizeof(eeprom_settings), eeprom_data_size)); } void CrealityDWINClass::Load_Settings(const char *buff) { - memcpy(&eeprom_settings, buff, min(sizeof(eeprom_settings), eeprom_data_size)); + memcpy(&eeprom_settings, buff, _MIN(sizeof(eeprom_settings), eeprom_data_size)); TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1); if (eeprom_settings.corner_pos == 0) eeprom_settings.corner_pos = 325; corner_pos = eeprom_settings.corner_pos / 10.0f; diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp index 5380d1b93e..92f4be4548 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp @@ -92,7 +92,7 @@ bool DWIN_Handshake(void) { #endif LCD_SERIAL.begin(LCD_BAUDRATE); const millis_t serial_connect_timeout = millis() + 1000UL; - while (!LCD_SERIAL && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + while (!LCD_SERIAL.connected() && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } size_t i = 0; DWIN_Byte(i, 0x00);