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
 
48
 
49
 int Servo::read() { return this->degrees; }
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
   int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
53
   int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
54
   int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
54
   int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
55
   ledcWrite(channel, duty);
55
   ledcWrite(channel, duty);

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

127
   byte channel = this->servoIndex;
127
   byte channel = this->servoIndex;
128
   if (channel < MAX_SERVOS) {  // ensure channel is valid
128
   if (channel < MAX_SERVOS) {  // ensure channel is valid
129
     // ensure pulse width is valid
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
     value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
131
     value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
132
 
132
 
133
     CRITICAL_SECTION_START;
133
     CRITICAL_SECTION_START;

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

369
         cy1 = CELL_INDEX(Y, current_position[Y_AXIS]),
369
         cy1 = CELL_INDEX(Y, current_position[Y_AXIS]),
370
         cx2 = CELL_INDEX(X, destination[X_AXIS]),
370
         cx2 = CELL_INDEX(X, destination[X_AXIS]),
371
         cy2 = CELL_INDEX(Y, destination[Y_AXIS]);
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
     // Start and end in the same cell? No split needed.
377
     // Start and end in the same cell? No split needed.
378
     if (cx1 == cx2 && cy1 == cy2) {
378
     if (cx1 == cx2 && cy1 == cy2) {

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

443
       int8_t cell_xi = (raw[X_AXIS] - (MESH_MIN_X)) * (1.0f / (MESH_X_DIST)),
443
       int8_t cell_xi = (raw[X_AXIS] - (MESH_MIN_X)) * (1.0f / (MESH_X_DIST)),
444
              cell_yi = (raw[Y_AXIS] - (MESH_MIN_Y)) * (1.0f / (MESH_Y_DIST));
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
       const float x0 = mesh_index_to_xpos(cell_xi),   // 64 byte table lookup avoids mul+add
449
       const float x0 = mesh_index_to_xpos(cell_xi),   // 64 byte table lookup avoids mul+add
450
                   y0 = mesh_index_to_ypos(cell_yi);
450
                   y0 = mesh_index_to_ypos(cell_yi);

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

337
             sx = _GET_MESH_X(  i  ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
337
             sx = _GET_MESH_X(  i  ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
338
             ex = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
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
             sy = ey = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
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
             if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey))
344
             if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey))
345
               print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
345
               print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
358
               ey = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
358
               ey = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
359
 
359
 
360
               sx = ex = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
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
               if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey))
364
               if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey))
365
                 print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
365
                 print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
832
             // Check to make sure this segment is entirely on the bed, skip if not.
832
             // Check to make sure this segment is entirely on the bed, skip if not.
833
             if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue;
833
             if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue;
834
           #else                                               // not, we need to skip
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
           #endif
839
           #endif
840
 
840
 
841
           print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height);
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
           // Get nearest i / j from rx / ry
318
           // Get nearest i / j from rx / ry
319
           i = (rx - bilinear_start[X_AXIS] + 0.5 * xGridSpacing) / xGridSpacing;
319
           i = (rx - bilinear_start[X_AXIS] + 0.5 * xGridSpacing) / xGridSpacing;
320
           j = (ry - bilinear_start[Y_AXIS] + 0.5 * yGridSpacing) / yGridSpacing;
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
         if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) {
324
         if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) {
325
           set_bed_leveling_enabled(false);
325
           set_bed_leveling_enabled(false);

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

163
           Y_current = Y_probe_location - (Y_PROBE_OFFSET_FROM_EXTRUDER) + sin(RADIANS(angle)) * radius;
163
           Y_current = Y_probe_location - (Y_PROBE_OFFSET_FROM_EXTRUDER) + sin(RADIANS(angle)) * radius;
164
 
164
 
165
           #if DISABLED(DELTA)
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
           #else
168
           #else
169
             // If we have gone out too far, we can do a simple fix and scale the numbers
169
             // If we have gone out too far, we can do a simple fix and scale the numbers
170
             // back in closer to the origin.
170
             // back in closer to the origin.

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

115
   switch (command[0]) {
115
   switch (command[0]) {
116
     case 'C': // Cope with both V1 early rev and later LCDs.
116
     case 'C': // Cope with both V1 early rev and later LCDs.
117
     case 'S': {
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
     } break;
120
     } break;
122
     case 'T': {
121
     case 'T': {
123
       thermalManager.setTargetHotend(atoi(command + 1), 0);
122
       thermalManager.setTargetHotend(atoi(command + 1), 0);

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

67
 void BrickoutGame::game_screen() {
67
 void BrickoutGame::game_screen() {
68
   if (game_frame()) {     // Run logic twice for finer resolution
68
   if (game_frame()) {     // Run logic twice for finer resolution
69
     // Update Paddle Position
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
     ui.encoderPosition = paddle_x;
71
     ui.encoderPosition = paddle_x;
73
     paddle_x *= (PADDLE_VEL);
72
     paddle_x *= (PADDLE_VEL);
74
 
73
 

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

263
   if (ui.first_page) {
263
   if (ui.first_page) {
264
 
264
 
265
     // Update Cannon Position
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
     ui.encoderPosition = ep;
267
     ui.encoderPosition = ep;
269
 
268
 
270
     ep *= (CANNON_VEL);
269
     ep *= (CANNON_VEL);

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

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

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

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

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

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

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

460
             if (cycles > 0) {
460
             if (cycles > 0) {
461
               const long max_pow = GHV(MAX_BED_POWER, PID_MAX);
461
               const long max_pow = GHV(MAX_BED_POWER, PID_MAX);
462
               bias += (d * (t_high - t_low)) / (t_low + t_high);
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
               d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
464
               d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
465
 
465
 
466
               SERIAL_ECHOPAIR(MSG_BIAS, bias, MSG_D, d, MSG_T_MIN, min, MSG_T_MAX, max);
466
               SERIAL_ECHOPAIR(MSG_BIAS, bias, MSG_D, d, MSG_T_MIN, min, MSG_T_MAX, max);
874
           }
874
           }
875
         #endif // PID_EXTRUSION_SCALING
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
       temp_dState[ee] = temp_hotend[ee].current;
879
       temp_dState[ee] = temp_hotend[ee].current;
880
 
880
 
1070
     if (filament_sensor) {
1070
     if (filament_sensor) {
1071
       meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
1071
       meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
1072
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
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
       planner.calculate_volumetric_for_width_sensor(measurement_delay[meas_shift_index]);
1074
       planner.calculate_volumetric_for_width_sensor(measurement_delay[meas_shift_index]);
1075
     }
1075
     }
1076
   #endif // FILAMENT_WIDTH_SENSOR
1076
   #endif // FILAMENT_WIDTH_SENSOR

Loading…
Cancel
Save