Browse Source

Extend SERIAL_CHAR to take multiple arguments

Scott Lahteine 4 years ago
parent
commit
95046c9047

+ 2
- 4
Marlin/src/HAL/HAL_AVR/pinsDebug.h View File

@@ -234,8 +234,7 @@ static void print_is_also_tied() { SERIAL_ECHOPGM(" is also tied to this pin");
234 234
 void com_print(uint8_t N, uint8_t Z) {
235 235
   const uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
236 236
   SERIAL_ECHOPGM("    COM");
237
-  SERIAL_CHAR('0' + N);
238
-  SERIAL_CHAR('A' + Z);
237
+  SERIAL_CHAR('0' + N, 'A' + Z);
239 238
   SERIAL_ECHOPAIR(": ", int((*TCCRA >> (6 - Z * 2)) & 0x03));
240 239
 }
241 240
 
@@ -247,8 +246,7 @@ void timer_prefix(uint8_t T, char L, uint8_t N) {  // T - timer    L - pwm  N -
247 246
   if (N == 4) WGM |= ((*TCCRB & _BV(WGM_3)) >> 1);
248 247
 
249 248
   SERIAL_ECHOPGM("    TIMER");
250
-  SERIAL_CHAR(T + '0');
251
-  SERIAL_CHAR(L);
249
+  SERIAL_CHAR(T + '0', L);
252 250
   SERIAL_ECHO_SP(3);
253 251
 
254 252
   if (N == 3) {

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

@@ -35,7 +35,7 @@ static bool UnwReportOut(void* ctx, const UnwReport* bte) {
35 35
 
36 36
   (*p)++;
37 37
 
38
-  SERIAL_CHAR('#'); SERIAL_PRINT(*p,DEC); SERIAL_ECHOPGM(" : ");
38
+  SERIAL_CHAR('#'); SERIAL_PRINT(*p, DEC); SERIAL_ECHOPGM(" : ");
39 39
   SERIAL_ECHOPGM(bte->name ? bte->name : "unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function, HEX);
40 40
   SERIAL_CHAR('+'); SERIAL_PRINT(bte->address - bte->function,DEC);
41 41
   SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address,HEX); SERIAL_CHAR('\n');

+ 16
- 1
Marlin/src/core/serial.h View File

@@ -66,7 +66,6 @@ extern uint8_t marlin_debug_flags;
66 66
 #define PORT_REDIRECT(p)        _PORT_REDIRECT(1,p)
67 67
 #define PORT_RESTORE()          _PORT_RESTORE(1)
68 68
 
69
-#define SERIAL_CHAR(x)          SERIAL_OUT(write, x)
70 69
 #define SERIAL_ECHO(x)          SERIAL_OUT(print, x)
71 70
 #define SERIAL_ECHO_F(V...)     SERIAL_OUT(print, V)
72 71
 #define SERIAL_ECHOLN(x)        SERIAL_OUT(println, x)
@@ -83,6 +82,22 @@ extern uint8_t marlin_debug_flags;
83 82
   #define SERIAL_FLUSHTX()
84 83
 #endif
85 84
 
85
+// Print up to 10 chars from a list
86
+#define __CHAR_N(N,V...)  _CHAR_##N(V)
87
+#define _CHAR_N(N,V...)   __CHAR_N(N,V)
88
+#define _CHAR_1(c)        SERIAL_OUT(write, c)
89
+#define _CHAR_2(a,b)      do{ _CHAR_1(a); _CHAR_1(b); }while(0)
90
+#define _CHAR_3(a,V...)   do{ _CHAR_1(a); _CHAR_2(V); }while(0)
91
+#define _CHAR_4(a,V...)   do{ _CHAR_1(a); _CHAR_3(V); }while(0)
92
+#define _CHAR_5(a,V...)   do{ _CHAR_1(a); _CHAR_4(V); }while(0)
93
+#define _CHAR_6(a,V...)   do{ _CHAR_1(a); _CHAR_5(V); }while(0)
94
+#define _CHAR_7(a,V...)   do{ _CHAR_1(a); _CHAR_6(V); }while(0)
95
+#define _CHAR_8(a,V...)   do{ _CHAR_1(a); _CHAR_7(V); }while(0)
96
+#define _CHAR_9(a,V...)   do{ _CHAR_1(a); _CHAR_8(V); }while(0)
97
+#define _CHAR_10(a,V...)  do{ _CHAR_1(a); _CHAR_9(V); }while(0)
98
+
99
+#define SERIAL_CHAR(V...) _CHAR_N(NUM_ARGS(V),V)
100
+
86 101
 // Print up to 12 pairs of values. Odd elements auto-wrapped in PSTR().
87 102
 #define __SEP_N(N,V...)   _SEP_##N(V)
88 103
 #define _SEP_N(N,V...)    __SEP_N(N,V)

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

@@ -148,8 +148,7 @@ void safe_delay(millis_t ms) {
148 148
           SERIAL_ECHOPGM("ABL Adjustment X");
149 149
           LOOP_XYZ(a) {
150 150
             float v = planner.get_axis_position_mm(AxisEnum(a)) - current_position[a];
151
-            SERIAL_CHAR(' ');
152
-            SERIAL_CHAR('X' + char(a));
151
+            SERIAL_CHAR(' ', 'X' + char(a));
153 152
             if (v > 0) SERIAL_CHAR('+');
154 153
             SERIAL_ECHO(v);
155 154
           }

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

@@ -207,8 +207,7 @@ void reset_bed_level() {
207 207
         #endif
208 208
       }
209 209
       #ifdef SCAD_MESH_OUTPUT
210
-        SERIAL_CHAR(' ');
211
-        SERIAL_CHAR(']');                     // close sub-array
210
+        SERIAL_CHAR(' ', ']');                    // close sub-array
212 211
         if (y < sy - 1) SERIAL_CHAR(',');
213 212
       #endif
214 213
       SERIAL_EOL();

+ 1
- 1
Marlin/src/feature/runout.h View File

@@ -213,7 +213,7 @@ class FilamentSensorBase {
213 213
           if (change) {
214 214
             SERIAL_ECHOPGM("Motion detected:");
215 215
             for (uint8_t e = 0; e < NUM_RUNOUT_SENSORS; e++)
216
-              if (TEST(change, e)) { SERIAL_CHAR(' '); SERIAL_CHAR('0' + e); }
216
+              if (TEST(change, e)) SERIAL_CHAR(' ', '0' + e);
217 217
             SERIAL_EOL();
218 218
           }
219 219
         #endif

+ 3
- 3
Marlin/src/gcode/calibrate/M100.cpp View File

@@ -238,12 +238,12 @@ inline int check_for_free_memory_corruption(PGM_P const title) {
238 238
     SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
239 239
 
240 240
   if (block_cnt == 0)       // Make sure the special case of no free blocks shows up as an
241
-    block_cnt = -1;         // error to the calling code!
241
+    block_cnt = -1;         //  error to the calling code!
242 242
 
243 243
   SERIAL_ECHOPGM(" return=");
244 244
   if (block_cnt == 1) {
245
-    SERIAL_CHAR('0');       // if the block_cnt is 1, nothing has broken up the free memory
246
-    SERIAL_EOL();             // area and it is appropriate to say 'no corruption'.
245
+    SERIAL_CHAR('0');       // If the block_cnt is 1, nothing has broken up the free memory
246
+    SERIAL_EOL();           //  area and it is appropriate to say 'no corruption'.
247 247
     return 0;
248 248
   }
249 249
   SERIAL_ECHOLNPGM("true");

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

@@ -75,8 +75,7 @@ void GcodeSuite::M425() {
75 75
     SERIAL_ECHOLNPAIR("  Correction Amount/Fade-out:     F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)");
76 76
     SERIAL_ECHOPGM("  Backlash Distance (mm):        ");
77 77
     LOOP_XYZ(a) {
78
-      SERIAL_CHAR(' ');
79
-      SERIAL_CHAR(axis_codes[a]);
78
+      SERIAL_CHAR(' ', axis_codes[a]);
80 79
       SERIAL_ECHO(backlash.distance_mm[a]);
81 80
       SERIAL_EOL();
82 81
     }
@@ -89,8 +88,7 @@ void GcodeSuite::M425() {
89 88
       SERIAL_ECHOPGM("  Average measured backlash (mm):");
90 89
       if (backlash.has_any_measurement()) {
91 90
         LOOP_XYZ(a) if (backlash.has_measurement(AxisEnum(a))) {
92
-          SERIAL_CHAR(' ');
93
-          SERIAL_CHAR(axis_codes[a]);
91
+          SERIAL_CHAR(' ', axis_codes[a]);
94 92
           SERIAL_ECHO(backlash.get_measurement(AxisEnum(a)));
95 93
         }
96 94
       }

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

@@ -39,8 +39,7 @@ void GcodeSuite::M221() {
39 39
   }
40 40
   else {
41 41
     SERIAL_ECHO_START();
42
-    SERIAL_CHAR('E');
43
-    SERIAL_CHAR('0' + target_extruder);
42
+    SERIAL_CHAR('E', '0' + target_extruder);
44 43
     SERIAL_ECHOPAIR(" Flow: ", planner.flow_percentage[target_extruder]);
45 44
     SERIAL_CHAR('%');
46 45
     SERIAL_EOL();

+ 3
- 9
Marlin/src/gcode/host/M114.cpp View File

@@ -39,9 +39,7 @@
39 39
   void report_xyze(const xyze_pos_t &pos, const uint8_t n=4, const uint8_t precision=3) {
40 40
     char str[12];
41 41
     for (uint8_t a = 0; a < n; a++) {
42
-      SERIAL_CHAR(' ');
43
-      SERIAL_CHAR(axis_codes[a]);
44
-      SERIAL_CHAR(':');
42
+      SERIAL_CHAR(' ', axis_codes[a], ':');
45 43
       SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
46 44
     }
47 45
     SERIAL_EOL();
@@ -50,9 +48,7 @@
50 48
   void report_xyz(const xyz_pos_t &pos, const uint8_t precision=3) {
51 49
     char str[12];
52 50
     for (uint8_t a = X_AXIS; a <= Z_AXIS; a++) {
53
-      SERIAL_CHAR(' ');
54
-      SERIAL_CHAR(axis_codes[a]);
55
-      SERIAL_CHAR(':');
51
+      SERIAL_CHAR(' ', axis_codes[a], ':');
56 52
       SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
57 53
     }
58 54
     SERIAL_EOL();
@@ -150,9 +146,7 @@
150 146
 
151 147
     SERIAL_ECHOPGM("Stepper:");
152 148
     LOOP_XYZE(i) {
153
-      SERIAL_CHAR(' ');
154
-      SERIAL_CHAR(axis_codes[i]);
155
-      SERIAL_CHAR(':');
149
+      SERIAL_CHAR(' ', axis_codes[i], ':');
156 150
       SERIAL_ECHO(stepper.position((AxisEnum)i));
157 151
     }
158 152
     SERIAL_EOL();

+ 1
- 1
Marlin/src/gcode/parser.cpp View File

@@ -346,7 +346,7 @@ void GCodeParser::unknown_command_error() {
346 346
     SERIAL_ECHOLNPGM(")");
347 347
     #if ENABLED(FASTER_GCODE_PARSER)
348 348
       SERIAL_ECHOPGM(" args: { ");
349
-      for (char c = 'A'; c <= 'Z'; ++c) if (seen(c)) { SERIAL_CHAR(c); SERIAL_CHAR(' '); }
349
+      for (char c = 'A'; c <= 'Z'; ++c) if (seen(c)) SERIAL_CHAR(c, ' ');
350 350
       SERIAL_CHAR('}');
351 351
     #else
352 352
       SERIAL_ECHOPAIR(" args: { ", command_args, " }");

+ 1
- 4
Marlin/src/libs/L6470/L6470_Marlin.cpp View File

@@ -539,10 +539,7 @@ bool L6470_Marlin::get_user_input(uint8_t &driver_count, uint8_t axis_index[3],
539 539
 
540 540
 void L6470_Marlin::say_axis(const uint8_t axis, const bool label/*=true*/) {
541 541
   if (label) SERIAL_ECHOPGM("AXIS:");
542
-  SERIAL_CHAR(' ');
543
-  SERIAL_CHAR(index_to_axis[axis][0]);
544
-  SERIAL_CHAR(index_to_axis[axis][1]);
545
-  SERIAL_CHAR(' ');
542
+  SERIAL_CHAR(' ', index_to_axis[axis][0], index_to_axis[axis][1], ' ');
546 543
 }
547 544
 
548 545
 void L6470_Marlin::error_status_decode(const uint16_t status, const uint8_t axis) {  // assumes status bits have been inverted

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

@@ -471,7 +471,7 @@ void _O2 Endstops::report_states() {
471 471
           #endif
472 472
         }
473 473
         SERIAL_ECHOPGM(MSG_FILAMENT_RUNOUT_SENSOR);
474
-        if (i > 1) { SERIAL_CHAR(' '); SERIAL_CHAR('0' + i); }
474
+        if (i > 1) SERIAL_CHAR(' ', '0' + i);
475 475
         print_es_state(extDigitalRead(pin) != FIL_RUNOUT_INVERTING);
476 476
       }
477 477
     #endif

+ 47
- 46
Marlin/src/module/stepper.cpp View File

@@ -2932,77 +2932,78 @@ void Stepper::report_positions() {
2932 2932
   }
2933 2933
 
2934 2934
   void Stepper::microstep_readings() {
2935
-    SERIAL_ECHOPGM("MS1,MS2,MS3 Pins\nX: ");
2935
+    SERIAL_ECHOLNPGM("MS1|MS2|MS3 Pins");
2936 2936
     #if HAS_X_MICROSTEPS
2937
-      SERIAL_CHAR('0' + READ(X_MS1_PIN));
2938
-      SERIAL_CHAR('0' + READ(X_MS2_PIN));
2939
-      #if PIN_EXISTS(X_MS3)
2940
-        SERIAL_ECHOLN((int)READ(X_MS3_PIN));
2941
-      #endif
2937
+      SERIAL_ECHOPGM("X: ");
2938
+      SERIAL_CHAR('0' + READ(X_MS1_PIN), '0' + READ(X_MS2_PIN)
2939
+        #if PIN_EXISTS(X_MS3)
2940
+          , '0' + READ(X_MS3_PIN)
2941
+        #endif
2942
+      );
2942 2943
     #endif
2943 2944
     #if HAS_Y_MICROSTEPS
2944 2945
       SERIAL_ECHOPGM("Y: ");
2945
-      SERIAL_CHAR('0' + READ(Y_MS1_PIN));
2946
-      SERIAL_CHAR('0' + READ(Y_MS2_PIN));
2947
-      #if PIN_EXISTS(Y_MS3)
2948
-        SERIAL_ECHOLN((int)READ(Y_MS3_PIN));
2949
-      #endif
2946
+      SERIAL_CHAR('0' + READ(Y_MS1_PIN), '0' + READ(Y_MS2_PIN)
2947
+        #if PIN_EXISTS(Y_MS3)
2948
+          , '0' + READ(Y_MS3_PIN)
2949
+        #endif
2950
+      );
2950 2951
     #endif
2951 2952
     #if HAS_Z_MICROSTEPS
2952 2953
       SERIAL_ECHOPGM("Z: ");
2953
-      SERIAL_CHAR('0' + READ(Z_MS1_PIN));
2954
-      SERIAL_CHAR('0' + READ(Z_MS2_PIN));
2955
-      #if PIN_EXISTS(Z_MS3)
2956
-        SERIAL_ECHOLN((int)READ(Z_MS3_PIN));
2957
-      #endif
2954
+      SERIAL_CHAR('0' + READ(Z_MS1_PIN), '0' + READ(Z_MS2_PIN)
2955
+        #if PIN_EXISTS(Z_MS3)
2956
+          , '0' + READ(Z_MS3_PIN)
2957
+        #endif
2958
+      );
2958 2959
     #endif
2959 2960
     #if HAS_E0_MICROSTEPS
2960 2961
       SERIAL_ECHOPGM("E0: ");
2961
-      SERIAL_CHAR('0' + READ(E0_MS1_PIN));
2962
-      SERIAL_CHAR('0' + READ(E0_MS2_PIN));
2963
-      #if PIN_EXISTS(E0_MS3)
2964
-        SERIAL_ECHOLN((int)READ(E0_MS3_PIN));
2965
-      #endif
2962
+      SERIAL_CHAR('0' + READ(E0_MS1_PIN), '0' + READ(E0_MS2_PIN)
2963
+        #if PIN_EXISTS(E0_MS3)
2964
+          , '0' + READ(E0_MS3_PIN)
2965
+        #endif
2966
+      );
2966 2967
     #endif
2967 2968
     #if HAS_E1_MICROSTEPS
2968 2969
       SERIAL_ECHOPGM("E1: ");
2969
-      SERIAL_CHAR('0' + READ(E1_MS1_PIN));
2970
-      SERIAL_CHAR('0' + READ(E1_MS2_PIN));
2971
-      #if PIN_EXISTS(E1_MS3)
2972
-        SERIAL_ECHOLN((int)READ(E1_MS3_PIN));
2973
-      #endif
2970
+      SERIAL_CHAR('0' + READ(E1_MS1_PIN), '0' + READ(E1_MS2_PIN)
2971
+        #if PIN_EXISTS(E1_MS3)
2972
+          , '0' + READ(E1_MS3_PIN)
2973
+        #endif
2974
+      );
2974 2975
     #endif
2975 2976
     #if HAS_E2_MICROSTEPS
2976 2977
       SERIAL_ECHOPGM("E2: ");
2977
-      SERIAL_CHAR('0' + READ(E2_MS1_PIN));
2978
-      SERIAL_CHAR('0' + READ(E2_MS2_PIN));
2979
-      #if PIN_EXISTS(E2_MS3)
2980
-        SERIAL_ECHOLN((int)READ(E2_MS3_PIN));
2981
-      #endif
2978
+      SERIAL_CHAR('0' + READ(E2_MS1_PIN), '0' + READ(E2_MS2_PIN)
2979
+        #if PIN_EXISTS(E2_MS3)
2980
+          , '0' + READ(E2_MS3_PIN)
2981
+        #endif
2982
+      );
2982 2983
     #endif
2983 2984
     #if HAS_E3_MICROSTEPS
2984 2985
       SERIAL_ECHOPGM("E3: ");
2985
-      SERIAL_CHAR('0' + READ(E3_MS1_PIN));
2986
-      SERIAL_CHAR('0' + READ(E3_MS2_PIN));
2987
-      #if PIN_EXISTS(E3_MS3)
2988
-        SERIAL_ECHOLN((int)READ(E3_MS3_PIN));
2989
-      #endif
2986
+      SERIAL_CHAR('0' + READ(E3_MS1_PIN), '0' + READ(E3_MS2_PIN)
2987
+        #if PIN_EXISTS(E3_MS3)
2988
+          , '0' + READ(E3_MS3_PIN)
2989
+        #endif
2990
+      );
2990 2991
     #endif
2991 2992
     #if HAS_E4_MICROSTEPS
2992 2993
       SERIAL_ECHOPGM("E4: ");
2993
-      SERIAL_CHAR('0' + READ(E4_MS1_PIN));
2994
-      SERIAL_CHAR('0' + READ(E4_MS2_PIN));
2995
-      #if PIN_EXISTS(E4_MS3)
2996
-        SERIAL_ECHOLN((int)READ(E4_MS3_PIN));
2997
-      #endif
2994
+      SERIAL_CHAR('0' + READ(E4_MS1_PIN), '0' + READ(E4_MS2_PIN)
2995
+        #if PIN_EXISTS(E4_MS3)
2996
+          , '0' + READ(E4_MS3_PIN)
2997
+        #endif
2998
+      );
2998 2999
     #endif
2999 3000
     #if HAS_E5_MICROSTEPS
3000 3001
       SERIAL_ECHOPGM("E5: ");
3001
-      SERIAL_CHAR('0' + READ(E5_MS1_PIN));
3002
-      SERIAL_ECHOLN((int)READ(E5_MS2_PIN));
3003
-      #if PIN_EXISTS(E5_MS3)
3004
-        SERIAL_ECHOLN((int)READ(E5_MS3_PIN));
3005
-      #endif
3002
+      SERIAL_CHAR('0' + READ(E5_MS1_PIN), '0' + READ(E5_MS2_PIN)
3003
+        #if PIN_EXISTS(E5_MS3)
3004
+          , '0' + READ(E5_MS3_PIN)
3005
+        #endif
3006
+      );
3006 3007
     #endif
3007 3008
   }
3008 3009
 

Loading…
Cancel
Save