Browse Source

🐛 Fix JyersUI for LPC176x (#22745)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
tome9111991 3 years ago
parent
commit
3a457c9d13
No account linked to committer's email address

+ 1
- 1
Marlin/src/HAL/LPC1768/HAL.h View File

107
     #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
107
     #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
108
   #endif
108
   #endif
109
   #if HAS_DGUS_LCD
109
   #if HAS_DGUS_LCD
110
-    #define SERIAL_GET_TX_BUFFER_FREE() MSerial0.available()
110
+    #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.available()
111
   #endif
111
   #endif
112
 #endif
112
 #endif
113
 
113
 

+ 2
- 0
Marlin/src/HAL/LPC1768/MarlinSerial.h View File

46
 
46
 
47
   void end() {}
47
   void end() {}
48
 
48
 
49
+  uint8_t availableForWrite(void) { /* flushTX(); */ return TX_BUFFER_SIZE; }
50
+
49
   #if ENABLED(EMERGENCY_PARSER)
51
   #if ENABLED(EMERGENCY_PARSER)
50
     bool recv_callback(const char c) override;
52
     bool recv_callback(const char c) override;
51
   #endif
53
   #endif

+ 22
- 21
Marlin/src/lcd/e3v2/jyersui/dwin.cpp View File

307
       const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
307
       const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
308
       const uint16_t cell_width_px  = total_width_px / GRID_MAX_POINTS_X;
308
       const uint16_t cell_width_px  = total_width_px / GRID_MAX_POINTS_X;
309
       const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
309
       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);
311
 
311
 
312
       // Clear background from previous selection and select new square
312
       // 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);
314
       if (selected >= 0) {
314
       if (selected >= 0) {
315
         const auto selected_y = selected / GRID_MAX_POINTS_X;
315
         const auto selected_y = selected / GRID_MAX_POINTS_X;
316
         const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
316
         const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
317
         const auto start_y_px = padding_y_top + selected_y * cell_height_px;
317
         const auto start_y_px = padding_y_top + selected_y * cell_height_px;
318
         const auto start_x_px = padding_x + selected_x * cell_width_px;
318
         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);
320
       }
320
       }
321
 
321
 
322
       // Draw value square grid
322
       // Draw value square grid
326
         const auto end_x_px   = start_x_px + cell_width_px - 1 - gridline_width;
326
         const auto end_x_px   = start_x_px + cell_width_px - 1 - gridline_width;
327
         const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
327
         const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
328
         const auto end_y_px   = start_y_px + cell_height_px - 1 - gridline_width;
328
         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
331
             (mesh_z_values[x][y] < 0 ?
331
             (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
+
340
         // Draw value text on
341
         // Draw value text on
341
         if (viewer_print_value) {
342
         if (viewer_print_value) {
342
-          gcode.process_subcommands_now_P("G4 P10");  // still fails without additional delay...
343
-          planner.synchronize();
344
           int8_t offset_x, offset_y = cell_height_px / 2 - 6;
343
           int8_t offset_x, offset_y = cell_height_px / 2 - 6;
345
           if (isnan(mesh_z_values[x][y])) {  // undefined
344
           if (isnan(mesh_z_values[x][y])) {  // undefined
346
             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"));
345
             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
               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("."));
354
               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("."));
356
             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);
355
             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);
357
           }
356
           }
357
+          safe_delay(10);
358
+          LCD_SERIAL.flushTX();
358
         }
359
         }
359
       }
360
       }
360
     }
361
     }
361
 
362
 
362
     void Set_Mesh_Viewer_Status() { // TODO: draw gradient with values as a legend instead
363
     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);
364
       if (v_min > 3e+10F) v_min = 0.0000001;
365
       if (v_min > 3e+10F) v_min = 0.0000001;
365
       if (v_max > 3e+10F) v_max = 0.0000001;
366
       if (v_max > 3e+10F) v_max = 0.0000001;
366
       if (range > 3e+10F) range = 0.0000001;
367
       if (range > 3e+10F) range = 0.0000001;
470
 
471
 
471
 void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, const char * label1, const char * label2, bool more/*=false*/, bool centered/*=false*/) {
472
 void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, const char * label1, const char * label2, bool more/*=false*/, bool centered/*=false*/) {
472
   const uint8_t label_offset_y = !(label1 && label2) ? 0 : MENU_CHR_H * 3 / 5;
473
   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);
475
   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
476
   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
476
   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
477
   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
477
   if (icon) DWIN_ICON_Show(ICON, icon, 26, MBASE(row) - 3);   //Draw Menu Icon
478
   if (icon) DWIN_ICON_Show(ICON, icon, 26, MBASE(row) - 3);   //Draw Menu Icon
501
     last_menu = active_menu;
502
     last_menu = active_menu;
502
     if (process == Menu) last_selection = selection;
503
     if (process == Menu) last_selection = selection;
503
   }
504
   }
504
-  selection = min(select, Get_Menu_Size(menu));
505
+  selection = _MIN(select, Get_Menu_Size(menu));
505
   scrollpos = scroll;
506
   scrollpos = scroll;
506
   if (selection - scrollpos > MROWS)
507
   if (selection - scrollpos > MROWS)
507
     scrollpos = selection - MROWS;
508
     scrollpos = selection - MROWS;
4975
 void CrealityDWINClass::Save_Settings(char *buff) {
4976
 void CrealityDWINClass::Save_Settings(char *buff) {
4976
   TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = mesh_conf.tilt_grid - 1);
4977
   TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = mesh_conf.tilt_grid - 1);
4977
   eeprom_settings.corner_pos = corner_pos * 10;
4978
   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));
4979
 }
4980
 }
4980
 
4981
 
4981
 void CrealityDWINClass::Load_Settings(const char *buff) {
4982
 void 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));
4983
   TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
4984
   TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
4984
   if (eeprom_settings.corner_pos == 0) eeprom_settings.corner_pos = 325;
4985
   if (eeprom_settings.corner_pos == 0) eeprom_settings.corner_pos = 325;
4985
   corner_pos = eeprom_settings.corner_pos / 10.0f;
4986
   corner_pos = eeprom_settings.corner_pos / 10.0f;

+ 1
- 1
Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp View File

92
   #endif
92
   #endif
93
   LCD_SERIAL.begin(LCD_BAUDRATE);
93
   LCD_SERIAL.begin(LCD_BAUDRATE);
94
   const millis_t serial_connect_timeout = millis() + 1000UL;
94
   const millis_t serial_connect_timeout = millis() + 1000UL;
95
-  while (!LCD_SERIAL && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
95
+  while (!LCD_SERIAL.connected() && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
96
 
96
 
97
   size_t i = 0;
97
   size_t i = 0;
98
   DWIN_Byte(i, 0x00);
98
   DWIN_Byte(i, 0x00);

Loading…
Cancel
Save