From e6cf7860e8fafb5c2bdb95ff36ad7d598fa5636a Mon Sep 17 00:00:00 2001 From: Marcio Teixeira Date: Fri, 28 Jun 2019 23:23:57 -0600 Subject: [PATCH] Improve ExtUI, fix compiler errors, warnings (#14441) --- Marlin/Makefile | 4 +-- Marlin/src/feature/backlash.h | 6 ++++ Marlin/src/feature/tmc_util.cpp | 2 +- Marlin/src/gcode/calibrate/G425.cpp | 6 ++++ Marlin/src/gcode/config/M92.cpp | 4 +-- Marlin/src/gcode/queue.cpp | 36 ++++++++++---------- Marlin/src/gcode/queue.h | 5 +++ Marlin/src/inc/Conditionals_LCD.h | 2 ++ Marlin/src/lcd/extensible_ui/ui_api.cpp | 44 ++++++++++++++++++++----- Marlin/src/lcd/menu/menu_sdcard.cpp | 2 +- 10 files changed, 80 insertions(+), 31 deletions(-) diff --git a/Marlin/Makefile b/Marlin/Makefile index b7d0bf5c6b..4c8137f335 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -666,8 +666,8 @@ LIBWARN = -w -Wno-packed-bitfield-compat CSTANDARD = -std=gnu99 CXXSTANDARD = -std=gnu++11 CDEBUG = -g$(DEBUG) -CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas -CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas +CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter +CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter CTUNING = -fsigned-char -funsigned-bitfields -fpack-struct -fno-exceptions \ -fshort-enums -ffunction-sections -fdata-sections ifneq ($(HARDWARE_MOTHERBOARD),) diff --git a/Marlin/src/feature/backlash.h b/Marlin/src/feature/backlash.h index 4937fcdae9..fd220a4914 100644 --- a/Marlin/src/feature/backlash.h +++ b/Marlin/src/feature/backlash.h @@ -68,6 +68,9 @@ public: #endif 0 ); + #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING) + UNUSED(e); + #endif } static inline bool has_measurement(const uint8_t e) { @@ -76,6 +79,9 @@ public: || (measured_count[e] > 0) #endif ); + #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING) + UNUSED(e); + #endif } static inline bool has_any_measurement() { diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index e79d4045ea..c432a3cf9a 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -985,7 +985,7 @@ st.TCOOLTHRS(0xFFFFF); return true; } - void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth) { + void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth _UNUSED) { st.TCOOLTHRS(0); } diff --git a/Marlin/src/gcode/calibrate/G425.cpp b/Marlin/src/gcode/calibrate/G425.cpp index efe853c4cd..5b3765737b 100644 --- a/Marlin/src/gcode/calibrate/G425.cpp +++ b/Marlin/src/gcode/calibrate/G425.cpp @@ -411,9 +411,13 @@ inline void probe_sides(measurements_t &m, const float uncertainty) { SERIAL_ECHOLNPGM("Nozzle Tip Outer Dimensions:"); #if HAS_X_CENTER SERIAL_ECHOLNPAIR(" X", m.nozzle_outer_dimension[X_AXIS]); + #else + UNUSED(m); #endif #if HAS_Y_CENTER SERIAL_ECHOLNPAIR(" Y", m.nozzle_outer_dimension[Y_AXIS]); + #else + UNUSED(m); #endif SERIAL_EOL(); } @@ -518,6 +522,8 @@ inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const #if HOTENDS > 1 set_nozzle(m, extruder); + #else + UNUSED(extruder); #endif probe_sides(m, uncertainty); diff --git a/Marlin/src/gcode/config/M92.cpp b/Marlin/src/gcode/config/M92.cpp index 236ecfe650..dc4b134af7 100644 --- a/Marlin/src/gcode/config/M92.cpp +++ b/Marlin/src/gcode/config/M92.cpp @@ -40,9 +40,9 @@ void report_M92(const bool echo=true, const int8_t e=-1) { SERIAL_ECHOPAIR(" M92 T", (int)i); SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)])); } - #else - UNUSED(e); #endif + + UNUSED_E(e); } /** diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index 9e2d5984a4..d519378a29 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -89,6 +89,13 @@ GCodeQueue::GCodeQueue() { for (uint8_t i = 0; i < COUNT(send_ok); i++) send_ok[i] = true; } +/** + * Check whether there are any commands yet to be executed + */ +bool GCodeQueue::has_commands_queued() { + return queue.length || injected_commands_P; +} + /** * Clear the Marlin command queue */ @@ -154,6 +161,8 @@ bool GCodeQueue::enqueue_one(const char* cmd) { /** * Process the next "immediate" command. + * Return 'true' if any commands were processed, + * or remain to process. */ bool GCodeQueue::process_injected_command() { if (injected_commands_P == nullptr) return false; @@ -161,19 +170,16 @@ bool GCodeQueue::process_injected_command() { char c; size_t i = 0; while ((c = pgm_read_byte(&injected_commands_P[i])) && c != '\n') i++; - if (!i) return false; - - char cmd[i + 1]; - memcpy_P(cmd, injected_commands_P, i); - cmd[i] = '\0'; + if (i) { + char cmd[i + 1]; + memcpy_P(cmd, injected_commands_P, i); + cmd[i] = '\0'; + parser.parse(cmd); + PORT_REDIRECT(SERIAL_PORT); + gcode.process_parsed_command(); + } injected_commands_P = c ? injected_commands_P + i + 1 : nullptr; - - parser.parse(cmd); - PORT_REDIRECT(SERIAL_PORT); - gcode.process_parsed_command(); - PORT_RESTORE(); - return true; } @@ -183,17 +189,13 @@ bool GCodeQueue::process_injected_command() { * Aborts the current queue, if any. * Note: process_injected_command() will be called to drain any commands afterwards */ -void GCodeQueue::inject_P(PGM_P const pgcode) { - injected_commands_P = pgcode; -} +void GCodeQueue::inject_P(PGM_P const pgcode) { injected_commands_P = pgcode; } /** * Enqueue and return only when commands are actually enqueued. * Never call this from a G-code handler! */ -void GCodeQueue::enqueue_one_now(const char* cmd) { - while (!enqueue_one(cmd)) idle(); -} +void GCodeQueue::enqueue_one_now(const char* cmd) { while (!enqueue_one(cmd)) idle(); } /** * Enqueue from program memory and return only when commands are actually enqueued diff --git a/Marlin/src/gcode/queue.h b/Marlin/src/gcode/queue.h index 9819fd4226..671793e2bd 100644 --- a/Marlin/src/gcode/queue.h +++ b/Marlin/src/gcode/queue.h @@ -84,6 +84,11 @@ public: */ static void enqueue_now_P(PGM_P const cmd); + /** + * Check whether there are any commands yet to be executed + */ + static bool has_commands_queued(); + /** * Get the next command in the queue, optionally log it to SD, then dispatch it */ diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 7a71a6175b..21a1c53ae7 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -451,10 +451,12 @@ #if ENABLED(DISTINCT_E_FACTORS) && E_STEPPERS > 1 #define XYZE_N (XYZ + E_STEPPERS) #define E_AXIS_N(E) AxisEnum(E_AXIS + E) + #define UNUSED_E(E) NOOP #else #undef DISTINCT_E_FACTORS #define XYZE_N XYZE #define E_AXIS_N(E) E_AXIS + #define UNUSED_E(E) UNUSED(E) #endif /** diff --git a/Marlin/src/lcd/extensible_ui/ui_api.cpp b/Marlin/src/lcd/extensible_ui/ui_api.cpp index 87f2eab92d..32008afc22 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.cpp +++ b/Marlin/src/lcd/extensible_ui/ui_api.cpp @@ -242,18 +242,28 @@ namespace ExtUI { } float getTargetFan_percent(const fan_t fan) { - return thermalManager.fanPercent(thermalManager.fan_speed[fan - FAN0]); + #if FAN_COUNT > 0 + return thermalManager.fanPercent(thermalManager.fan_speed[fan - FAN0]); + #else + UNUSED(fan); + return 0; + #endif } float getActualFan_percent(const fan_t fan) { - return thermalManager.fanPercent(thermalManager.scaledFanSpeed(fan - FAN0)); + #if FAN_COUNT > 0 + return thermalManager.fanPercent(thermalManager.scaledFanSpeed(fan - FAN0)); + #else + UNUSED(fan); + return 0; + #endif } float getAxisPosition_mm(const axis_t axis) { return flags.manual_motion ? destination[axis] : current_position[axis]; } - float getAxisPosition_mm(const extruder_t extruder) { + float getAxisPosition_mm(const extruder_t) { return flags.manual_motion ? destination[E_AXIS] : current_position[E_AXIS]; } @@ -353,6 +363,9 @@ namespace ExtUI { if (e != active_extruder) tool_change(e, no_move); #endif active_extruder = e; + #else + UNUSED(extruder); + UNUSED(no_move); #endif } @@ -506,6 +519,7 @@ namespace ExtUI { } float getAxisSteps_per_mm(const extruder_t extruder) { + UNUSED_E(extruder); return planner.settings.axis_steps_per_mm[E_AXIS_N(extruder - E0)]; } @@ -514,6 +528,7 @@ namespace ExtUI { } void setAxisSteps_per_mm(const float value, const extruder_t extruder) { + UNUSED_E(extruder); planner.settings.axis_steps_per_mm[E_AXIS_N(axis - E0)] = value; } @@ -522,6 +537,7 @@ namespace ExtUI { } float getAxisMaxFeedrate_mm_s(const extruder_t extruder) { + UNUSED_E(extruder); return planner.settings.max_feedrate_mm_s[E_AXIS_N(axis - E0)]; } @@ -530,6 +546,7 @@ namespace ExtUI { } void setAxisMaxFeedrate_mm_s(const float value, const extruder_t extruder) { + UNUSED_E(extruder); planner.settings.max_feedrate_mm_s[E_AXIS_N(axis - E0)] = value; } @@ -538,6 +555,7 @@ namespace ExtUI { } float getAxisMaxAcceleration_mm_s2(const extruder_t extruder) { + UNUSED_E(extruder); return planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(extruder - E0)]; } @@ -546,6 +564,7 @@ namespace ExtUI { } void setAxisMaxAcceleration_mm_s2(const float value, const extruder_t extruder) { + UNUSED_E(extruder); planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(extruder - E0)] = value; } @@ -589,7 +608,7 @@ namespace ExtUI { return planner.max_jerk[axis]; } - float getAxisMaxJerk_mm_s(const extruder_t extruder) { + float getAxisMaxJerk_mm_s(const extruder_t) { return planner.max_jerk[E_AXIS]; } @@ -597,7 +616,7 @@ namespace ExtUI { planner.max_jerk[axis] = value; } - void setAxisMaxJerk_mm_s(const float value, const extruder_t extruder) { + void setAxisMaxJerk_mm_s(const float value, const extruder_t) { planner.max_jerk[E_AXIS] = value; } #endif @@ -780,12 +799,16 @@ namespace ExtUI { queue.inject_P(gcode); } - bool commandsInQueue() { return (planner.movesplanned() || queue.length); } + bool commandsInQueue() { return (planner.movesplanned() || queue.has_commands_queued()); } bool isAxisPositionKnown(const axis_t axis) { return TEST(axis_known_position, axis); } + bool isAxisPositionKnown(const extruder_t) { + return TEST(axis_known_position, E_AXIS); + } + bool isPositionKnown() { return all_axes_known(); } bool isMachineHomed() { return all_axes_homed(); } @@ -814,8 +837,13 @@ namespace ExtUI { } void setTargetFan_percent(const float value, const fan_t fan) { - if (fan < FAN_COUNT) - thermalManager.set_fan_speed(fan - FAN0, map(clamp(value, 0, 100), 0, 100, 0, 255)); + #if FAN_COUNT > 0 + if (fan < FAN_COUNT) + thermalManager.set_fan_speed(fan - FAN0, map(clamp(value, 0, 100), 0, 100, 0, 255)); + #else + UNUSED(value); + UNUSED(fan); + #endif } void setFeedrate_percent(const float value) { diff --git a/Marlin/src/lcd/menu/menu_sdcard.cpp b/Marlin/src/lcd/menu/menu_sdcard.cpp index 5d920d689c..894d9288a9 100644 --- a/Marlin/src/lcd/menu/menu_sdcard.cpp +++ b/Marlin/src/lcd/menu/menu_sdcard.cpp @@ -93,7 +93,7 @@ inline void sdcard_start_selected_file() { class MenuItem_sdfile { public: - static void action(CardReader &theCard) { + static void action(CardReader &) { #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE) // Save menu state for the selected file sd_encoder_position = ui.encoderPosition;