Skip to content

Commit 0916d32

Browse files
committed
πŸ§‘β€πŸ’» Serial ON_OFF, TRUE_FALSE
1 parent af7b126 commit 0916d32

File tree

15 files changed

+45
-62
lines changed

15 files changed

+45
-62
lines changed

β€ŽMarlin/src/core/serial.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ void serial_ternary(FSTR_P const pre, const bool onoff, FSTR_P const on, FSTR_P
114114
if (post) SERIAL_ECHO(post);
115115
}
116116

117-
void serialprint_onoff(const bool onoff) { SERIAL_ECHO(onoff ? F(STR_ON) : F(STR_OFF)); }
118-
void serialprintln_onoff(const bool onoff) { serialprint_onoff(onoff); SERIAL_EOL(); }
119-
void serialprint_truefalse(const bool tf) { SERIAL_ECHO(tf ? F("true") : F("false")); }
120-
121117
void print_bin(uint16_t val) {
122118
for (uint8_t i = 16; i--;) {
123119
SERIAL_CHAR('0' + TEST(val, i));

β€ŽMarlin/src/core/serial.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ void serial_ternary(FSTR_P const pre, const bool onoff, FSTR_P const on, FSTR_P
233233
// Print up to 255 spaces
234234
void SERIAL_ECHO_SP(uint8_t count);
235235

236-
void serialprint_onoff(const bool onoff);
237-
void serialprintln_onoff(const bool onoff);
238-
void serialprint_truefalse(const bool tf);
236+
inline FSTR_P const ON_OFF(const bool onoff) { return onoff ? F("ON") : F("OFF"); }
237+
inline FSTR_P const TRUE_FALSE(const bool tf) { return tf ? F("true") : F("false"); }
238+
239239
void serial_offset(const_float_t v, const uint8_t sp=0); // For v==0 draw space (sp==1) or plus (sp==2)
240240

241241
void print_bin(const uint16_t val);

β€ŽMarlin/src/feature/meatpack.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@ void MeatPack::handle_command(const MeatPack_Command c) {
169169
void MeatPack::report_state() {
170170
// NOTE: if any configuration vars are added below, the outgoing sync text for host plugin
171171
// should not contain the "PV' substring, as this is used to indicate protocol version
172-
SERIAL_ECHOPGM("[MP] " MeatPack_ProtocolVersion " ");
173-
serialprint_onoff(TEST(state, MPConfig_Bit_Active));
174-
SERIAL_ECHO(TEST(state, MPConfig_Bit_NoSpaces) ? F(" NSP\n") : F(" ESP\n"));
172+
SERIAL_ECHO(
173+
F("[MP] " MeatPack_ProtocolVersion " "),
174+
ON_OFF(TEST(state, MPConfig_Bit_Active)),
175+
TEST(state, MPConfig_Bit_NoSpaces) ? F(" NSP\n") : F(" ESP\n")
176+
);
175177
}
176178

177179
/**

β€ŽMarlin/src/feature/tmc_util.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,15 @@
595595
void print_cs_actual(TMCMarlin<TMC2240Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &) { }
596596
#endif
597597

598+
static void print_true_or_false(const bool tf) { SERIAL_ECHO(TRUE_FALSE(tf)); }
599+
598600
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC5130)
599601
static void _tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
600602
switch (i) {
601603
case TMC_PWM_SCALE: SERIAL_ECHO(st.PWM_SCALE()); break;
602604
case TMC_SGT: SERIAL_ECHO(st.sgt()); break;
603-
case TMC_STEALTHCHOP: serialprint_truefalse(st.en_pwm_mode()); break;
604-
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
605+
case TMC_STEALTHCHOP: print_true_or_false(st.en_pwm_mode()); break;
606+
case TMC_INTERPOLATE: print_true_or_false(st.intpol()); break;
605607
default: break;
606608
}
607609
}
@@ -623,15 +625,15 @@
623625
switch (i) {
624626
case TMC_PWM_SCALE: SERIAL_ECHO(st.PWM_SCALE()); break;
625627
case TMC_SGT: SERIAL_ECHO(st.sgt()); break;
626-
case TMC_STEALTHCHOP: serialprint_truefalse(st.en_pwm_mode()); break;
628+
case TMC_STEALTHCHOP: print_true_or_false(st.en_pwm_mode()); break;
627629
case TMC_GLOBAL_SCALER:
628630
{
629631
const uint16_t value = st.GLOBAL_SCALER();
630632
SERIAL_ECHO(value ?: 256);
631633
SERIAL_ECHOPGM("/256");
632634
}
633635
break;
634-
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
636+
case TMC_INTERPOLATE: print_true_or_false(st.intpol()); break;
635637
default: break;
636638
}
637639
}
@@ -645,8 +647,8 @@
645647
case TMC_PWM_SCALE_AUTO: SERIAL_ECHO(st.pwm_scale_auto()); break;
646648
case TMC_PWM_OFS_AUTO: SERIAL_ECHO(st.pwm_ofs_auto()); break;
647649
case TMC_PWM_GRAD_AUTO: SERIAL_ECHO(st.pwm_grad_auto()); break;
648-
case TMC_STEALTHCHOP: serialprint_truefalse(st.stealth()); break;
649-
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
650+
case TMC_STEALTHCHOP: print_true_or_false(st.stealth()); break;
651+
case TMC_INTERPOLATE: print_true_or_false(st.intpol()); break;
650652
default: break;
651653
}
652654
}
@@ -697,8 +699,8 @@
697699
case TMC_PWM_SCALE_AUTO: SERIAL_ECHO(st.pwm_scale_auto()); break;
698700
case TMC_PWM_OFS_AUTO: SERIAL_ECHO(st.pwm_ofs_auto()); break;
699701
case TMC_PWM_GRAD_AUTO: SERIAL_ECHO(st.pwm_grad_auto()); break;
700-
case TMC_STEALTHCHOP: serialprint_truefalse(st.stealth()); break;
701-
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
702+
case TMC_STEALTHCHOP: print_true_or_false(st.stealth()); break;
703+
case TMC_INTERPOLATE: print_true_or_false(st.intpol()); break;
702704
default: break;
703705
}
704706
}
@@ -708,7 +710,7 @@
708710
static void _tmc_parse_drv_status(TMC2660Stepper, const TMC_drv_status_enum) { }
709711
static void _tmc_status(TMC2660Stepper &st, const TMC_debug_enum i) {
710712
switch (i) {
711-
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
713+
case TMC_INTERPOLATE: print_true_or_false(st.intpol()); break;
712714
default: break;
713715
}
714716
}
@@ -734,7 +736,7 @@
734736
SERIAL_CHAR('\t');
735737
switch (i) {
736738
case TMC_CODES: st.printLabel(); break;
737-
case TMC_ENABLED: serialprint_truefalse(st.isEnabled()); break;
739+
case TMC_ENABLED: print_true_or_false(st.isEnabled()); break;
738740
case TMC_CURRENT: SERIAL_ECHO(st.getMilliamps()); break;
739741
case TMC_RMS_CURRENT: SERIAL_ECHO(st.rms_current()); break;
740742
case TMC_MAX_CURRENT: SERIAL_ECHO(p_float_t(st.rms_current() * 1.41, 0)); break;
@@ -757,9 +759,9 @@
757759
if (tpwmthrs_val) SERIAL_ECHO(tpwmthrs_val); else SERIAL_CHAR('-');
758760
} break;
759761
#endif
760-
case TMC_OTPW: serialprint_truefalse(st.otpw()); break;
762+
case TMC_OTPW: print_true_or_false(st.otpw()); break;
761763
#if ENABLED(MONITOR_DRIVER_STATUS)
762-
case TMC_OTPW_TRIGGERED: serialprint_truefalse(st.getOTPW()); break;
764+
case TMC_OTPW_TRIGGERED: print_true_or_false(st.getOTPW()); break;
763765
#endif
764766
case TMC_TOFF: SERIAL_ECHO(st.toff()); break;
765767
case TMC_TBL: print_blank_time(st); break;
@@ -776,7 +778,7 @@
776778
SERIAL_CHAR('\t');
777779
switch (i) {
778780
case TMC_CODES: st.printLabel(); break;
779-
case TMC_ENABLED: serialprint_truefalse(st.isEnabled()); break;
781+
case TMC_ENABLED: print_true_or_false(st.isEnabled()); break;
780782
case TMC_CURRENT: SERIAL_ECHO(st.getMilliamps()); break;
781783
case TMC_RMS_CURRENT: SERIAL_ECHO(st.rms_current()); break;
782784
case TMC_MAX_CURRENT: SERIAL_ECHO(p_float_t(st.rms_current() * 1.41, 0)); break;
@@ -786,8 +788,8 @@
786788
break;
787789
case TMC_VSENSE: SERIAL_ECHO(st.vsense() ? F("1=.165") : F("0=.310")); break;
788790
case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
789-
//case TMC_OTPW: serialprint_truefalse(st.otpw()); break;
790-
//case TMC_OTPW_TRIGGERED: serialprint_truefalse(st.getOTPW()); break;
791+
//case TMC_OTPW: print_true_or_false(st.otpw()); break;
792+
//case TMC_OTPW_TRIGGERED: print_true_or_false(st.getOTPW()); break;
791793
case TMC_SGT: SERIAL_ECHO(st.sgt()); break;
792794
case TMC_TOFF: SERIAL_ECHO(st.toff()); break;
793795
case TMC_TBL: print_blank_time(st); break;

β€ŽMarlin/src/gcode/bedlevel/M420.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ void GcodeSuite::M420() {
228228
if (to_enable && !planner.leveling_active)
229229
SERIAL_ERROR_MSG(STR_ERR_M420_FAILED);
230230

231-
SERIAL_ECHO_START();
232-
SERIAL_ECHOPGM("Bed Leveling ");
233-
serialprintln_onoff(planner.leveling_active);
231+
SERIAL_ECHO_MSG("Bed Leveling ", ON_OFF(planner.leveling_active));
234232

235233
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
236234
SERIAL_ECHO_START();
@@ -252,14 +250,13 @@ void GcodeSuite::M420_report(const bool forReplay/*=true*/) {
252250
report_heading_etc(forReplay, F(
253251
TERN(MESH_BED_LEVELING, "Mesh Bed Leveling", TERN(AUTO_BED_LEVELING_UBL, "Unified Bed Leveling", "Auto Bed Leveling"))
254252
));
255-
SERIAL_ECHO(
253+
SERIAL_ECHOLN(
256254
F(" M420 S"), planner.leveling_active
257255
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
258256
, FPSTR(SP_Z_STR), LINEAR_UNIT(planner.z_fade_height)
259257
#endif
260-
, F(" ; Leveling ")
258+
, F(" ; Leveling "), ON_OFF(planner.leveling_active)
261259
);
262-
serialprintln_onoff(planner.leveling_active);
263260
}
264261

265262
#endif // HAS_LEVELING

β€ŽMarlin/src/gcode/bedlevel/mbl/G29.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void GcodeSuite::G29() {
9999
case MeshReport:
100100
SERIAL_ECHOPGM("Mesh Bed Leveling ");
101101
if (leveling_is_valid()) {
102-
serialprintln_onoff(planner.leveling_active);
102+
SERIAL_ECHOLN(ON_OFF(planner.leveling_active));
103103
bedlevel.report_mesh();
104104
}
105105
else

β€ŽMarlin/src/gcode/control/M211.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ void GcodeSuite::M211_report(const bool forReplay/*=true*/) {
4343
TERN_(MARLIN_SMALL_BUILD, return);
4444

4545
report_heading_etc(forReplay, F(STR_SOFT_ENDSTOPS));
46-
SERIAL_ECHOPGM(" M211 S", AS_DIGIT(soft_endstop._enabled), " ; ");
47-
serialprintln_onoff(soft_endstop._enabled);
46+
SERIAL_ECHOLNPGM(" M211 S", AS_DIGIT(soft_endstop._enabled), " ; ", ON_OFF(soft_endstop._enabled));
4847

4948
report_echo_start(forReplay);
5049
const xyz_pos_t l_soft_min = soft_endstop.min.asLogical(),

β€ŽMarlin/src/gcode/control/M605.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@
173173
set_duplication_enabled(ena && (duplication_e_mask >= 3));
174174
}
175175
SERIAL_ECHO_START();
176-
SERIAL_ECHOPGM(STR_DUPLICATION_MODE);
177-
serialprint_onoff(extruder_duplication_enabled);
176+
SERIAL_ECHOPGM(STR_DUPLICATION_MODE, ON_OFF(extruder_duplication_enabled));
178177
if (ena) {
179178
SERIAL_ECHOPGM(" ( ");
180179
HOTEND_LOOP() if (TEST(duplication_e_mask, e)) { SERIAL_ECHO(e); SERIAL_CHAR(' '); }

β€ŽMarlin/src/gcode/feature/mixing/M166.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ void GcodeSuite::M166() {
6868

6969
mixer.refresh_gradient();
7070

71-
SERIAL_ECHOPGM("Gradient Mix ");
72-
serialprint_onoff(mixer.gradient.enabled);
71+
SERIAL_ECHOPGM("Gradient Mix ", ON_OFF(mixer.gradient.enabled));
7372
if (mixer.gradient.enabled) {
7473

7574
#if ENABLED(GRADIENT_VTOOL)

β€ŽMarlin/src/gcode/feature/powerloss/M413.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ void GcodeSuite::M413_report(const bool forReplay/*=true*/) {
6767
TERN_(MARLIN_SMALL_BUILD, return);
6868

6969
report_heading_etc(forReplay, F(STR_POWER_LOSS_RECOVERY));
70-
SERIAL_ECHOPGM(" M413 S", AS_DIGIT(recovery.enabled)
70+
SERIAL_ECHOLNPGM(" M413 S", AS_DIGIT(recovery.enabled)
7171
#if HAS_PLR_BED_THRESHOLD
7272
, " B", recovery.bed_temp_threshold
7373
#endif
74+
, " ; ", ON_OFF(recovery.enabled)
7475
);
75-
SERIAL_ECHO(" ; ");
76-
serialprintln_onoff(recovery.enabled);
7776
}
7877

7978
#endif // POWER_LOSS_RECOVERY

β€ŽMarlin/src/gcode/feature/prusa_MMU2/M704-M709.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,12 @@ void GcodeSuite::M709() {
185185
void GcodeSuite::MMU3_report(const bool forReplay/*=true*/) {
186186
using namespace MMU3;
187187
report_heading(forReplay, F("MMU3 Operational Stats"));
188-
SERIAL_ECHOPGM(" MMU "); serialprintln_onoff(mmu3.mmu_hw_enabled);
189-
SERIAL_ECHOPGM(" Stealth Mode "); serialprintln_onoff(mmu3.stealth_mode);
188+
SERIAL_ECHOLNPGM(" MMU ", ON_OFF(mmu3.mmu_hw_enabled));
189+
SERIAL_ECHOLNPGM(" Stealth Mode ", ON_OFF(mmu3.stealth_mode));
190190
#if ENABLED(MMU3_HAS_CUTTER)
191-
SERIAL_ECHOPGM(" Cutter ");
192-
serialprintln_onoff(mmu3.cutter_mode != 0);
191+
SERIAL_ECHOLNPGM(" Cutter ", ON_OFF(mmu3.cutter_mode != 0));
193192
#endif
194-
SERIAL_ECHOPGM(" SpoolJoin "); serialprintln_onoff(spooljoin.enabled);
193+
SERIAL_ECHOLNPGM(" SpoolJoin ", ON_OFF(spooljoin.enabled));
195194
SERIAL_ECHOLNPGM(" Tool Changes ", operation_statistics.tool_change_counter);
196195
SERIAL_ECHOLNPGM(" Total Tool Changes ", operation_statistics.tool_change_total_counter);
197196
SERIAL_ECHOLNPGM(" Fails ", operation_statistics.fail_num);

β€ŽMarlin/src/gcode/feature/runout/M412.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ void GcodeSuite::M412() {
5353
}
5454
else {
5555
SERIAL_ECHO_START();
56-
SERIAL_ECHOPGM("Filament runout ");
57-
serialprint_onoff(runout.enabled);
56+
SERIAL_ECHOPGM("Filament runout ", ON_OFF(runout.enabled));
5857
#if HAS_FILAMENT_RUNOUT_DISTANCE
5958
SERIAL_ECHOPGM(" ; Distance ", runout.runout_distance(), "mm");
6059
#endif
6160
#if ENABLED(HOST_ACTION_COMMANDS)
62-
SERIAL_ECHOPGM(" ; Host handling ");
63-
serialprint_onoff(runout.host_handling);
61+
SERIAL_ECHOPGM(" ; Host handling ", ON_OFF(runout.host_handling));
6462
#endif
6563
SERIAL_EOL();
6664
}
@@ -70,14 +68,13 @@ void GcodeSuite::M412_report(const bool forReplay/*=true*/) {
7068
TERN_(MARLIN_SMALL_BUILD, return);
7169

7270
report_heading_etc(forReplay, F(STR_FILAMENT_RUNOUT_SENSOR));
73-
SERIAL_ECHOPGM(
71+
SERIAL_ECHOLNPGM(
7472
" M412 S", runout.enabled
7573
#if HAS_FILAMENT_RUNOUT_DISTANCE
7674
, " D", LINEAR_UNIT(runout.runout_distance())
7775
#endif
78-
, " ; Sensor "
76+
, " ; Sensor ", ON_OFF(runout.enabled)
7977
);
80-
serialprintln_onoff(runout.enabled);
8178
}
8279

8380
#endif // HAS_FILAMENT_SENSOR

β€ŽMarlin/src/gcode/feature/trinamic/M911-M914.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@
7676
template<typename TMC>
7777
static void tmc_report_otpw(TMC &st) {
7878
st.printLabel();
79-
SERIAL_ECHOPGM(" temperature prewarn triggered: ");
80-
serialprint_truefalse(st.getOTPW());
81-
SERIAL_EOL();
79+
SERIAL_ECHOLNPGM(" temperature prewarn triggered: ", TRUE_FALSE(st.getOTPW()));
8280
}
8381

8482
template<typename TMC>

β€ŽMarlin/src/gcode/probe/M401_M402.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ void GcodeSuite::M401() {
4747
seenS = parser.seen('S');
4848
if (seenH || seenS) {
4949
if (seenS) bltouch.high_speed_mode = parser.value_bool();
50-
SERIAL_ECHO_START();
51-
SERIAL_ECHOPGM("BLTouch HS mode ");
52-
serialprintln_onoff(bltouch.high_speed_mode);
50+
SERIAL_ECHO_MSG("BLTouch HS mode ", ON_OFF(bltouch.high_speed_mode));
5351
return;
5452
}
5553
#endif

β€ŽMarlin/src/gcode/temp/M303.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ void GcodeSuite::M303() {
5050
#if HAS_PID_DEBUG
5151
if (parser.seen_test('D')) {
5252
FLIP(thermalManager.pid_debug_flag);
53-
SERIAL_ECHO_START();
54-
SERIAL_ECHOPGM("PID Debug ");
55-
serialprintln_onoff(thermalManager.pid_debug_flag);
53+
SERIAL_ECHO_MSG("PID Debug ", ON_OFF(thermalManager.pid_debug_flag));
5654
return;
5755
}
5856
#endif

0 commit comments

Comments
Β (0)