@@ -307,16 +307,16 @@ CrealityDWINClass CrealityDWIN;
307307 const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
308308 const uint16_t cell_width_px = total_width_px / GRID_MAX_POINTS_X;
309309 const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
310- const float v_max = abs (get_max_value ()), v_min = abs (get_min_value ()), range = max (v_min, v_max);
310+ const float v_max = abs (get_max_value ()), v_min = abs (get_min_value ()), range = _MAX (v_min, v_max);
311311
312312 // Clear background from previous selection and select new square
313- 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);
313+ 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);
314314 if (selected >= 0 ) {
315315 const auto selected_y = selected / GRID_MAX_POINTS_X;
316316 const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
317317 const auto start_y_px = padding_y_top + selected_y * cell_height_px;
318318 const auto start_x_px = padding_x + selected_x * cell_width_px;
319- 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);
319+ 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);
320320 }
321321
322322 // Draw value square grid
@@ -326,21 +326,20 @@ CrealityDWINClass CrealityDWIN;
326326 const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width;
327327 const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1 ) * cell_height_px;
328328 const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
329- DWIN_Draw_Rectangle (1 , // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
330- isnan (mesh_z_values[x][y]) ? Color_Grey : ( // gray if undefined
329+ DWIN_Draw_Rectangle (1 , // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
330+ isnan (mesh_z_values[x][y]) ? Color_Grey : ( // gray if undefined
331331 (mesh_z_values[x][y] < 0 ?
332- (uint16_t )round (0b11111 * -mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
333- (uint16_t )round (0b111111 * mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5 ) | // green if mesh point value is positive
334- min (0b11111 , (((uint8_t )abs (mesh_z_values[x][y]) / 10 ) * 4 ))), // + blue stepping for every mm
335- start_x_px, start_y_px, end_x_px, end_y_px);
336- while (LCD_SERIAL.availableForWrite () < 32 ) { // wait for serial to be available without blocking and resetting the MCU
337- gcode.process_subcommands_now_P (" G4 P10" );
338- planner.synchronize ();
339- }
332+ (uint16_t )round (0x1F * -mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
333+ (uint16_t )round (0x3F * mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5 ) | // green if mesh point value is positive
334+ _MIN (0x1F , (((uint8_t )abs (mesh_z_values[x][y]) / 10 ) * 4 ))), // + blue stepping for every mm
335+ start_x_px, start_y_px, end_x_px, end_y_px
336+ );
337+
338+ safe_delay (10 );
339+ LCD_SERIAL.flushTX ();
340+
340341 // Draw value text on
341342 if (viewer_print_value) {
342- gcode.process_subcommands_now_P (" G4 P10" ); // still fails without additional delay...
343- planner.synchronize ();
344343 int8_t offset_x, offset_y = cell_height_px / 2 - 6 ;
345344 if (isnan (mesh_z_values[x][y])) { // undefined
346345 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;
355354 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 (" ." ));
356355 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);
357356 }
357+ safe_delay (10 );
358+ LCD_SERIAL.flushTX ();
358359 }
359360 }
360361 }
361362
362363 void Set_Mesh_Viewer_Status () { // TODO: draw gradient with values as a legend instead
363- float v_max = abs (get_max_value ()), v_min = abs (get_min_value ()), range = max (v_min, v_max);
364+ float v_max = abs (get_max_value ()), v_min = abs (get_min_value ()), range = _MAX (v_min, v_max);
364365 if (v_min > 3e+10F ) v_min = 0.0000001 ;
365366 if (v_max > 3e+10F ) v_max = 0.0000001 ;
366367 if (range > 3e+10F ) range = 0.0000001 ;
@@ -470,8 +471,8 @@ void CrealityDWINClass::Draw_Title(const char * title) {
470471
471472void CrealityDWINClass::Draw_Menu_Item (uint8_t row, uint8_t icon/* =0*/ , const char * label1, const char * label2, bool more/* =false*/ , bool centered/* =false*/ ) {
472473 const uint8_t label_offset_y = !(label1 && label2) ? 0 : MENU_CHR_H * 3 / 5 ;
473- 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 );
474- 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 );
474+ 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 );
475+ 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 );
475476 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
476477 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
477478 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
501502 last_menu = active_menu;
502503 if (process == Menu) last_selection = selection;
503504 }
504- selection = min (select, Get_Menu_Size (menu));
505+ selection = _MIN (select, Get_Menu_Size (menu));
505506 scrollpos = scroll;
506507 if (selection - scrollpos > MROWS)
507508 scrollpos = selection - MROWS;
@@ -4975,11 +4976,11 @@ void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) {
49754976void CrealityDWINClass::Save_Settings (char *buff) {
49764977 TERN_ (AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = mesh_conf.tilt_grid - 1 );
49774978 eeprom_settings.corner_pos = corner_pos * 10 ;
4978- memcpy (buff, &eeprom_settings, min (sizeof (eeprom_settings), eeprom_data_size));
4979+ memcpy (buff, &eeprom_settings, _MIN (sizeof (eeprom_settings), eeprom_data_size));
49794980}
49804981
49814982void CrealityDWINClass::Load_Settings (const char *buff) {
4982- memcpy (&eeprom_settings, buff, min (sizeof (eeprom_settings), eeprom_data_size));
4983+ memcpy (&eeprom_settings, buff, _MIN (sizeof (eeprom_settings), eeprom_data_size));
49834984 TERN_ (AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1 );
49844985 if (eeprom_settings.corner_pos == 0 ) eeprom_settings.corner_pos = 325 ;
49854986 corner_pos = eeprom_settings.corner_pos / 10 .0f ;
0 commit comments