Browse Source

Add SERIAL_FLOAT_PRECISION option (#18367)

Fabio Santos 4 years ago
parent
commit
25c7c43a82
No account linked to committer's email address

+ 3
- 0
Marlin/Configuration_adv.h View File

1901
 // This option inserts short delays between lines of serial output.
1901
 // This option inserts short delays between lines of serial output.
1902
 #define SERIAL_OVERRUN_PROTECTION
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
 // @section extras
1907
 // @section extras
1905
 
1908
 
1906
 /**
1909
 /**

+ 1
- 1
Marlin/src/MarlinCore.cpp View File

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

+ 3
- 0
Marlin/src/core/debug_out.h View File

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

+ 1
- 1
Marlin/src/core/macros.h View File

270
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
270
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
271
 
271
 
272
 #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0 : (1 / float(x)))
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
 // Maths macros that can be overridden by HAL
276
 // Maths macros that can be overridden by HAL

+ 2
- 2
Marlin/src/core/serial.cpp View File

42
 void serial_echopair_PGM(PGM_P const s_P, char v)          { serialprintPGM(s_P); SERIAL_CHAR(v); }
42
 void serial_echopair_PGM(PGM_P const s_P, char v)          { serialprintPGM(s_P); SERIAL_CHAR(v); }
43
 void serial_echopair_PGM(PGM_P const s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
43
 void serial_echopair_PGM(PGM_P const s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
44
 void serial_echopair_PGM(PGM_P const s_P, long v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
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
 void serial_echopair_PGM(PGM_P const s_P, unsigned int v)  { serialprintPGM(s_P); SERIAL_ECHO(v); }
47
 void serial_echopair_PGM(PGM_P const s_P, unsigned int v)  { serialprintPGM(s_P); SERIAL_ECHO(v); }
48
 void serial_echopair_PGM(PGM_P const s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
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 View File

286
 
286
 
287
 #define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
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
 // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
296
 // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
291
 //
297
 //

+ 2
- 2
Marlin/src/core/utility.cpp View File

123
         #if ABL_PLANAR
123
         #if ABL_PLANAR
124
           SERIAL_ECHOPGM("ABL Adjustment X");
124
           SERIAL_ECHOPGM("ABL Adjustment X");
125
           LOOP_XYZ(a) {
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
             SERIAL_CHAR(' ', XYZ_CHAR(a));
127
             SERIAL_CHAR(' ', XYZ_CHAR(a));
128
             if (v > 0) SERIAL_CHAR('+');
128
             if (v > 0) SERIAL_CHAR('+');
129
-            SERIAL_ECHO(v);
129
+            SERIAL_DECIMAL(v);
130
           }
130
           }
131
         #else
131
         #else
132
           #if ENABLED(AUTO_BED_LEVELING_UBL)
132
           #if ENABLED(AUTO_BED_LEVELING_UBL)

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

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

+ 1
- 1
Marlin/src/feature/encoder_i2c.cpp View File

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

+ 2
- 2
Marlin/src/feature/encoder_i2c.h View File

280
     static void set_ec_threshold(const int8_t idx, const float newThreshold, const AxisEnum axis) {
280
     static void set_ec_threshold(const int8_t idx, const float newThreshold, const AxisEnum axis) {
281
       CHECK_IDX();
281
       CHECK_IDX();
282
       encoders[idx].set_ec_threshold(newThreshold);
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
     static void get_ec_threshold(const int8_t idx, const AxisEnum axis) {
286
     static void get_ec_threshold(const int8_t idx, const AxisEnum axis) {
287
       CHECK_IDX();
287
       CHECK_IDX();
288
       const float threshold = encoders[idx].get_ec_threshold();
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
     static int8_t idx_from_axis(const AxisEnum axis) {
292
     static int8_t idx_from_axis(const AxisEnum axis) {

+ 3
- 3
Marlin/src/feature/powerloss.cpp View File

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

+ 1
- 1
Marlin/src/gcode/config/M92.cpp View File

105
       if (wanted) {
105
       if (wanted) {
106
         const float best = uint16_t(wanted / z_full_step_mm) * z_full_step_mm;
106
         const float best = uint16_t(wanted / z_full_step_mm) * z_full_step_mm;
107
         SERIAL_ECHOPAIR(", best:[", best);
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
         SERIAL_CHAR(']');
109
         SERIAL_CHAR(']');
110
       }
110
       }
111
       SERIAL_ECHOLNPGM(" }");
111
       SERIAL_ECHOLNPGM(" }");

+ 1
- 1
Marlin/src/gcode/feature/advance/M900.cpp View File

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

+ 1
- 1
Marlin/src/gcode/probe/G30.cpp View File

53
   const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
53
   const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
54
   const float measured_z = probe.probe_at_point(pos, raise_after, 1);
54
   const float measured_z = probe.probe_at_point(pos, raise_after, 1);
55
   if (!isnan(measured_z))
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
   restore_feedrate_and_scaling();
58
   restore_feedrate_and_scaling();
59
 
59
 

+ 2
- 5
Marlin/src/module/probe.cpp View File

715
     else if (raise_after == PROBE_PT_STOW)
715
     else if (raise_after == PROBE_PT_STOW)
716
       if (stow()) measured_z = NAN;   // Error on stow?
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
   feedrate_mm_s = old_feedrate_mm_s;
722
   feedrate_mm_s = old_feedrate_mm_s;

Loading…
Cancel
Save