瀏覽代碼

Use provided 'constrain'

Scott Lahteine 5 年之前
父節點
當前提交
712aaa26d5
共有 1 個檔案被更改,包括 21 行新增25 行删除
  1. 21
    25
      Marlin/src/lcd/extensible_ui/ui_api.cpp

+ 21
- 25
Marlin/src/lcd/extensible_ui/ui_api.cpp 查看文件

@@ -102,10 +102,6 @@
102 102
   #include "../../feature/host_actions.h"
103 103
 #endif
104 104
 
105
-inline float clamp(const float value, const float minimum, const float maximum) {
106
-  return _MAX(_MIN(value, maximum), minimum);
107
-}
108
-
109 105
 static struct {
110 106
   uint8_t printer_killed  : 1;
111 107
   uint8_t manual_motion : 1;
@@ -339,7 +335,7 @@ namespace ExtUI {
339 335
     setFeedrate_mm_s(MMM_TO_MMS(max_manual_feedrate[axis]));
340 336
 
341 337
     if (!flags.manual_motion) set_destination_from_current();
342
-    destination[axis] = clamp(position, min, max);
338
+    destination[axis] = constrain(position, min, max);
343 339
     flags.manual_motion = true;
344 340
   }
345 341
 
@@ -474,13 +470,13 @@ namespace ExtUI {
474 470
     void  setAxisCurrent_mA(const float mA, const axis_t axis) {
475 471
       switch (axis) {
476 472
         #if AXIS_IS_TMC(X)
477
-          case X: stepperX.rms_current(clamp(mA, 500, 1500)); break;
473
+          case X: stepperX.rms_current(constrain(mA, 500, 1500)); break;
478 474
         #endif
479 475
         #if AXIS_IS_TMC(Y)
480
-          case Y: stepperY.rms_current(clamp(mA, 500, 1500)); break;
476
+          case Y: stepperY.rms_current(constrain(mA, 500, 1500)); break;
481 477
         #endif
482 478
         #if AXIS_IS_TMC(Z)
483
-          case Z: stepperZ.rms_current(clamp(mA, 500, 1500)); break;
479
+          case Z: stepperZ.rms_current(constrain(mA, 500, 1500)); break;
484 480
         #endif
485 481
         default: break;
486 482
       };
@@ -489,22 +485,22 @@ namespace ExtUI {
489 485
     void  setAxisCurrent_mA(const float mA, const extruder_t extruder) {
490 486
       switch (extruder) {
491 487
         #if AXIS_IS_TMC(E0)
492
-          case E0: stepperE0.rms_current(clamp(mA, 500, 1500)); break;
488
+          case E0: stepperE0.rms_current(constrain(mA, 500, 1500)); break;
493 489
         #endif
494 490
         #if AXIS_IS_TMC(E1)
495
-          case E1: stepperE1.rms_current(clamp(mA, 500, 1500)); break;
491
+          case E1: stepperE1.rms_current(constrain(mA, 500, 1500)); break;
496 492
         #endif
497 493
         #if AXIS_IS_TMC(E2)
498
-          case E2: stepperE2.rms_current(clamp(mA, 500, 1500)); break;
494
+          case E2: stepperE2.rms_current(constrain(mA, 500, 1500)); break;
499 495
         #endif
500 496
         #if AXIS_IS_TMC(E3)
501
-          case E3: stepperE3.rms_current(clamp(mA, 500, 1500)); break;
497
+          case E3: stepperE3.rms_current(constrain(mA, 500, 1500)); break;
502 498
         #endif
503 499
         #if AXIS_IS_TMC(E4)
504
-          case E4: stepperE4.rms_current(clamp(mA, 500, 1500)); break;
500
+          case E4: stepperE4.rms_current(constrain(mA, 500, 1500)); break;
505 501
         #endif
506 502
         #if AXIS_IS_TMC(E5)
507
-          case E5: stepperE5.rms_current(clamp(mA, 500, 1500)); break;
503
+          case E5: stepperE5.rms_current(constrain(mA, 500, 1500)); break;
508 504
         #endif
509 505
         default: break;
510 506
       };
@@ -607,7 +603,7 @@ namespace ExtUI {
607 603
 
608 604
     #ifdef FILAMENT_RUNOUT_DISTANCE_MM
609 605
       float getFilamentRunoutDistance_mm()                 { return runout.runout_distance(); }
610
-      void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(clamp(value, 0, 999)); }
606
+      void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(constrain(value, 0, 999)); }
611 607
     #endif
612 608
   #endif
613 609
 
@@ -618,7 +614,7 @@ namespace ExtUI {
618 614
 
619 615
     void setLinearAdvance_mm_mm_s(const float value, const extruder_t extruder) {
620 616
       if (extruder < EXTRUDERS)
621
-        planner.extruder_advance_K[extruder - E0] = clamp(value, 0, 999);
617
+        planner.extruder_advance_K[extruder - E0] = constrain(value, 0, 999);
622 618
     }
623 619
   #endif
624 620
 
@@ -629,7 +625,7 @@ namespace ExtUI {
629 625
     }
630 626
 
631 627
     void setJunctionDeviation_mm(const float value) {
632
-      planner.junction_deviation_mm = clamp(value, 0.01, 0.3);
628
+      planner.junction_deviation_mm = constrain(value, 0.01, 0.3);
633 629
       #if ENABLED(LIN_ADVANCE)
634 630
         planner.recalculate_max_e_jerk();
635 631
       #endif
@@ -784,14 +780,14 @@ namespace ExtUI {
784 780
   #if ENABLED(BACKLASH_GCODE)
785 781
     float getAxisBacklash_mm(const axis_t axis)       { return backlash.distance_mm[axis]; }
786 782
     void setAxisBacklash_mm(const float value, const axis_t axis)
787
-                                                      { backlash.distance_mm[axis] = clamp(value,0,5); }
783
+                                                      { backlash.distance_mm[axis] = constrain(value,0,5); }
788 784
 
789 785
     float getBacklashCorrection_percent()             { return ui8_to_percent(backlash.correction); }
790
-    void setBacklashCorrection_percent(const float value) { backlash.correction = map(clamp(value, 0, 100), 0, 100, 0, 255); }
786
+    void setBacklashCorrection_percent(const float value) { backlash.correction = map(constrain(value, 0, 100), 0, 100, 0, 255); }
791 787
 
792 788
     #ifdef BACKLASH_SMOOTHING_MM
793 789
       float getBacklashSmoothing_mm()                 { return backlash.smoothing_mm; }
794
-      void setBacklashSmoothing_mm(const float value) { backlash.smoothing_mm = clamp(value, 0, 999); }
790
+      void setBacklashSmoothing_mm(const float value) { backlash.smoothing_mm = constrain(value, 0, 999); }
795 791
     #endif
796 792
   #endif
797 793
 
@@ -869,14 +865,14 @@ namespace ExtUI {
869 865
     enableHeater(heater);
870 866
     #if HAS_HEATED_BED
871 867
       if (heater == BED)
872
-        thermalManager.setTargetBed(clamp(value, 0, BED_MAXTEMP - 10));
868
+        thermalManager.setTargetBed(constrain(value, 0, BED_MAXTEMP - 10));
873 869
       else
874 870
     #endif
875 871
       {
876 872
         #if HOTENDS
877 873
           static constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
878 874
           const int16_t e = heater - H0;
879
-          thermalManager.setTargetHotend(clamp(value, 0, heater_maxtemp[e] - 15), e);
875
+          thermalManager.setTargetHotend(constrain(value, 0, heater_maxtemp[e] - 15), e);
880 876
         #endif
881 877
       }
882 878
   }
@@ -886,14 +882,14 @@ namespace ExtUI {
886 882
       constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
887 883
       const int16_t e = extruder - E0;
888 884
       enableHeater(extruder);
889
-      thermalManager.setTargetHotend(clamp(value, 0, heater_maxtemp[e] - 15), e);
885
+      thermalManager.setTargetHotend(constrain(value, 0, heater_maxtemp[e] - 15), e);
890 886
     #endif
891 887
   }
892 888
 
893 889
   void setTargetFan_percent(const float value, const fan_t fan) {
894 890
     #if FAN_COUNT > 0
895 891
       if (fan < FAN_COUNT)
896
-        thermalManager.set_fan_speed(fan - FAN0, map(clamp(value, 0, 100), 0, 100, 0, 255));
892
+        thermalManager.set_fan_speed(fan - FAN0, map(constrain(value, 0, 100), 0, 100, 0, 255));
897 893
     #else
898 894
       UNUSED(value);
899 895
       UNUSED(fan);
@@ -901,7 +897,7 @@ namespace ExtUI {
901 897
   }
902 898
 
903 899
   void setFeedrate_percent(const float value) {
904
-    feedrate_percentage = clamp(value, 10, 500);
900
+    feedrate_percentage = constrain(value, 10, 500);
905 901
   }
906 902
 
907 903
   void setUserConfirmed() {

Loading…
取消
儲存