Browse Source

Apply LIMIT macro

Scott Lahteine 6 years ago
parent
commit
ed0e6afacb

+ 2
- 2
Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp View File

@@ -48,8 +48,8 @@ void Servo::detach() { ledcDetachPin(this->pin); }
48 48
 
49 49
 int Servo::read() { return this->degrees; }
50 50
 
51
-void Servo::write(int degrees) {
52
-  this->degrees = constrain(degrees, MIN_ANGLE, MAX_ANGLE);
51
+void Servo::write(int inDegrees) {
52
+  this->degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
53 53
   int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
54 54
   int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
55 55
   ledcWrite(channel, duty);

+ 1
- 1
Marlin/src/HAL/shared/servo.cpp View File

@@ -127,7 +127,7 @@ void Servo::writeMicroseconds(int value) {
127 127
   byte channel = this->servoIndex;
128 128
   if (channel < MAX_SERVOS) {  // ensure channel is valid
129 129
     // ensure pulse width is valid
130
-    value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
130
+    LIMIT(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
131 131
     value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
132 132
 
133 133
     CRITICAL_SECTION_START;

+ 4
- 4
Marlin/src/feature/bedlevel/abl/abl.cpp View File

@@ -369,10 +369,10 @@ float bilinear_z_offset(const float raw[XYZ]) {
369 369
         cy1 = CELL_INDEX(Y, current_position[Y_AXIS]),
370 370
         cx2 = CELL_INDEX(X, destination[X_AXIS]),
371 371
         cy2 = CELL_INDEX(Y, destination[Y_AXIS]);
372
-    cx1 = constrain(cx1, 0, ABL_BG_POINTS_X - 2);
373
-    cy1 = constrain(cy1, 0, ABL_BG_POINTS_Y - 2);
374
-    cx2 = constrain(cx2, 0, ABL_BG_POINTS_X - 2);
375
-    cy2 = constrain(cy2, 0, ABL_BG_POINTS_Y - 2);
372
+    LIMIT(cx1, 0, ABL_BG_POINTS_X - 2);
373
+    LIMIT(cy1, 0, ABL_BG_POINTS_Y - 2);
374
+    LIMIT(cx2, 0, ABL_BG_POINTS_X - 2);
375
+    LIMIT(cy2, 0, ABL_BG_POINTS_Y - 2);
376 376
 
377 377
     // Start and end in the same cell? No split needed.
378 378
     if (cx1 == cx2 && cy1 == cy2) {

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp View File

@@ -443,8 +443,8 @@
443 443
       int8_t cell_xi = (raw[X_AXIS] - (MESH_MIN_X)) * (1.0f / (MESH_X_DIST)),
444 444
              cell_yi = (raw[Y_AXIS] - (MESH_MIN_Y)) * (1.0f / (MESH_Y_DIST));
445 445
 
446
-      cell_xi = constrain(cell_xi, 0, (GRID_MAX_POINTS_X) - 1);
447
-      cell_yi = constrain(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1);
446
+      LIMIT(cell_xi, 0, (GRID_MAX_POINTS_X) - 1);
447
+      LIMIT(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1);
448 448
 
449 449
       const float x0 = mesh_index_to_xpos(cell_xi),   // 64 byte table lookup avoids mul+add
450 450
                   y0 = mesh_index_to_ypos(cell_yi);

+ 8
- 8
Marlin/src/gcode/bedlevel/G26.cpp View File

@@ -337,9 +337,9 @@ inline bool look_for_lines_to_connect() {
337 337
             sx = _GET_MESH_X(  i  ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
338 338
             ex = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
339 339
 
340
-            sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);
340
+            LIMIT(sx, X_MIN_POS + 1, X_MAX_POS - 1);
341 341
             sy = ey = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
342
-            ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
342
+            LIMIT(ex, X_MIN_POS + 1, X_MAX_POS - 1);
343 343
 
344 344
             if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey))
345 345
               print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
@@ -358,8 +358,8 @@ inline bool look_for_lines_to_connect() {
358 358
               ey = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
359 359
 
360 360
               sx = ex = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
361
-              sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
362
-              ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
361
+              LIMIT(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
362
+              LIMIT(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
363 363
 
364 364
               if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey))
365 365
                 print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
@@ -832,10 +832,10 @@ void GcodeSuite::G26() {
832 832
             // Check to make sure this segment is entirely on the bed, skip if not.
833 833
             if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue;
834 834
           #else                                               // not, we need to skip
835
-            rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
836
-            ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1);
837
-            xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1);
838
-            ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1);
835
+            LIMIT(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
836
+            LIMIT(ry, Y_MIN_POS + 1, Y_MAX_POS - 1);
837
+            LIMIT(xe, X_MIN_POS + 1, X_MAX_POS - 1);
838
+            LIMIT(ye, Y_MIN_POS + 1, Y_MAX_POS - 1);
839 839
           #endif
840 840
 
841 841
           print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height);

+ 2
- 2
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

@@ -318,8 +318,8 @@ G29_TYPE GcodeSuite::G29() {
318 318
           // Get nearest i / j from rx / ry
319 319
           i = (rx - bilinear_start[X_AXIS] + 0.5 * xGridSpacing) / xGridSpacing;
320 320
           j = (ry - bilinear_start[Y_AXIS] + 0.5 * yGridSpacing) / yGridSpacing;
321
-          i = constrain(i, 0, GRID_MAX_POINTS_X - 1);
322
-          j = constrain(j, 0, GRID_MAX_POINTS_Y - 1);
321
+          LIMIT(i, 0, GRID_MAX_POINTS_X - 1);
322
+          LIMIT(j, 0, GRID_MAX_POINTS_Y - 1);
323 323
         }
324 324
         if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) {
325 325
           set_bed_leveling_enabled(false);

+ 2
- 2
Marlin/src/gcode/calibrate/M48.cpp View File

@@ -163,8 +163,8 @@ void GcodeSuite::M48() {
163 163
           Y_current = Y_probe_location - (Y_PROBE_OFFSET_FROM_EXTRUDER) + sin(RADIANS(angle)) * radius;
164 164
 
165 165
           #if DISABLED(DELTA)
166
-            X_current = constrain(X_current, X_MIN_POS, X_MAX_POS);
167
-            Y_current = constrain(Y_current, Y_MIN_POS, Y_MAX_POS);
166
+            LIMIT(X_current, X_MIN_POS, X_MAX_POS);
167
+            LIMIT(Y_current, Y_MIN_POS, Y_MAX_POS);
168 168
           #else
169 169
             // If we have gone out too far, we can do a simple fix and scale the numbers
170 170
             // back in closer to the origin.

+ 2
- 3
Marlin/src/lcd/extui_malyan_lcd.cpp View File

@@ -115,9 +115,8 @@ void process_lcd_c_command(const char* command) {
115 115
   switch (command[0]) {
116 116
     case 'C': // Cope with both V1 early rev and later LCDs.
117 117
     case 'S': {
118
-      int raw_feedrate = atoi(command + 1);
119
-      feedrate_percentage = raw_feedrate * 10;
120
-      feedrate_percentage = constrain(feedrate_percentage, 10, 999);
118
+      feedrate_percentage = atoi(command + 1) * 10;
119
+      LIMIT(feedrate_percentage, 10, 999);
121 120
     } break;
122 121
     case 'T': {
123 122
       thermalManager.setTargetHotend(atoi(command + 1), 0);

+ 1
- 2
Marlin/src/lcd/menu/game/brickout.cpp View File

@@ -67,8 +67,7 @@ void reset_ball() {
67 67
 void BrickoutGame::game_screen() {
68 68
   if (game_frame()) {     // Run logic twice for finer resolution
69 69
     // Update Paddle Position
70
-    paddle_x = (int8_t)ui.encoderPosition;
71
-    paddle_x = constrain(paddle_x, 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL));
70
+    paddle_x = constrain(int8_t(ui.encoderPosition), 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL));
72 71
     ui.encoderPosition = paddle_x;
73 72
     paddle_x *= (PADDLE_VEL);
74 73
 

+ 1
- 2
Marlin/src/lcd/menu/game/invaders.cpp View File

@@ -263,8 +263,7 @@ void InvadersGame::game_screen() {
263 263
   if (ui.first_page) {
264 264
 
265 265
     // Update Cannon Position
266
-    int16_t ep = int16_t(ui.encoderPosition);
267
-    ep = constrain(ep, 0, (LCD_PIXEL_WIDTH - (CANNON_W)) / (CANNON_VEL));
266
+    int16_t ep = constrain(int16_t(ui.encoderPosition), 0, (LCD_PIXEL_WIDTH - (CANNON_W)) / (CANNON_VEL));
268 267
     ui.encoderPosition = ep;
269 268
 
270 269
     ep *= (CANNON_VEL);

+ 1
- 1
Marlin/src/lcd/menu/menu_configuration.cpp View File

@@ -70,7 +70,7 @@ static void lcd_factory_settings() {
70 70
       return;
71 71
     }
72 72
     bar_percent += (int8_t)ui.encoderPosition;
73
-    bar_percent = constrain(bar_percent, 0, 100);
73
+    LIMIT(bar_percent, 0, 100);
74 74
     ui.encoderPosition = 0;
75 75
     draw_menu_item_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
76 76
     lcd_moveto((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);

+ 1
- 1
Marlin/src/lcd/ultralcd.cpp View File

@@ -548,7 +548,7 @@ void MarlinUI::status_screen() {
548 548
     else if ((old_frm < 100 && new_frm > 100) || (old_frm > 100 && new_frm < 100))
549 549
       new_frm = 100;
550 550
 
551
-    new_frm = constrain(new_frm, 10, 999);
551
+    LIMIT(new_frm, 10, 999);
552 552
 
553 553
     if (old_frm != new_frm) {
554 554
       feedrate_percentage = new_frm;

+ 1
- 1
Marlin/src/module/planner.cpp View File

@@ -1157,7 +1157,7 @@ void Planner::recalculate() {
1157 1157
     }
1158 1158
 
1159 1159
     float t = autotemp_min + high * autotemp_factor;
1160
-    t = constrain(t, autotemp_min, autotemp_max);
1160
+    LIMIT(t, autotemp_min, autotemp_max);
1161 1161
     if (t < oldt) t = t * (1 - float(AUTOTEMP_OLDWEIGHT)) + oldt * float(AUTOTEMP_OLDWEIGHT);
1162 1162
     oldt = t;
1163 1163
     thermalManager.setTargetHotend(t, 0);

+ 3
- 3
Marlin/src/module/temperature.cpp View File

@@ -460,7 +460,7 @@ temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0
460 460
             if (cycles > 0) {
461 461
               const long max_pow = GHV(MAX_BED_POWER, PID_MAX);
462 462
               bias += (d * (t_high - t_low)) / (t_low + t_high);
463
-              bias = constrain(bias, 20, max_pow - 20);
463
+              LIMIT(bias, 20, max_pow - 20);
464 464
               d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
465 465
 
466 466
               SERIAL_ECHOPAIR(MSG_BIAS, bias, MSG_D, d, MSG_T_MIN, min, MSG_T_MAX, max);
@@ -874,7 +874,7 @@ float Temperature::get_pid_output_hotend(const uint8_t e) {
874 874
           }
875 875
         #endif // PID_EXTRUSION_SCALING
876 876
 
877
-        pid_output = constrain(pid_output, 0, PID_MAX);
877
+        LIMIT(pid_output, 0, PID_MAX);
878 878
       }
879 879
       temp_dState[ee] = temp_hotend[ee].current;
880 880
 
@@ -1070,7 +1070,7 @@ void Temperature::manage_heater() {
1070 1070
     if (filament_sensor) {
1071 1071
       meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
1072 1072
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
1073
-      meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
1073
+      LIMIT(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
1074 1074
       planner.calculate_volumetric_for_width_sensor(measurement_delay[meas_shift_index]);
1075 1075
     }
1076 1076
   #endif // FILAMENT_WIDTH_SENSOR

Loading…
Cancel
Save