Browse Source

Merge pull request #6559 from thinkyhead/rc_more_optimal

Compact smart_fill_mesh slightly
Scott Lahteine 8 years ago
parent
commit
e1b85ff67b

+ 17
- 14
Marlin/G26_Mesh_Validation_Tool.cpp View File

@@ -126,6 +126,8 @@
126 126
   void set_destination_to_current();
127 127
   void set_current_to_destination();
128 128
   float code_value_float();
129
+  float code_value_linear_units();
130
+  float code_value_axis_units(const AxisEnum axis);
129 131
   bool code_value_bool();
130 132
   bool code_has_value();
131 133
   void lcd_init();
@@ -164,10 +166,11 @@
164 166
                filament_diameter = FILAMENT,
165 167
                prime_length = PRIME_LENGTH,
166 168
                x_pos, y_pos,
167
-               bed_temp = BED_TEMP,
168
-               hotend_temp = HOTEND_TEMP,
169 169
                ooze_amount = OOZE_AMOUNT;
170 170
 
171
+  static int16_t bed_temp = BED_TEMP,
172
+                 hotend_temp = HOTEND_TEMP;
173
+
171 174
   static int8_t prime_flag = 0;
172 175
 
173 176
   static bool keep_heaters_on = false;
@@ -379,9 +382,9 @@
379 382
 
380 383
     if (!keep_heaters_on) {
381 384
       #if HAS_TEMP_BED
382
-        thermalManager.setTargetBed(0.0);
385
+        thermalManager.setTargetBed(0);
383 386
       #endif
384
-      thermalManager.setTargetHotend(0.0, 0);
387
+      thermalManager.setTargetHotend(0, 0);
385 388
     }
386 389
   }
387 390
 
@@ -640,8 +643,8 @@
640 643
     keep_heaters_on       = false;
641 644
 
642 645
     if (code_seen('B')) {
643
-      bed_temp = code_value_float();
644
-      if (!WITHIN(bed_temp, 15.0, 140.0)) {
646
+      bed_temp = code_value_temp_abs();
647
+      if (!WITHIN(bed_temp, 15, 140)) {
645 648
         SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible.");
646 649
         return UBL_ERR;
647 650
       }
@@ -650,7 +653,7 @@
650 653
     if (code_seen('C')) continue_with_closest++;
651 654
 
652 655
     if (code_seen('L')) {
653
-      layer_height = code_value_float();
656
+      layer_height = code_value_linear_units();
654 657
       if (!WITHIN(layer_height, 0.0, 2.0)) {
655 658
         SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible.");
656 659
         return UBL_ERR;
@@ -682,14 +685,14 @@
682 685
     if (code_seen('K')) keep_heaters_on++;
683 686
 
684 687
     if (code_seen('O') && code_has_value())
685
-      ooze_amount = code_value_float();
688
+      ooze_amount = code_value_linear_units();
686 689
 
687 690
     if (code_seen('P')) {
688 691
       if (!code_has_value())
689 692
         prime_flag = -1;
690 693
       else {
691 694
         prime_flag++;
692
-        prime_length = code_value_float();
695
+        prime_length = code_value_linear_units();
693 696
         if (!WITHIN(prime_length, 0.0, 25.0)) {
694 697
           SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible.");
695 698
           return UBL_ERR;
@@ -698,7 +701,7 @@
698 701
     }
699 702
 
700 703
     if (code_seen('F')) {
701
-      filament_diameter = code_value_float();
704
+      filament_diameter = code_value_linear_units();
702 705
       if (!WITHIN(filament_diameter, 1.0, 4.0)) {
703 706
         SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible.");
704 707
         return UBL_ERR;
@@ -711,8 +714,8 @@
711 714
     extrusion_multiplier *= filament_diameter * sq(nozzle) / sq(0.3); // Scale up by nozzle size
712 715
 
713 716
     if (code_seen('H')) {
714
-      hotend_temp = code_value_float();
715
-      if (!WITHIN(hotend_temp, 165.0, 280.0)) {
717
+      hotend_temp = code_value_temp_abs();
718
+      if (!WITHIN(hotend_temp, 165, 280)) {
716 719
         SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible.");
717 720
         return UBL_ERR;
718 721
       }
@@ -727,7 +730,7 @@
727 730
     y_pos = current_position[Y_AXIS];
728 731
 
729 732
     if (code_seen('X')) {
730
-      x_pos = code_value_float();
733
+      x_pos = code_value_axis_units(X_AXIS);
731 734
       if (!WITHIN(x_pos, X_MIN_POS, X_MAX_POS)) {
732 735
         SERIAL_PROTOCOLLNPGM("?Specified X coordinate not plausible.");
733 736
         return UBL_ERR;
@@ -736,7 +739,7 @@
736 739
     else
737 740
 
738 741
     if (code_seen('Y')) {
739
-      y_pos = code_value_float();
742
+      y_pos = code_value_axis_units(Y_AXIS);
740 743
       if (!WITHIN(y_pos, Y_MIN_POS, Y_MAX_POS)) {
741 744
         SERIAL_PROTOCOLLNPGM("?Specified Y coordinate not plausible.");
742 745
         return UBL_ERR;

+ 1
- 1
Marlin/M100_Free_Mem_Chk.cpp View File

@@ -241,7 +241,7 @@ void gcode_M100() {
241 241
   SERIAL_ECHOPAIR("\n__brkval : ", hex_address(__brkval));
242 242
   SERIAL_ECHOPAIR("\n__bss_end : ", hex_address(&__bss_end));
243 243
 
244
-  uint8_t *ptr = END_OF_HEAP(), *sp = top_of_stack();
244
+  char *ptr = END_OF_HEAP(), *sp = top_of_stack();
245 245
 
246 246
   SERIAL_ECHOPAIR("\nstart of free space : ", hex_address(ptr));
247 247
   SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_address(sp));

+ 13
- 3
Marlin/Marlin.h View File

@@ -290,8 +290,18 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
290 290
 // GCode support for external objects
291 291
 bool code_seen(char);
292 292
 int code_value_int();
293
-float code_value_temp_abs();
294
-float code_value_temp_diff();
293
+int16_t code_value_temp_abs();
294
+int16_t code_value_temp_diff();
295
+
296
+#if ENABLED(INCH_MODE_SUPPORT)
297
+  float code_value_linear_units();
298
+  float code_value_axis_units(const AxisEnum axis);
299
+  float code_value_per_axis_unit(const AxisEnum axis);
300
+#else
301
+  #define code_value_linear_units() code_value_float()
302
+  #define code_value_axis_units(A) code_value_float()
303
+  #define code_value_per_axis_unit(A) code_value_float()
304
+#endif
295 305
 
296 306
 #if IS_KINEMATIC
297 307
   extern float delta[ABC];
@@ -351,7 +361,7 @@ float code_value_temp_diff();
351 361
 #endif
352 362
 
353 363
 #if FAN_COUNT > 0
354
-  extern int fanSpeeds[FAN_COUNT];
364
+  extern int16_t fanSpeeds[FAN_COUNT];
355 365
 #endif
356 366
 
357 367
 #if ENABLED(BARICUDA)

+ 40
- 45
Marlin/Marlin_main.cpp View File

@@ -440,7 +440,7 @@ float soft_endstop_min[XYZ] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
440 440
       soft_endstop_max[XYZ] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
441 441
 
442 442
 #if FAN_COUNT > 0
443
-  int fanSpeeds[FAN_COUNT] = { 0 };
443
+  int16_t fanSpeeds[FAN_COUNT] = { 0 };
444 444
 #endif
445 445
 
446 446
 // The active extruder (tool). Set with T<extruder> command.
@@ -1292,32 +1292,24 @@ inline bool code_value_bool() { return !code_has_value() || code_value_byte() >
1292 1292
   inline float code_value_linear_units() { return code_value_float() * linear_unit_factor; }
1293 1293
   inline float code_value_axis_units(const AxisEnum axis) { return code_value_float() * axis_unit_factor(axis); }
1294 1294
   inline float code_value_per_axis_unit(const AxisEnum axis) { return code_value_float() / axis_unit_factor(axis); }
1295
-
1296
-#else
1297
-
1298
-  #define code_value_linear_units() code_value_float()
1299
-  #define code_value_axis_units(A) code_value_float()
1300
-  #define code_value_per_axis_unit(A) code_value_float()
1301
-
1302 1295
 #endif
1303 1296
 
1304 1297
 #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
1305 1298
   inline void set_input_temp_units(TempUnit units) { input_temp_units = units; }
1306 1299
 
1307
-  float code_value_temp_abs() {
1300
+  int16_t code_value_temp_abs() {
1308 1301
     switch (input_temp_units) {
1309
-      case TEMPUNIT_C:
1310
-        return code_value_float();
1311 1302
       case TEMPUNIT_F:
1312 1303
         return (code_value_float() - 32) * 0.5555555556;
1313 1304
       case TEMPUNIT_K:
1314 1305
         return code_value_float() - 273.15;
1306
+      case TEMPUNIT_C:
1315 1307
       default:
1316
-        return code_value_float();
1308
+        return code_value_int();
1317 1309
     }
1318 1310
   }
1319 1311
 
1320
-  float code_value_temp_diff() {
1312
+  int16_t code_value_temp_diff() {
1321 1313
     switch (input_temp_units) {
1322 1314
       case TEMPUNIT_C:
1323 1315
       case TEMPUNIT_K:
@@ -1329,8 +1321,8 @@ inline bool code_value_bool() { return !code_has_value() || code_value_byte() >
1329 1321
     }
1330 1322
   }
1331 1323
 #else
1332
-  float code_value_temp_abs() { return code_value_float(); }
1333
-  float code_value_temp_diff() { return code_value_float(); }
1324
+  int16_t code_value_temp_abs() { return code_value_int(); }
1325
+  int16_t code_value_temp_diff() { return code_value_int(); }
1334 1326
 #endif
1335 1327
 
1336 1328
 FORCE_INLINE millis_t code_value_millis() { return code_value_ulong(); }
@@ -1391,7 +1383,7 @@ bool get_target_extruder_from_command(int code) {
1391 1383
   static float raised_parked_position[XYZE];         // used in mode 1
1392 1384
   static millis_t delayed_move_time = 0;             // used in mode 1
1393 1385
   static float duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // used in mode 2
1394
-  static float duplicate_extruder_temp_offset = 0;   // used in mode 2
1386
+  static int16_t duplicate_extruder_temp_offset = 0; // used in mode 2
1395 1387
 
1396 1388
 #endif // DUAL_X_CARRIAGE
1397 1389
 
@@ -2080,10 +2072,10 @@ static void clean_up_after_endstop_or_probe_move() {
2080 2072
       void set_heaters_for_bltouch(const bool deploy) {
2081 2073
         static bool heaters_were_disabled = false;
2082 2074
         static millis_t next_emi_protection = 0;
2083
-        static float temps_at_entry[HOTENDS];
2075
+        static int16_t temps_at_entry[HOTENDS];
2084 2076
 
2085 2077
         #if HAS_TEMP_BED
2086
-          static float bed_temp_at_entry;
2078
+          static int16_t bed_temp_at_entry;
2087 2079
         #endif
2088 2080
 
2089 2081
         // If called out of order or far apart something is seriously wrong
@@ -2588,7 +2580,7 @@ static void clean_up_after_endstop_or_probe_move() {
2588 2580
   /**
2589 2581
    * Extrapolate a single point from its neighbors
2590 2582
    */
2591
-  static void extrapolate_one_point(uint8_t x, uint8_t y, int8_t xdir, int8_t ydir) {
2583
+  static void extrapolate_one_point(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
2592 2584
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2593 2585
       if (DEBUGGING(LEVELING)) {
2594 2586
         SERIAL_ECHOPGM("Extrapolate [");
@@ -2611,9 +2603,10 @@ static void clean_up_after_endstop_or_probe_move() {
2611 2603
     SERIAL_EOL;
2612 2604
 
2613 2605
     // Get X neighbors, Y neighbors, and XY neighbors
2614
-    float a1 = z_values[x + xdir][y], a2 = z_values[x + xdir * 2][y],
2615
-          b1 = z_values[x][y + ydir], b2 = z_values[x][y + ydir * 2],
2616
-          c1 = z_values[x + xdir][y + ydir], c2 = z_values[x + xdir * 2][y + ydir * 2];
2606
+    const uint8_t x1 = x + xdir, y1 = y + ydir, x2 = x1 + xdir, y2 = y1 + ydir;
2607
+    float a1 = z_values[x1][y ], a2 = z_values[x2][y ],
2608
+          b1 = z_values[x ][y1], b2 = z_values[x ][y2],
2609
+          c1 = z_values[x1][y1], c2 = z_values[x2][y2];
2617 2610
 
2618 2611
     // Treat far unprobed points as zero, near as equal to far
2619 2612
     if (isnan(a2)) a2 = 0.0; if (isnan(a1)) a1 = a2;
@@ -2647,19 +2640,19 @@ static void clean_up_after_endstop_or_probe_move() {
2647 2640
    */
2648 2641
   static void extrapolate_unprobed_bed_level() {
2649 2642
     #ifdef HALF_IN_X
2650
-      const uint8_t ctrx2 = 0, xlen = GRID_MAX_POINTS_X - 1;
2643
+      constexpr uint8_t ctrx2 = 0, xlen = GRID_MAX_POINTS_X - 1;
2651 2644
     #else
2652
-      const uint8_t ctrx1 = (GRID_MAX_POINTS_X - 1) / 2, // left-of-center
2653
-                    ctrx2 = GRID_MAX_POINTS_X / 2,       // right-of-center
2654
-                    xlen = ctrx1;
2645
+      constexpr uint8_t ctrx1 = (GRID_MAX_POINTS_X - 1) / 2, // left-of-center
2646
+                        ctrx2 = (GRID_MAX_POINTS_X) / 2,     // right-of-center
2647
+                        xlen = ctrx1;
2655 2648
     #endif
2656 2649
 
2657 2650
     #ifdef HALF_IN_Y
2658
-      const uint8_t ctry2 = 0, ylen = GRID_MAX_POINTS_Y - 1;
2651
+      constexpr uint8_t ctry2 = 0, ylen = GRID_MAX_POINTS_Y - 1;
2659 2652
     #else
2660
-      const uint8_t ctry1 = (GRID_MAX_POINTS_Y - 1) / 2, // top-of-center
2661
-                    ctry2 = GRID_MAX_POINTS_Y / 2,       // bottom-of-center
2662
-                    ylen = ctry1;
2653
+      constexpr uint8_t ctry1 = (GRID_MAX_POINTS_Y - 1) / 2, // top-of-center
2654
+                        ctry2 = (GRID_MAX_POINTS_Y) / 2,     // bottom-of-center
2655
+                        ylen = ctry1;
2663 2656
     #endif
2664 2657
 
2665 2658
     for (uint8_t xo = 0; xo <= xlen; xo++)
@@ -6477,10 +6470,11 @@ inline void gcode_M104() {
6477 6470
   #endif
6478 6471
 
6479 6472
   if (code_seen('S')) {
6480
-    thermalManager.setTargetHotend(code_value_temp_abs(), target_extruder);
6473
+    const int16_t temp = code_value_temp_abs();
6474
+    thermalManager.setTargetHotend(temp, target_extruder);
6481 6475
     #if ENABLED(DUAL_X_CARRIAGE)
6482 6476
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
6483
-        thermalManager.setTargetHotend(code_value_temp_abs() == 0.0 ? 0.0 : code_value_temp_abs() + duplicate_extruder_temp_offset, 1);
6477
+        thermalManager.setTargetHotend(temp ? temp + duplicate_extruder_temp_offset : 0, 1);
6484 6478
     #endif
6485 6479
 
6486 6480
     #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
@@ -6490,7 +6484,7 @@ inline void gcode_M104() {
6490 6484
        * standby mode, for instance in a dual extruder setup, without affecting
6491 6485
        * the running print timer.
6492 6486
        */
6493
-      if (code_value_temp_abs() <= (EXTRUDE_MINTEMP)/2) {
6487
+      if (code_value_temp_abs() <= (EXTRUDE_MINTEMP) / 2) {
6494 6488
         print_job_timer.stop();
6495 6489
         LCD_MESSAGEPGM(WELCOME_MSG);
6496 6490
       }
@@ -6513,7 +6507,7 @@ inline void gcode_M104() {
6513 6507
       SERIAL_PROTOCOLPGM(" /");
6514 6508
       SERIAL_PROTOCOL_F(thermalManager.degTargetHotend(target_extruder), 1);
6515 6509
       #if ENABLED(SHOW_TEMP_ADC_VALUES)
6516
-        SERIAL_PROTOCOLPAIR(" (", thermalManager.current_temperature_raw[target_extruder] / OVERSAMPLENR);
6510
+        SERIAL_PROTOCOLPAIR(" (", thermalManager.rawHotendTemp(target_extruder) / OVERSAMPLENR);
6517 6511
         SERIAL_PROTOCOLCHAR(')');
6518 6512
       #endif
6519 6513
     #endif
@@ -6523,7 +6517,7 @@ inline void gcode_M104() {
6523 6517
       SERIAL_PROTOCOLPGM(" /");
6524 6518
       SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1);
6525 6519
       #if ENABLED(SHOW_TEMP_ADC_VALUES)
6526
-        SERIAL_PROTOCOLPAIR(" (", thermalManager.current_temperature_bed_raw / OVERSAMPLENR);
6520
+        SERIAL_PROTOCOLPAIR(" (", thermalManager.rawBedTemp() / OVERSAMPLENR);
6527 6521
         SERIAL_PROTOCOLCHAR(')');
6528 6522
       #endif
6529 6523
     #endif
@@ -6535,7 +6529,7 @@ inline void gcode_M104() {
6535 6529
         SERIAL_PROTOCOLPGM(" /");
6536 6530
         SERIAL_PROTOCOL_F(thermalManager.degTargetHotend(e), 1);
6537 6531
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
6538
-          SERIAL_PROTOCOLPAIR(" (", thermalManager.current_temperature_raw[e] / OVERSAMPLENR);
6532
+          SERIAL_PROTOCOLPAIR(" (", thermalManager.rawHotendTemp(e) / OVERSAMPLENR);
6539 6533
           SERIAL_PROTOCOLCHAR(')');
6540 6534
         #endif
6541 6535
       }
@@ -6671,10 +6665,11 @@ inline void gcode_M109() {
6671 6665
 
6672 6666
   const bool no_wait_for_cooling = code_seen('S');
6673 6667
   if (no_wait_for_cooling || code_seen('R')) {
6674
-    thermalManager.setTargetHotend(code_value_temp_abs(), target_extruder);
6668
+    const int16_t temp = code_value_temp_abs();
6669
+    thermalManager.setTargetHotend(temp, target_extruder);
6675 6670
     #if ENABLED(DUAL_X_CARRIAGE)
6676 6671
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
6677
-        thermalManager.setTargetHotend(code_value_temp_abs() == 0.0 ? 0.0 : code_value_temp_abs() + duplicate_extruder_temp_offset, 1);
6672
+        thermalManager.setTargetHotend(temp ? temp + duplicate_extruder_temp_offset : 0, 1);
6678 6673
     #endif
6679 6674
 
6680 6675
     #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
@@ -7202,7 +7197,7 @@ inline void gcode_M92() {
7202 7197
   LOOP_XYZE(i) {
7203 7198
     if (code_seen(axis_codes[i])) {
7204 7199
       if (i == E_AXIS) {
7205
-        const float value = code_value_per_axis_unit(E_AXIS + TARGET_EXTRUDER);
7200
+        const float value = code_value_per_axis_unit((AxisEnum)(E_AXIS + TARGET_EXTRUDER));
7206 7201
         if (value < 20.0) {
7207 7202
           float factor = planner.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] / value; // increase e constants if M92 E14 is given for netfab.
7208 7203
           planner.max_jerk[E_AXIS] *= factor;
@@ -7212,7 +7207,7 @@ inline void gcode_M92() {
7212 7207
         planner.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] = value;
7213 7208
       }
7214 7209
       else {
7215
-        planner.axis_steps_per_mm[i] = code_value_per_axis_unit(i);
7210
+        planner.axis_steps_per_mm[i] = code_value_per_axis_unit((AxisEnum)i);
7216 7211
       }
7217 7212
     }
7218 7213
   }
@@ -8106,11 +8101,11 @@ inline void gcode_M226() {
8106 8101
  */
8107 8102
 inline void gcode_M303() {
8108 8103
   #if HAS_PID_HEATING
8109
-    int e = code_seen('E') ? code_value_int() : 0;
8110
-    int c = code_seen('C') ? code_value_int() : 5;
8111
-    bool u = code_seen('U') && code_value_bool();
8104
+    const int e = code_seen('E') ? code_value_int() : 0,
8105
+              c = code_seen('C') ? code_value_int() : 5;
8106
+    const bool u = code_seen('U') && code_value_bool();
8112 8107
 
8113
-    float temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70.0 : 150.0);
8108
+    int16_t temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70 : 150);
8114 8109
 
8115 8110
     if (WITHIN(e, 0, HOTENDS - 1))
8116 8111
       target_extruder = e;
@@ -8747,7 +8742,6 @@ inline void gcode_M503() {
8747 8742
 
8748 8743
     const millis_t nozzle_timeout = millis() + (millis_t)(FILAMENT_CHANGE_NOZZLE_TIMEOUT) * 1000UL;
8749 8744
     bool nozzle_timed_out = false;
8750
-    float temps[4];
8751 8745
 
8752 8746
     // Wait for filament insert by user and press button
8753 8747
     lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_INSERT);
@@ -8758,6 +8752,7 @@ inline void gcode_M503() {
8758 8752
 
8759 8753
     idle();
8760 8754
 
8755
+    int16_t temps[HOTENDS];
8761 8756
     HOTEND_LOOP() temps[e] = thermalManager.target_temperature[e]; // Save nozzle temps
8762 8757
 
8763 8758
     KEEPALIVE_STATE(PAUSED_FOR_USER);

+ 1
- 4
Marlin/planner.cpp View File

@@ -387,10 +387,7 @@ void Planner::recalculate() {
387 387
 
388 388
     float t = autotemp_min + high * autotemp_factor;
389 389
     t = constrain(t, autotemp_min, autotemp_max);
390
-    if (oldt > t) {
391
-      t *= (1 - (AUTOTEMP_OLDWEIGHT));
392
-      t += (AUTOTEMP_OLDWEIGHT) * oldt;
393
-    }
390
+    if (t < oldt) t = t * (1 - (AUTOTEMP_OLDWEIGHT)) + oldt * (AUTOTEMP_OLDWEIGHT);
394 391
     oldt = t;
395 392
     thermalManager.setTargetHotend(t, 0);
396 393
   }

+ 28
- 28
Marlin/temperature.cpp View File

@@ -64,10 +64,10 @@ Temperature thermalManager;
64 64
 
65 65
 float Temperature::current_temperature[HOTENDS] = { 0.0 },
66 66
       Temperature::current_temperature_bed = 0.0;
67
-int   Temperature::current_temperature_raw[HOTENDS] = { 0 },
68
-      Temperature::target_temperature[HOTENDS] = { 0 },
69
-      Temperature::current_temperature_bed_raw = 0,
70
-      Temperature::target_temperature_bed = 0;
67
+int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
68
+        Temperature::target_temperature[HOTENDS] = { 0 },
69
+        Temperature::current_temperature_bed_raw = 0,
70
+        Temperature::target_temperature_bed = 0;
71 71
 
72 72
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
73 73
   float Temperature::redundant_temperature = 0.0;
@@ -160,33 +160,33 @@ volatile bool Temperature::temp_meas_ready = false;
160 160
   millis_t Temperature::next_bed_check_ms;
161 161
 #endif
162 162
 
163
-unsigned long Temperature::raw_temp_value[MAX_EXTRUDERS] = { 0 };
164
-unsigned long Temperature::raw_temp_bed_value = 0;
163
+uint16_t Temperature::raw_temp_value[MAX_EXTRUDERS] = { 0 },
164
+         Temperature::raw_temp_bed_value = 0;
165 165
 
166 166
 // Init min and max temp with extreme values to prevent false errors during startup
167
-int Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP, HEATER_3_RAW_LO_TEMP, HEATER_4_RAW_LO_TEMP),
168
-    Temperature::maxttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP, HEATER_3_RAW_HI_TEMP, HEATER_4_RAW_HI_TEMP),
169
-    Temperature::minttemp[HOTENDS] = { 0 },
170
-    Temperature::maxttemp[HOTENDS] = ARRAY_BY_HOTENDS1(16383);
167
+int16_t Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP, HEATER_3_RAW_LO_TEMP, HEATER_4_RAW_LO_TEMP),
168
+        Temperature::maxttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP, HEATER_3_RAW_HI_TEMP, HEATER_4_RAW_HI_TEMP),
169
+        Temperature::minttemp[HOTENDS] = { 0 },
170
+        Temperature::maxttemp[HOTENDS] = ARRAY_BY_HOTENDS1(16383);
171 171
 
172 172
 #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
173
-  int Temperature::consecutive_low_temperature_error[HOTENDS] = { 0 };
173
+  uint8_t Temperature::consecutive_low_temperature_error[HOTENDS] = { 0 };
174 174
 #endif
175 175
 
176 176
 #ifdef MILLISECONDS_PREHEAT_TIME
177
-  unsigned long Temperature::preheat_end_time[HOTENDS] = { 0 };
177
+  millis_t Temperature::preheat_end_time[HOTENDS] = { 0 };
178 178
 #endif
179 179
 
180 180
 #ifdef BED_MINTEMP
181
-  int Temperature::bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
181
+  int16_t Temperature::bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
182 182
 #endif
183 183
 
184 184
 #ifdef BED_MAXTEMP
185
-  int Temperature::bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
185
+  int16_t Temperature::bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
186 186
 #endif
187 187
 
188 188
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
189
-  int Temperature::meas_shift_index;  // Index of a delayed sample in buffer
189
+  int16_t Temperature::meas_shift_index;  // Index of a delayed sample in buffer
190 190
 #endif
191 191
 
192 192
 #if HAS_AUTO_FAN
@@ -1242,7 +1242,7 @@ void Temperature::init() {
1242 1242
     millis_t Temperature::thermal_runaway_bed_timer;
1243 1243
   #endif
1244 1244
 
1245
-  void Temperature::thermal_runaway_protection(Temperature::TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1245
+  void Temperature::thermal_runaway_protection(Temperature::TRState* state, millis_t* timer, float current, float target, int heater_id, int period_seconds, int hysteresis_degc) {
1246 1246
 
1247 1247
     static float tr_target_temperature[HOTENDS + 1] = { 0.0 };
1248 1248
 
@@ -1252,17 +1252,17 @@ void Temperature::init() {
1252 1252
         if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHO(heater_id);
1253 1253
         SERIAL_ECHOPAIR(" ;  State:", *state);
1254 1254
         SERIAL_ECHOPAIR(" ;  Timer:", *timer);
1255
-        SERIAL_ECHOPAIR(" ;  Temperature:", temperature);
1256
-        SERIAL_ECHOPAIR(" ;  Target Temp:", target_temperature);
1255
+        SERIAL_ECHOPAIR(" ;  Temperature:", current);
1256
+        SERIAL_ECHOPAIR(" ;  Target Temp:", target);
1257 1257
         SERIAL_EOL;
1258 1258
     */
1259 1259
 
1260 1260
     int heater_index = heater_id >= 0 ? heater_id : HOTENDS;
1261 1261
 
1262 1262
     // If the target temperature changes, restart
1263
-    if (tr_target_temperature[heater_index] != target_temperature) {
1264
-      tr_target_temperature[heater_index] = target_temperature;
1265
-      *state = target_temperature > 0 ? TRFirstHeating : TRInactive;
1263
+    if (tr_target_temperature[heater_index] != target) {
1264
+      tr_target_temperature[heater_index] = target;
1265
+      *state = target > 0 ? TRFirstHeating : TRInactive;
1266 1266
     }
1267 1267
 
1268 1268
     switch (*state) {
@@ -1270,11 +1270,11 @@ void Temperature::init() {
1270 1270
       case TRInactive: break;
1271 1271
       // When first heating, wait for the temperature to be reached then go to Stable state
1272 1272
       case TRFirstHeating:
1273
-        if (temperature < tr_target_temperature[heater_index]) break;
1273
+        if (current < tr_target_temperature[heater_index]) break;
1274 1274
         *state = TRStable;
1275 1275
       // While the temperature is stable watch for a bad temperature
1276 1276
       case TRStable:
1277
-        if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc) {
1277
+        if (current >= tr_target_temperature[heater_index] - hysteresis_degc) {
1278 1278
           *timer = millis() + period_seconds * 1000UL;
1279 1279
           break;
1280 1280
         }
@@ -1961,9 +1961,9 @@ void Temperature::isr() {
1961 1961
     };
1962 1962
 
1963 1963
     for (uint8_t e = 0; e < COUNT(temp_dir); e++) {
1964
-      const int tdir = temp_dir[e], rawtemp = current_temperature_raw[e] * tdir;
1965
-      if (rawtemp > maxttemp_raw[e] * tdir && target_temperature[e] > 0.0f) max_temp_error(e);
1966
-      if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && target_temperature[e] > 0.0f) {
1964
+      const int16_t tdir = temp_dir[e], rawtemp = current_temperature_raw[e] * tdir;
1965
+      if (rawtemp > maxttemp_raw[e] * tdir && target_temperature[e] > 0) max_temp_error(e);
1966
+      if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && target_temperature[e] > 0) {
1967 1967
         #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1968 1968
           if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
1969 1969
         #endif
@@ -1981,8 +1981,8 @@ void Temperature::isr() {
1981 1981
       #else
1982 1982
         #define GEBED >=
1983 1983
       #endif
1984
-      if (current_temperature_bed_raw GEBED bed_maxttemp_raw && target_temperature_bed > 0.0f) max_temp_error(-1);
1985
-      if (bed_minttemp_raw GEBED current_temperature_bed_raw && target_temperature_bed > 0.0f) min_temp_error(-1);
1984
+      if (current_temperature_bed_raw GEBED bed_maxttemp_raw && target_temperature_bed > 0) max_temp_error(-1);
1985
+      if (bed_minttemp_raw GEBED current_temperature_bed_raw && target_temperature_bed > 0) min_temp_error(-1);
1986 1986
     #endif
1987 1987
 
1988 1988
   } // temp_count >= OVERSAMPLENR

+ 30
- 30
Marlin/temperature.h View File

@@ -99,10 +99,10 @@ class Temperature {
99 99
 
100 100
     static float current_temperature[HOTENDS],
101 101
                  current_temperature_bed;
102
-    static int   current_temperature_raw[HOTENDS],
103
-                 target_temperature[HOTENDS],
104
-                 current_temperature_bed_raw,
105
-                 target_temperature_bed;
102
+    static int16_t current_temperature_raw[HOTENDS],
103
+                   target_temperature[HOTENDS],
104
+                   current_temperature_bed_raw,
105
+                   target_temperature_bed;
106 106
 
107 107
     static volatile bool in_temp_isr;
108 108
 
@@ -217,33 +217,33 @@ class Temperature {
217 217
       static millis_t next_bed_check_ms;
218 218
     #endif
219 219
 
220
-    static unsigned long raw_temp_value[MAX_EXTRUDERS],
221
-                         raw_temp_bed_value;
220
+    static uint16_t raw_temp_value[MAX_EXTRUDERS],
221
+                    raw_temp_bed_value;
222 222
 
223 223
     // Init min and max temp with extreme values to prevent false errors during startup
224
-    static int minttemp_raw[HOTENDS],
225
-               maxttemp_raw[HOTENDS],
226
-               minttemp[HOTENDS],
227
-               maxttemp[HOTENDS];
224
+    static int16_t minttemp_raw[HOTENDS],
225
+                   maxttemp_raw[HOTENDS],
226
+                   minttemp[HOTENDS],
227
+                   maxttemp[HOTENDS];
228 228
 
229 229
     #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
230
-      static int consecutive_low_temperature_error[HOTENDS];
230
+      static uint8_t consecutive_low_temperature_error[HOTENDS];
231 231
     #endif
232 232
 
233 233
     #ifdef MILLISECONDS_PREHEAT_TIME
234
-      static unsigned long preheat_end_time[HOTENDS];
234
+      static millis_t preheat_end_time[HOTENDS];
235 235
     #endif
236 236
 
237 237
     #ifdef BED_MINTEMP
238
-      static int bed_minttemp_raw;
238
+      static int16_t bed_minttemp_raw;
239 239
     #endif
240 240
 
241 241
     #ifdef BED_MAXTEMP
242
-      static int bed_maxttemp_raw;
242
+      static int16_t bed_maxttemp_raw;
243 243
     #endif
244 244
 
245 245
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
246
-      static int meas_shift_index;  // Index of a delayed sample in buffer
246
+      static int16_t meas_shift_index;  // Index of a delayed sample in buffer
247 247
     #endif
248 248
 
249 249
     #if HAS_AUTO_FAN
@@ -323,31 +323,31 @@ class Temperature {
323 323
     //inline so that there is no performance decrease.
324 324
     //deg=degreeCelsius
325 325
 
326
-    static float degHotend(uint8_t e) {
326
+    static int16_t degHotend(uint8_t e) {
327 327
       #if HOTENDS == 1
328 328
         UNUSED(e);
329 329
       #endif
330 330
       return current_temperature[HOTEND_INDEX];
331 331
     }
332
-    static float degBed() { return current_temperature_bed; }
332
+    static int16_t degBed() { return current_temperature_bed; }
333 333
 
334 334
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
335
-    static float rawHotendTemp(uint8_t e) {
336
-      #if HOTENDS == 1
337
-        UNUSED(e);
338
-      #endif
339
-      return current_temperature_raw[HOTEND_INDEX];
340
-    }
341
-    static float rawBedTemp() { return current_temperature_bed_raw; }
335
+      static int16_t rawHotendTemp(uint8_t e) {
336
+        #if HOTENDS == 1
337
+          UNUSED(e);
338
+        #endif
339
+        return current_temperature_raw[HOTEND_INDEX];
340
+      }
341
+      static int16_t rawBedTemp() { return current_temperature_bed_raw; }
342 342
     #endif
343 343
 
344
-    static float degTargetHotend(uint8_t e) {
344
+    static int16_t degTargetHotend(uint8_t e) {
345 345
       #if HOTENDS == 1
346 346
         UNUSED(e);
347 347
       #endif
348 348
       return target_temperature[HOTEND_INDEX];
349 349
     }
350
-    static float degTargetBed() { return target_temperature_bed; }
350
+    static int16_t degTargetBed() { return target_temperature_bed; }
351 351
 
352 352
     #if WATCH_HOTENDS
353 353
       static void start_watching_heater(uint8_t e = 0);
@@ -357,14 +357,14 @@ class Temperature {
357 357
       static void start_watching_bed();
358 358
     #endif
359 359
 
360
-    static void setTargetHotend(const float& celsius, uint8_t e) {
360
+    static void setTargetHotend(const int16_t &celsius, uint8_t e) {
361 361
       #if HOTENDS == 1
362 362
         UNUSED(e);
363 363
       #endif
364 364
       #ifdef MILLISECONDS_PREHEAT_TIME
365
-        if (celsius == 0.0f)
365
+        if (celsius == 0)
366 366
           reset_preheat_time(HOTEND_INDEX);
367
-        else if (target_temperature[HOTEND_INDEX] == 0.0f)
367
+        else if (target_temperature[HOTEND_INDEX] == 0)
368 368
           start_preheat_time(HOTEND_INDEX);
369 369
       #endif
370 370
       target_temperature[HOTEND_INDEX] = celsius;
@@ -373,7 +373,7 @@ class Temperature {
373 373
       #endif
374 374
     }
375 375
 
376
-    static void setTargetBed(const float& celsius) {
376
+    static void setTargetBed(const int16_t &celsius) {
377 377
       target_temperature_bed = celsius;
378 378
       #if WATCH_THE_BED
379 379
         start_watching_bed();

+ 17
- 20
Marlin/ubl_G29.cpp View File

@@ -1522,10 +1522,8 @@
1522 1522
     if (isnan(ubl.z_values[x][y]) && !isnan(ubl.z_values[x1][y1]) && !isnan(ubl.z_values[x2][y2])) {
1523 1523
       if (ubl.z_values[x1][y1] < ubl.z_values[x2][y2])                  // Angled downward?
1524 1524
         ubl.z_values[x][y] = ubl.z_values[x1][y1];                      // Use nearest (maybe a little too high.)
1525
-      else {
1526
-        const float diff = ubl.z_values[x1][y1] - ubl.z_values[x2][y2]; // Angled upward
1527
-        ubl.z_values[x][y] = ubl.z_values[x1][y1] + diff;               // Use closest plus difference
1528
-      }
1525
+      else
1526
+        ubl.z_values[x][y] = 2.0 * ubl.z_values[x1][y1] - ubl.z_values[x2][y2];   // Angled upward...
1529 1527
       return true;
1530 1528
     }
1531 1529
     return false;
@@ -1533,21 +1531,6 @@
1533 1531
 
1534 1532
   typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
1535 1533
 
1536
-  void smart_fill_loop(const smart_fill_info &f) {
1537
-    if (f.yfirst) {
1538
-      const int8_t dir = f.ex > f.sx ? 1 : -1;
1539
-      for (uint8_t y = f.sy; y != f.ey; ++y)
1540
-        for (uint8_t x = f.sx; x != f.ex; x += dir)
1541
-          if (smart_fill_one(x, y, dir, 0)) break;
1542
-    }
1543
-    else {
1544
-      const int8_t dir = f.ey > f.sy ? 1 : -1;
1545
-       for (uint8_t x = f.sx; x != f.ex; ++x)
1546
-        for (uint8_t y = f.sy; y != f.ey; y += dir)
1547
-          if (smart_fill_one(x, y, 0, dir)) break;
1548
-    }
1549
-  }
1550
-
1551 1534
   void smart_fill_mesh() {
1552 1535
     const smart_fill_info info[] = {
1553 1536
       { 0, GRID_MAX_POINTS_X,      0, GRID_MAX_POINTS_Y - 2,  false },  // Bottom of the mesh looking up
@@ -1555,7 +1538,21 @@
1555 1538
       { 0, GRID_MAX_POINTS_X - 2,  0, GRID_MAX_POINTS_Y,      true  },  // Left side of the mesh looking right
1556 1539
       { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  }   // Right side of the mesh looking left
1557 1540
     };
1558
-    for (uint8_t i = 0; i < COUNT(info); ++i) smart_fill_loop(info[i]);
1541
+    for (uint8_t i = 0; i < COUNT(info); ++i) {
1542
+      const smart_fill_info &f = info[i];
1543
+      if (f.yfirst) {
1544
+        const int8_t dir = f.ex > f.sx ? 1 : -1;
1545
+        for (uint8_t y = f.sy; y != f.ey; ++y)
1546
+          for (uint8_t x = f.sx; x != f.ex; x += dir)
1547
+            if (smart_fill_one(x, y, dir, 0)) break;
1548
+      }
1549
+      else {
1550
+        const int8_t dir = f.ey > f.sy ? 1 : -1;
1551
+         for (uint8_t x = f.sx; x != f.ex; ++x)
1552
+          for (uint8_t y = f.sy; y != f.ey; y += dir)
1553
+            if (smart_fill_one(x, y, 0, dir)) break;
1554
+      }
1555
+    }
1559 1556
   }
1560 1557
 
1561 1558
   void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map) {

+ 2
- 2
Marlin/ultralcd.cpp View File

@@ -1179,14 +1179,14 @@ void kill_screen(const char* lcd_msg) {
1179 1179
     }
1180 1180
   #endif
1181 1181
 
1182
-  constexpr int heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
1182
+  constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
1183 1183
 
1184 1184
   /**
1185 1185
    *
1186 1186
    * "Prepare" submenu items
1187 1187
    *
1188 1188
    */
1189
-  void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
1189
+  void _lcd_preheat(const int endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
1190 1190
     if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
1191 1191
     #if TEMP_SENSOR_BED != 0
1192 1192
       if (tempb >= 0) thermalManager.setTargetBed(tempb);

Loading…
Cancel
Save