🧑‍💻 EXTRUDER_LOOP macro

This commit is contained in:
Scott Lahteine 2022-03-22 22:22:08 -05:00 committed by Scott Lahteine
parent b094a3fc0d
commit 4a8b99d505
15 changed files with 62 additions and 61 deletions

View File

@ -73,10 +73,10 @@ void FWRetract::reset() {
settings.swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
current_hop = 0.0;
LOOP_L_N(i, EXTRUDERS) {
retracted[i] = false;
E_TERN_(retracted_swap[i] = false);
current_retract[i] = 0.0;
EXTRUDER_LOOP() {
retracted[e] = false;
E_TERN_(retracted_swap[e] = false);
current_retract[e] = 0.0;
}
}
@ -111,10 +111,10 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/))
" swapping ", swapping,
" active extruder ", active_extruder
);
LOOP_L_N(i, EXTRUDERS) {
SERIAL_ECHOLNPGM("retracted[", i, "] ", AS_DIGIT(retracted[i]));
EXTRUDER_LOOP() {
SERIAL_ECHOLNPGM("retracted[", e, "] ", AS_DIGIT(retracted[e]));
#if HAS_MULTI_EXTRUDER
SERIAL_ECHOLNPGM("retracted_swap[", i, "] ", AS_DIGIT(retracted_swap[i]));
SERIAL_ECHOLNPGM("retracted_swap[", e, "] ", AS_DIGIT(retracted_swap[e]));
#endif
}
SERIAL_ECHOLNPGM("current_position.z ", current_position.z);
@ -184,10 +184,10 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/))
SERIAL_ECHOLNPGM("retracting ", AS_DIGIT(retracting));
SERIAL_ECHOLNPGM("swapping ", AS_DIGIT(swapping));
SERIAL_ECHOLNPGM("active_extruder ", active_extruder);
LOOP_L_N(i, EXTRUDERS) {
SERIAL_ECHOLNPGM("retracted[", i, "] ", AS_DIGIT(retracted[i]));
EXTRUDER_LOOP() {
SERIAL_ECHOLNPGM("retracted[", e, "] ", AS_DIGIT(retracted[e]));
#if HAS_MULTI_EXTRUDER
SERIAL_ECHOLNPGM("retracted_swap[", i, "] ", AS_DIGIT(retracted_swap[i]));
SERIAL_ECHOLNPGM("retracted_swap[", e, "] ", AS_DIGIT(retracted_swap[e]));
#endif
}
SERIAL_ECHOLNPGM("current_position.z ", current_position.z);

View File

@ -64,7 +64,7 @@ public:
static void reset();
static void refresh_autoretract() {
LOOP_L_N(i, EXTRUDERS) retracted[i] = false;
EXTRUDER_LOOP() retracted[e] = false;
}
static void enable_autoretract(const bool enable) {

View File

@ -196,7 +196,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
#if DISABLED(NO_VOLUMETRICS)
info.flag.volumetric_enabled = parser.volumetric_enabled;
#if HAS_MULTI_EXTRUDER
for (int8_t e = 0; e < EXTRUDERS; e++) info.filament_size[e] = planner.filament_size[e];
EXTRUDER_LOOP() info.filament_size[e] = planner.filament_size[e];
#else
if (parser.volumetric_enabled) info.filament_size[0] = planner.filament_size[active_extruder];
#endif
@ -461,7 +461,7 @@ void PrintJobRecovery::resume() {
// Recover volumetric extrusion state
#if DISABLED(NO_VOLUMETRICS)
#if HAS_MULTI_EXTRUDER
for (int8_t e = 0; e < EXTRUDERS; e++) {
EXTRUDER_LOOP() {
sprintf_P(cmd, PSTR("M200T%iD%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1));
gcode.process_subcommands_now(cmd);
}
@ -511,7 +511,7 @@ void PrintJobRecovery::resume() {
// Restore retract and hop state from an active `G10` command
#if ENABLED(FWRETRACT)
LOOP_L_N(e, EXTRUDERS) {
EXTRUDER_LOOP() {
if (info.retract[e] != 0.0) {
fwretract.current_retract[e] = info.retract[e];
fwretract.retracted[e] = true;
@ -634,7 +634,7 @@ void PrintJobRecovery::resume() {
#if DISABLED(NO_VOLUMETRICS)
DEBUG_ECHOPGM("filament_size:");
LOOP_L_N(i, EXTRUDERS) DEBUG_ECHOLNPGM(" ", info.filament_size[i]);
EXTRUDER_LOOP() DEBUG_ECHOLNPGM(" ", info.filament_size[e]);
DEBUG_EOL();
#endif
@ -666,7 +666,7 @@ void PrintJobRecovery::resume() {
#if ENABLED(FWRETRACT)
DEBUG_ECHOPGM("retract: ");
for (int8_t e = 0; e < EXTRUDERS; e++) {
EXTRUDER_LOOP() {
DEBUG_ECHO(info.retract[e]);
if (e < EXTRUDERS - 1) DEBUG_CHAR(',');
}

View File

@ -93,12 +93,12 @@
}
#else
SERIAL_ECHOLNPGM(" M200 S", parser.volumetric_enabled);
LOOP_L_N(i, EXTRUDERS) {
EXTRUDER_LOOP() {
report_echo_start(forReplay);
SERIAL_ECHOLNPGM(
" M200 T", i, " D", LINEAR_UNIT(planner.filament_size[i])
" M200 T", e, " D", LINEAR_UNIT(planner.filament_size[e])
#if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
, " L", LINEAR_UNIT(planner.volumetric_extruder_limit[i])
, " L", LINEAR_UNIT(planner.volumetric_extruder_limit[e])
#endif
);
}

View File

@ -77,7 +77,7 @@ void do_enable(const axis_flags_t to_enable) {
}
}
#if HAS_EXTRUDERS
LOOP_L_N(e, EXTRUDERS) {
EXTRUDER_LOOP() {
const uint8_t a = INDEX_OF_AXIS(E_AXIS, e);
if (TEST(shall_enable, a)) {
stepper.ENABLE_EXTRUDER(e);
@ -161,7 +161,7 @@ void try_to_disable(const axis_flags_t to_disable) {
DEBUG_ECHOLNPGM(" ... still_enabled=", hex_word(still_enabled));
}
#if HAS_EXTRUDERS
LOOP_L_N(e, EXTRUDERS) {
EXTRUDER_LOOP() {
const uint8_t a = INDEX_OF_AXIS(E_AXIS, e);
if (TEST(to_disable.bits, a)) {
DEBUG_ECHOPGM("Try to disable E", AS_DIGIT(e), " (", a, ") with overlap ", hex_word(enable_overlap[a]), " ... ");
@ -194,7 +194,7 @@ void try_to_disable(const axis_flags_t to_disable) {
}
}
#if HAS_EXTRUDERS
LOOP_L_N(e, EXTRUDERS) {
EXTRUDER_LOOP() {
const uint8_t a = INDEX_OF_AXIS(E_AXIS, e);
if (TEST(still_enabled, a)) {
SERIAL_CHAR('E', '0' + e);

View File

@ -117,10 +117,10 @@ void GcodeSuite::M900() {
#if EXTRUDERS < 2
SERIAL_ECHOLNPGM("Advance S", new_slot, " K", kref, "(S", !new_slot, " K", lref, ")");
#else
LOOP_L_N(i, EXTRUDERS) {
const bool slot = TEST(lin_adv_slot, i);
SERIAL_ECHOLNPGM("Advance T", i, " S", slot, " K", planner.extruder_advance_K[i],
"(S", !slot, " K", other_extruder_advance_K[i], ")");
EXTRUDER_LOOP() {
const bool slot = TEST(lin_adv_slot, e);
SERIAL_ECHOLNPGM("Advance T", e, " S", slot, " K", planner.extruder_advance_K[e],
"(S", !slot, " K", other_extruder_advance_K[e], ")");
SERIAL_EOL();
}
#endif
@ -132,9 +132,9 @@ void GcodeSuite::M900() {
SERIAL_ECHOLNPGM("Advance K=", planner.extruder_advance_K[0]);
#else
SERIAL_ECHOPGM("Advance K");
LOOP_L_N(i, EXTRUDERS) {
SERIAL_CHAR(' ', '0' + i, ':');
SERIAL_DECIMAL(planner.extruder_advance_K[i]);
EXTRUDER_LOOP() {
SERIAL_CHAR(' ', '0' + e, ':');
SERIAL_DECIMAL(planner.extruder_advance_K[e]);
}
SERIAL_EOL();
#endif
@ -150,9 +150,9 @@ void GcodeSuite::M900_report(const bool forReplay/*=true*/) {
report_echo_start(forReplay);
SERIAL_ECHOLNPGM(" M900 K", planner.extruder_advance_K[0]);
#else
LOOP_L_N(i, EXTRUDERS) {
EXTRUDER_LOOP() {
report_echo_start(forReplay);
SERIAL_ECHOLNPGM(" M900 T", i, " K", planner.extruder_advance_K[i]);
SERIAL_ECHOLNPGM(" M900 T", e, " K", planner.extruder_advance_K[e]);
}
#endif
}

View File

@ -72,7 +72,7 @@ void GcodeSuite::M603_report(const bool forReplay/*=true*/) {
SERIAL_ECHOPGM(" M603 L", LINEAR_UNIT(fc_settings[0].load_length), " U", LINEAR_UNIT(fc_settings[0].unload_length), " ;");
say_units();
#else
LOOP_L_N(e, EXTRUDERS) {
EXTRUDER_LOOP() {
report_echo_start(forReplay);
SERIAL_ECHOPGM(" M603 T", e, " L", LINEAR_UNIT(fc_settings[e].load_length), " U", LINEAR_UNIT(fc_settings[e].unload_length), " ;");
say_units();

View File

@ -749,6 +749,7 @@
#endif
// Helper macros for extruder and hotend arrays
#define EXTRUDER_LOOP() for (int8_t e = 0; e < EXTRUDERS; e++)
#define HOTEND_LOOP() for (int8_t e = 0; e < HOTENDS; e++)
#define ARRAY_BY_EXTRUDERS(V...) ARRAY_N(EXTRUDERS, V)
#define ARRAY_BY_EXTRUDERS1(v1) ARRAY_N_1(EXTRUDERS, v1)

View File

@ -109,8 +109,8 @@ void menu_backlash();
#if EXTRUDERS == 1
EDIT_ITEM(float42_52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 10);
#elif HAS_MULTI_EXTRUDER
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_N(float42_52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 10);
EXTRUDER_LOOP()
EDIT_ITEM_N(float42_52, e, MSG_ADVANCE_K_E, &planner.extruder_advance_K[e], 0, 10);
#endif
#endif
@ -120,16 +120,16 @@ void menu_backlash();
#if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
EDIT_ITEM_FAST(float42_52, MSG_VOLUMETRIC_LIMIT, &planner.volumetric_extruder_limit[active_extruder], 0.0f, 20.0f, planner.calculate_volumetric_extruder_limits);
#if HAS_MULTI_EXTRUDER
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float42_52, n, MSG_VOLUMETRIC_LIMIT_E, &planner.volumetric_extruder_limit[n], 0.0f, 20.00f, planner.calculate_volumetric_extruder_limits);
EXTRUDER_LOOP()
EDIT_ITEM_FAST_N(float42_52, e, MSG_VOLUMETRIC_LIMIT_E, &planner.volumetric_extruder_limit[e], 0.0f, 20.00f, planner.calculate_volumetric_extruder_limits);
#endif
#endif
if (parser.volumetric_enabled) {
EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#if HAS_MULTI_EXTRUDER
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float43, n, MSG_FILAMENT_DIAM_E, &planner.filament_size[n], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
EXTRUDER_LOOP()
EDIT_ITEM_FAST_N(float43, e, MSG_FILAMENT_DIAM_E, &planner.filament_size[e], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#endif
}
#endif
@ -139,14 +139,14 @@ void menu_backlash();
EDIT_ITEM_FAST(float4, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
#if HAS_MULTI_EXTRUDER
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float4, n, MSG_FILAMENTUNLOAD_E, &fc_settings[n].unload_length, 0, extrude_maxlength);
EXTRUDER_LOOP()
EDIT_ITEM_FAST_N(float4, e, MSG_FILAMENTUNLOAD_E, &fc_settings[e].unload_length, 0, extrude_maxlength);
#endif
EDIT_ITEM_FAST(float4, MSG_FILAMENT_LOAD, &fc_settings[active_extruder].load_length, 0, extrude_maxlength);
#if HAS_MULTI_EXTRUDER
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_FAST_N(float4, n, MSG_FILAMENTLOAD_E, &fc_settings[n].load_length, 0, extrude_maxlength);
EXTRUDER_LOOP()
EDIT_ITEM_FAST_N(float4, e, MSG_FILAMENTLOAD_E, &fc_settings[e].load_length, 0, extrude_maxlength);
#endif
#endif

View File

@ -145,9 +145,9 @@ void menu_advanced_settings();
EDIT_ITEM(uint8, MSG_TOOL_MIGRATION_END, &migration.last, 0, EXTRUDERS - 1);
// Migrate to a chosen extruder
LOOP_L_N(s, EXTRUDERS) {
if (s != active_extruder) {
ACTION_ITEM_N_P(s, msg_migrate, []{
EXTRUDER_LOOP() {
if (e != active_extruder) {
ACTION_ITEM_N_P(e, msg_migrate, []{
char cmd[12];
sprintf_P(cmd, PSTR("M217 T%i"), int(MenuItemBase::itemIndex));
queue.inject(cmd);

View File

@ -48,7 +48,7 @@ void _mmu2_load_filament(uint8_t index) {
ui.reset_status();
}
void action_mmu2_load_all() {
LOOP_L_N(i, EXTRUDERS) _mmu2_load_filament(i);
EXTRUDER_LOOP() _mmu2_load_filament(e);
ui.return_to_status();
}
@ -56,14 +56,14 @@ void menu_mmu2_load_filament() {
START_MENU();
BACK_ITEM(MSG_MMU2_MENU);
ACTION_ITEM(MSG_MMU2_ALL, action_mmu2_load_all);
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); });
EXTRUDER_LOOP() ACTION_ITEM_N(e, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); });
END_MENU();
}
void menu_mmu2_load_to_nozzle() {
START_MENU();
BACK_ITEM(MSG_MMU2_MENU);
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); });
EXTRUDER_LOOP() ACTION_ITEM_N(e, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); });
END_MENU();
}
@ -89,7 +89,7 @@ void action_mmu2_unload_filament() {
void menu_mmu2_eject_filament() {
START_MENU();
BACK_ITEM(MSG_MMU2_MENU);
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); });
EXTRUDER_LOOP() ACTION_ITEM_N(e, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); });
END_MENU();
}
@ -130,7 +130,7 @@ void menu_mmu2_choose_filament() {
#if LCD_HEIGHT > 2
STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_DEFAULT|SS_INVERT);
#endif
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); });
EXTRUDER_LOOP() ACTION_ITEM_N(e, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); });
END_MENU();
}

View File

@ -199,8 +199,8 @@ void menu_tune() {
EDIT_ITEM(int3, MSG_FLOW, &planner.flow_percentage[active_extruder], 10, 999, []{ planner.refresh_e_factor(active_extruder); });
// Flow En:
#if HAS_MULTI_EXTRUDER
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_N(int3, n, MSG_FLOW_N, &planner.flow_percentage[n], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
EXTRUDER_LOOP()
EDIT_ITEM_N(int3, e, MSG_FLOW_N, &planner.flow_percentage[e], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
#endif
#endif
@ -211,8 +211,8 @@ void menu_tune() {
#if EXTRUDERS == 1
EDIT_ITEM(float42_52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 10);
#elif HAS_MULTI_EXTRUDER
LOOP_L_N(n, EXTRUDERS)
EDIT_ITEM_N(float42_52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 10);
EXTRUDER_LOOP()
EDIT_ITEM_N(float42_52, e, MSG_ADVANCE_K_E, &planner.extruder_advance_K[e], 0, 10);
#endif
#endif

View File

@ -1505,7 +1505,7 @@ void Planner::check_axes_activity() {
volumetric_extruder_feedrate_limit[e] = (lim && siz) ? lim / CIRCLE_AREA(siz * 0.5f) : 0;
}
void Planner::calculate_volumetric_extruder_limits() {
LOOP_L_N(e, EXTRUDERS) calculate_volumetric_extruder_limit(e);
EXTRUDER_LOOP() calculate_volumetric_extruder_limit(e);
}
#endif

View File

@ -928,8 +928,8 @@ class Planner {
#if HAS_LINEAR_E_JERK
FORCE_INLINE static void recalculate_max_e_jerk() {
const float prop = junction_deviation_mm * SQRT(0.5) / (1.0f - SQRT(0.5));
LOOP_L_N(i, EXTRUDERS)
max_e_jerk[E_INDEX_N(i)] = SQRT(prop * settings.max_acceleration_mm_per_s2[E_INDEX_N(i)]);
EXTRUDER_LOOP()
max_e_jerk[E_INDEX_N(e)] = SQRT(prop * settings.max_acceleration_mm_per_s2[E_INDEX_N(e)]);
}
#endif

View File

@ -3138,9 +3138,9 @@ void MarlinSettings::reset() {
//
#if ENABLED(LIN_ADVANCE)
LOOP_L_N(i, EXTRUDERS) {
planner.extruder_advance_K[i] = LIN_ADVANCE_K;
TERN_(EXTRA_LIN_ADVANCE_K, other_extruder_advance_K[i] = LIN_ADVANCE_K);
EXTRUDER_LOOP() {
planner.extruder_advance_K[e] = LIN_ADVANCE_K;
TERN_(EXTRA_LIN_ADVANCE_K, other_extruder_advance_K[e] = LIN_ADVANCE_K);
}
#endif
@ -3185,7 +3185,7 @@ void MarlinSettings::reset() {
// Advanced Pause filament load & unload lengths
//
#if ENABLED(ADVANCED_PAUSE_FEATURE)
LOOP_L_N(e, EXTRUDERS) {
EXTRUDER_LOOP() {
fc_settings[e].unload_length = FILAMENT_CHANGE_UNLOAD_LENGTH;
fc_settings[e].load_length = FILAMENT_CHANGE_FAST_LOAD_LENGTH;
}