Selaa lähdekoodia

Reduce code size by trusting the compiler

Scott Lahteine 9 vuotta sitten
vanhempi
commit
4cd045791c
1 muutettua tiedostoa jossa 15 lisäystä ja 21 poistoa
  1. 15
    21
      Marlin/Marlin_main.cpp

+ 15
- 21
Marlin/Marlin_main.cpp Näytä tiedosto

@@ -1338,16 +1338,15 @@ bool code_seen(char code) {
1338 1338
  */
1339 1339
 bool get_target_extruder_from_command(int code) {
1340 1340
   if (code_seen('T')) {
1341
-    uint8_t t = code_value_byte();
1342
-    if (t >= EXTRUDERS) {
1341
+    if (code_value_byte() >= EXTRUDERS) {
1343 1342
       SERIAL_ECHO_START;
1344 1343
       SERIAL_CHAR('M');
1345 1344
       SERIAL_ECHO(code);
1346
-      SERIAL_ECHOPAIR(" " MSG_INVALID_EXTRUDER " ", t);
1345
+      SERIAL_ECHOPAIR(" " MSG_INVALID_EXTRUDER " ", code_value_byte());
1347 1346
       SERIAL_EOL;
1348 1347
       return true;
1349 1348
     }
1350
-    target_extruder = t;
1349
+    target_extruder = code_value_byte();
1351 1350
   }
1352 1351
   else
1353 1352
     target_extruder = active_extruder;
@@ -2576,10 +2575,8 @@ void gcode_get_destination() {
2576 2575
     else
2577 2576
       destination[i] = current_position[i];
2578 2577
   }
2579
-  if (code_seen('F')) {
2580
-    float next_feedrate = code_value_linear_units();
2581
-    if (next_feedrate > 0.0) feedrate = next_feedrate;
2582
-  }
2578
+  if (code_seen('F') && code_value_linear_units() > 0.0)
2579
+    feedrate = code_value_linear_units();
2583 2580
 }
2584 2581
 
2585 2582
 void unknown_command_error() {
@@ -4387,11 +4384,10 @@ inline void gcode_M104() {
4387 4384
   #endif
4388 4385
 
4389 4386
   if (code_seen('S')) {
4390
-    float temp = code_value_temp_abs();
4391
-    thermalManager.setTargetHotend(temp, target_extruder);
4387
+    thermalManager.setTargetHotend(code_value_temp_abs(), target_extruder);
4392 4388
     #if ENABLED(DUAL_X_CARRIAGE)
4393 4389
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
4394
-        thermalManager.setTargetHotend(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset, 1);
4390
+        thermalManager.setTargetHotend(code_value_temp_abs() == 0.0 ? 0.0 : code_value_temp_abs() + duplicate_extruder_temp_offset, 1);
4395 4391
     #endif
4396 4392
 
4397 4393
     #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
@@ -4402,13 +4398,13 @@ inline void gcode_M104() {
4402 4398
        * stand by mode, for instance in a dual extruder setup, without affecting
4403 4399
        * the running print timer.
4404 4400
        */
4405
-      if (temp <= (EXTRUDE_MINTEMP)/2) {
4401
+      if (code_value_temp_abs() <= (EXTRUDE_MINTEMP)/2) {
4406 4402
         print_job_timer.stop();
4407 4403
         LCD_MESSAGEPGM(WELCOME_MSG);
4408 4404
       }
4409 4405
     #endif
4410 4406
 
4411
-    if (temp > thermalManager.degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4407
+    if (code_value_temp_abs() > thermalManager.degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4412 4408
   }
4413 4409
 }
4414 4410
 
@@ -4566,11 +4562,10 @@ inline void gcode_M109() {
4566 4562
 
4567 4563
   bool no_wait_for_cooling = code_seen('S');
4568 4564
   if (no_wait_for_cooling || code_seen('R')) {
4569
-    float temp = code_value_temp_abs();
4570
-    thermalManager.setTargetHotend(temp, target_extruder);
4565
+    thermalManager.setTargetHotend(code_value_temp_abs(), target_extruder);
4571 4566
     #if ENABLED(DUAL_X_CARRIAGE)
4572 4567
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
4573
-        thermalManager.setTargetHotend(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset, 1);
4568
+        thermalManager.setTargetHotend(code_value_temp_abs() == 0.0 ? 0.0 : code_value_temp_abs() + duplicate_extruder_temp_offset, 1);
4574 4569
     #endif
4575 4570
 
4576 4571
     #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
@@ -4579,7 +4574,7 @@ inline void gcode_M109() {
4579 4574
        * stand by mode, for instance in a dual extruder setup, without affecting
4580 4575
        * the running print timer.
4581 4576
        */
4582
-      if (temp <= (EXTRUDE_MINTEMP)/2) {
4577
+      if (code_value_temp_abs() <= (EXTRUDE_MINTEMP)/2) {
4583 4578
         print_job_timer.stop();
4584 4579
         LCD_MESSAGEPGM(WELCOME_MSG);
4585 4580
       }
@@ -4693,7 +4688,7 @@ inline void gcode_M109() {
4693 4688
     if (no_wait_for_cooling || code_seen('R')) {
4694 4689
       thermalManager.setTargetBed(code_value_temp_abs());
4695 4690
       #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
4696
-        if(code_value_temp_abs() > BED_MINTEMP) {
4691
+        if (code_value_temp_abs() > BED_MINTEMP) {
4697 4692
           /**
4698 4693
           * We start the timer when 'heating and waiting' command arrives, LCD 
4699 4694
           * functions never wait. Cooling down managed by extruders.
@@ -5241,13 +5236,12 @@ inline void gcode_M200() {
5241 5236
   if (get_target_extruder_from_command(200)) return;
5242 5237
 
5243 5238
   if (code_seen('D')) {
5244
-    float diameter = code_value_linear_units();
5245 5239
     // setting any extruder filament size disables volumetric on the assumption that
5246 5240
     // slicers either generate in extruder values as cubic mm or as as filament feeds
5247 5241
     // for all extruders
5248
-    volumetric_enabled = (diameter != 0.0);
5242
+    volumetric_enabled = (code_value_linear_units() != 0.0);
5249 5243
     if (volumetric_enabled) {
5250
-      filament_size[target_extruder] = diameter;
5244
+      filament_size[target_extruder] = code_value_linear_units();
5251 5245
       // make sure all extruders have some sane value for the filament size
5252 5246
       for (int i = 0; i < EXTRUDERS; i++)
5253 5247
         if (! filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;

Loading…
Peruuta
Tallenna