Просмотр исходного кода

Add SERIAL_FLOAT_PRECISION option (#18367)

Fabio Santos 4 лет назад
Родитель
Сommit
25c7c43a82
Аккаунт пользователя с таким Email не найден

+ 3
- 0
Marlin/Configuration_adv.h Просмотреть файл

@@ -1901,6 +1901,9 @@
1901 1901
 // This option inserts short delays between lines of serial output.
1902 1902
 #define SERIAL_OVERRUN_PROTECTION
1903 1903
 
1904
+// For serial echo, the number of digits after the decimal point
1905
+//#define SERIAL_FLOAT_PRECISION 4
1906
+
1904 1907
 // @section extras
1905 1908
 
1906 1909
 /**

+ 1
- 1
Marlin/src/MarlinCore.cpp Просмотреть файл

@@ -857,7 +857,7 @@ void setup() {
857 857
   #if ENABLED(MARLIN_DEV_MODE)
858 858
     auto log_current_ms = [&](PGM_P const msg) {
859 859
       SERIAL_ECHO_START();
860
-      SERIAL_CHAR('['); SERIAL_ECHO(millis()); SERIAL_ECHO("] ");
860
+      SERIAL_CHAR('['); SERIAL_ECHO(millis()); SERIAL_ECHOPGM("] ");
861 861
       serialprintPGM(msg);
862 862
       SERIAL_EOL();
863 863
     };

+ 3
- 0
Marlin/src/core/debug_out.h Просмотреть файл

@@ -31,6 +31,7 @@
31 31
 #undef DEBUG_ERROR_START
32 32
 #undef DEBUG_CHAR
33 33
 #undef DEBUG_ECHO
34
+#undef DEBUG_DECIMAL
34 35
 #undef DEBUG_ECHO_F
35 36
 #undef DEBUG_ECHOLN
36 37
 #undef DEBUG_ECHOPGM
@@ -57,6 +58,7 @@
57 58
   #define DEBUG_ERROR_START       SERIAL_ERROR_START
58 59
   #define DEBUG_CHAR              SERIAL_CHAR
59 60
   #define DEBUG_ECHO              SERIAL_ECHO
61
+  #define DEBUG_DECIMAL           SERIAL_DECIMAL
60 62
   #define DEBUG_ECHO_F            SERIAL_ECHO_F
61 63
   #define DEBUG_ECHOLN            SERIAL_ECHOLN
62 64
   #define DEBUG_ECHOPGM           SERIAL_ECHOPGM
@@ -82,6 +84,7 @@
82 84
   #define DEBUG_ERROR_START()       NOOP
83 85
   #define DEBUG_CHAR(...)           NOOP
84 86
   #define DEBUG_ECHO(...)           NOOP
87
+  #define DEBUG_DECIMAL(...)        NOOP
85 88
   #define DEBUG_ECHO_F(...)         NOOP
86 89
   #define DEBUG_ECHOLN(...)         NOOP
87 90
   #define DEBUG_ECHOPGM(...)        NOOP

+ 1
- 1
Marlin/src/core/macros.h Просмотреть файл

@@ -270,7 +270,7 @@
270 270
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
271 271
 
272 272
 #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0 : (1 / float(x)))
273
-#define FIXFLOAT(f)  ({__typeof__(f) _f = (f); _f + (_f < 0 ? -0.00005f : 0.00005f);})
273
+#define FIXFLOAT(f)  ({__typeof__(f) _f = (f); _f + (_f < 0 ? -0.0000005f : 0.0000005f);})
274 274
 
275 275
 //
276 276
 // Maths macros that can be overridden by HAL

+ 2
- 2
Marlin/src/core/serial.cpp Просмотреть файл

@@ -42,8 +42,8 @@ void serial_echopair_PGM(PGM_P const s_P, const char *v)   { serialprintPGM(s_P)
42 42
 void serial_echopair_PGM(PGM_P const s_P, char v)          { serialprintPGM(s_P); SERIAL_CHAR(v); }
43 43
 void serial_echopair_PGM(PGM_P const s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
44 44
 void serial_echopair_PGM(PGM_P const s_P, long v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
45
-void serial_echopair_PGM(PGM_P const s_P, float v)         { serialprintPGM(s_P); SERIAL_ECHO(v); }
46
-void serial_echopair_PGM(PGM_P const s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
45
+void serial_echopair_PGM(PGM_P const s_P, float v)         { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
46
+void serial_echopair_PGM(PGM_P const s_P, double v)        { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
47 47
 void serial_echopair_PGM(PGM_P const s_P, unsigned int v)  { serialprintPGM(s_P); SERIAL_ECHO(v); }
48 48
 void serial_echopair_PGM(PGM_P const s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
49 49
 

+ 6
- 0
Marlin/src/core/serial.h Просмотреть файл

@@ -286,6 +286,12 @@ extern uint8_t marlin_debug_flags;
286 286
 
287 287
 #define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
288 288
 
289
+#if SERIAL_FLOAT_PRECISION
290
+  #define SERIAL_DECIMAL(V) SERIAL_PRINT(V, SERIAL_FLOAT_PRECISION)
291
+#else
292
+  #define SERIAL_DECIMAL(V) SERIAL_ECHO(V)
293
+#endif
294
+
289 295
 //
290 296
 // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
291 297
 //

+ 2
- 2
Marlin/src/core/utility.cpp Просмотреть файл

@@ -123,10 +123,10 @@ void safe_delay(millis_t ms) {
123 123
         #if ABL_PLANAR
124 124
           SERIAL_ECHOPGM("ABL Adjustment X");
125 125
           LOOP_XYZ(a) {
126
-            float v = planner.get_axis_position_mm(AxisEnum(a)) - current_position[a];
126
+            const float v = planner.get_axis_position_mm(AxisEnum(a)) - current_position[a];
127 127
             SERIAL_CHAR(' ', XYZ_CHAR(a));
128 128
             if (v > 0) SERIAL_CHAR('+');
129
-            SERIAL_ECHO(v);
129
+            SERIAL_DECIMAL(v);
130 130
           }
131 131
         #else
132 132
           #if ENABLED(AUTO_BED_LEVELING_UBL)

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Просмотреть файл

@@ -433,7 +433,7 @@
433 433
             if (g29_verbose_level > 1) {
434 434
               SERIAL_ECHOPAIR("Probing around (", g29_pos.x);
435 435
               SERIAL_CHAR(',');
436
-              SERIAL_ECHO(g29_pos.y);
436
+              SERIAL_DECIMAL(g29_pos.y);
437 437
               SERIAL_ECHOLNPGM(").\n");
438 438
             }
439 439
             const xy_pos_t near_probe_xy = g29_pos + probe.offset_xy;

+ 1
- 1
Marlin/src/feature/encoder_i2c.cpp Просмотреть файл

@@ -107,7 +107,7 @@ void I2CPositionEncoder::update() {
107 107
           SERIAL_ECHOLNPAIR("New zero-offset of ", zeroOffset);
108 108
           SERIAL_ECHOPAIR("New position reads as ", get_position());
109 109
           SERIAL_CHAR('(');
110
-          SERIAL_ECHO(mm_from_count(get_position()));
110
+          SERIAL_DECIMAL(mm_from_count(get_position()));
111 111
           SERIAL_ECHOLNPGM(")");
112 112
         #endif
113 113
       }

+ 2
- 2
Marlin/src/feature/encoder_i2c.h Просмотреть файл

@@ -280,13 +280,13 @@ class I2CPositionEncodersMgr {
280 280
     static void set_ec_threshold(const int8_t idx, const float newThreshold, const AxisEnum axis) {
281 281
       CHECK_IDX();
282 282
       encoders[idx].set_ec_threshold(newThreshold);
283
-      SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis set to ", FIXFLOAT(newThreshold), "mm.");
283
+      SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis set to ", newThreshold, "mm.");
284 284
     }
285 285
 
286 286
     static void get_ec_threshold(const int8_t idx, const AxisEnum axis) {
287 287
       CHECK_IDX();
288 288
       const float threshold = encoders[idx].get_ec_threshold();
289
-      SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis is ", FIXFLOAT(threshold), "mm.");
289
+      SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis is ", threshold, "mm.");
290 290
     }
291 291
 
292 292
     static int8_t idx_from_axis(const AxisEnum axis) {

+ 3
- 3
Marlin/src/feature/powerloss.cpp Просмотреть файл

@@ -472,7 +472,7 @@ void PrintJobRecovery::resume() {
472 472
         DEBUG_ECHOPGM("current_position: ");
473 473
         LOOP_XYZE(i) {
474 474
           if (i) DEBUG_CHAR(',');
475
-          DEBUG_ECHO(info.current_position[i]);
475
+          DEBUG_DECIMAL(info.current_position[i]);
476 476
         }
477 477
         DEBUG_EOL();
478 478
 
@@ -480,7 +480,7 @@ void PrintJobRecovery::resume() {
480 480
           DEBUG_ECHOPGM("home_offset: ");
481 481
           LOOP_XYZ(i) {
482 482
             if (i) DEBUG_CHAR(',');
483
-            DEBUG_ECHO(info.home_offset[i]);
483
+            DEBUG_DECIMAL(info.home_offset[i]);
484 484
           }
485 485
           DEBUG_EOL();
486 486
         #endif
@@ -489,7 +489,7 @@ void PrintJobRecovery::resume() {
489 489
           DEBUG_ECHOPGM("position_shift: ");
490 490
           LOOP_XYZ(i) {
491 491
             if (i) DEBUG_CHAR(',');
492
-            DEBUG_ECHO(info.position_shift[i]);
492
+            DEBUG_DECIMAL(info.position_shift[i]);
493 493
           }
494 494
           DEBUG_EOL();
495 495
         #endif

+ 1
- 1
Marlin/src/gcode/config/M92.cpp Просмотреть файл

@@ -105,7 +105,7 @@ void GcodeSuite::M92() {
105 105
       if (wanted) {
106 106
         const float best = uint16_t(wanted / z_full_step_mm) * z_full_step_mm;
107 107
         SERIAL_ECHOPAIR(", best:[", best);
108
-        if (best != wanted) { SERIAL_CHAR(','); SERIAL_ECHO(best + z_full_step_mm); }
108
+        if (best != wanted) { SERIAL_CHAR(','); SERIAL_DECIMAL(best + z_full_step_mm); }
109 109
         SERIAL_CHAR(']');
110 110
       }
111 111
       SERIAL_ECHOLNPGM(" }");

+ 1
- 1
Marlin/src/gcode/feature/advance/M900.cpp Просмотреть файл

@@ -134,7 +134,7 @@ void GcodeSuite::M900() {
134 134
         SERIAL_ECHOPGM("Advance K");
135 135
         LOOP_L_N(i, EXTRUDERS) {
136 136
           SERIAL_CHAR(' ', '0' + i, ':');
137
-          SERIAL_ECHO(planner.extruder_advance_K[i]);
137
+          SERIAL_DECIMAL(planner.extruder_advance_K[i]);
138 138
         }
139 139
         SERIAL_EOL();
140 140
       #endif

+ 1
- 1
Marlin/src/gcode/probe/G30.cpp Просмотреть файл

@@ -53,7 +53,7 @@ void GcodeSuite::G30() {
53 53
   const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
54 54
   const float measured_z = probe.probe_at_point(pos, raise_after, 1);
55 55
   if (!isnan(measured_z))
56
-    SERIAL_ECHOLNPAIR("Bed X: ", FIXFLOAT(pos.x), " Y: ", FIXFLOAT(pos.y), " Z: ", FIXFLOAT(measured_z));
56
+    SERIAL_ECHOLNPAIR("Bed X: ", pos.x, " Y: ", pos.y, " Z: ", measured_z);
57 57
 
58 58
   restore_feedrate_and_scaling();
59 59
 

+ 2
- 5
Marlin/src/module/probe.cpp Просмотреть файл

@@ -715,11 +715,8 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise
715 715
     else if (raise_after == PROBE_PT_STOW)
716 716
       if (stow()) measured_z = NAN;   // Error on stow?
717 717
 
718
-    if (verbose_level > 2) {
719
-      SERIAL_ECHOPAIR_F("Bed X: ", LOGICAL_X_POSITION(rx), 3);
720
-      SERIAL_ECHOPAIR_F(   " Y: ", LOGICAL_Y_POSITION(ry), 3);
721
-      SERIAL_ECHOLNPAIR_F( " Z: ", measured_z, 3);
722
-    }
718
+    if (verbose_level > 2)
719
+      SERIAL_ECHOLNPAIR("Bed X: ", LOGICAL_X_POSITION(rx), " Y: ", LOGICAL_Y_POSITION(ry), " Z: ", measured_z);
723 720
   }
724 721
 
725 722
   feedrate_mm_s = old_feedrate_mm_s;

Загрузка…
Отмена
Сохранить