Browse Source

Optimize handling of block_buffer_runtime()

millis_t is long - divisions take for ever.

Return a kind of millisecond instead of microsecond -
divided by 1024 instead of 1000 for speed. (2.4% error)

That does not matter because block_buffer_runtime is
already a too short estimation.
Shrink the return-type.
AnHardt 7 years ago
parent
commit
292eb365c6
2 changed files with 12 additions and 5 deletions
  1. 7
    1
      Marlin/planner.h
  2. 5
    4
      Marlin/ultralcd.cpp

+ 7
- 1
Marlin/planner.h View File

@@ -395,10 +395,16 @@ class Planner {
395 395
 
396 396
     #if ENABLED(ULTRA_LCD)
397 397
 
398
-      static millis_t block_buffer_runtime() {
398
+      static uint16_t block_buffer_runtime() {
399 399
         CRITICAL_SECTION_START
400 400
           millis_t bbru = block_buffer_runtime_us;
401 401
         CRITICAL_SECTION_END
402
+        // To translate µs to ms a division by 1000 would be required.
403
+        // We introduce 2.4% error here by dividing by 1024.
404
+        // Doesn't matter because block_buffer_runtime_us is already too small an estimation.
405
+        bbru >>= 10;
406
+        // limit to about a minute.
407
+        NOMORE(bbru, 0xfffful);
402 408
         return bbru;
403 409
       }
404 410
 

+ 5
- 4
Marlin/ultralcd.cpp View File

@@ -64,7 +64,7 @@ void lcd_status_screen();
64 64
 millis_t next_lcd_update_ms;
65 65
 
66 66
 uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
67
-millis_t max_display_update_time = 0;
67
+uint16_t max_display_update_time = 0;
68 68
 
69 69
 #if ENABLED(DOGLCD)
70 70
   bool drawing_screen = false;
@@ -2978,12 +2978,13 @@ void lcd_update() {
2978 2978
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2979 2979
     }
2980 2980
 
2981
-    millis_t bbr = planner.block_buffer_runtime();
2981
+    // then we want to use 1/2 of the time only.
2982
+    uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
2982 2983
 
2983 2984
     #if ENABLED(DOGLCD)
2984
-      if ((lcdDrawUpdate || drawing_screen) && (!bbr || (bbr > 2 * max_display_update_time * 1000)))
2985
+      if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
2985 2986
     #else
2986
-      if (lcdDrawUpdate && (!bbr || (bbr > 2 * max_display_update_time * 1000)))
2987
+      if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
2987 2988
     #endif
2988 2989
     {
2989 2990
       #if ENABLED(DOGLCD)

Loading…
Cancel
Save