@@ -884,19 +884,19 @@ volatile bool Temperature::raw_temps_ready = false;
884
884
885
885
#if ENABLED(MPCTEMP)
886
886
887
- void Temperature::MPC_autotune () {
888
- auto housekeeping = [] (millis_t &ms, celsius_float_t ¤t_temp, millis_t &next_report_ms) {
887
+ void Temperature::MPC_autotune (const heater_id_t e ) {
888
+ auto housekeeping = [] (millis_t &ms, const heater_id_t e, celsius_float_t ¤t_temp, millis_t &next_report_ms) {
889
889
ms = millis ();
890
890
891
891
if (updateTemperaturesIfReady ()) { // temp sample ready
892
- current_temp = degHotend (active_extruder );
892
+ current_temp = degHotend (e );
893
893
TERN_ (HAS_FAN_LOGIC, manage_extruder_fans (ms));
894
894
}
895
895
896
896
if (ELAPSED (ms, next_report_ms)) {
897
897
next_report_ms += 1000UL ;
898
898
899
- print_heater_states (active_extruder );
899
+ print_heater_states (e );
900
900
SERIAL_EOL ();
901
901
}
902
902
@@ -914,27 +914,29 @@ volatile bool Temperature::raw_temps_ready = false;
914
914
};
915
915
916
916
struct OnExit {
917
+ heater_id_t e;
918
+ OnExit (const heater_id_t e) {this ->e = e;}
917
919
~OnExit () {
918
920
wait_for_heatup = false ;
919
921
920
922
ui.reset_status ();
921
923
922
- temp_hotend[active_extruder ].target = 0 .0f ;
923
- temp_hotend[active_extruder ].soft_pwm_amount = 0 ;
924
+ temp_hotend[e ].target = 0 .0f ;
925
+ temp_hotend[e ].soft_pwm_amount = 0 ;
924
926
#if HAS_FAN
925
- set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder , 0 );
927
+ set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e , 0 );
926
928
planner.sync_fan_speeds (fan_speed);
927
929
#endif
928
930
929
931
do_z_clearance (MPC_TUNING_END_Z);
930
932
931
933
TERN_ (TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = true );
932
934
}
933
- } on_exit;
935
+ } on_exit (e) ;
934
936
935
937
SERIAL_ECHOPGM (STR_MPC_AUTOTUNE);
936
- SERIAL_ECHOLNPGM (STR_MPC_AUTOTUNE_START, active_extruder );
937
- MPCHeaterInfo &hotend = temp_hotend[active_extruder ];
938
+ SERIAL_ECHOLNPGM (STR_MPC_AUTOTUNE_START, e );
939
+ MPCHeaterInfo &hotend = temp_hotend[e ];
938
940
MPC_t &mpc = hotend.mpc ;
939
941
940
942
TERN_ (TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = false );
@@ -944,7 +946,7 @@ volatile bool Temperature::raw_temps_ready = false;
944
946
disable_all_heaters ();
945
947
#if HAS_FAN
946
948
zero_fan_speeds ();
947
- set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder , 255 );
949
+ set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e , 255 );
948
950
planner.sync_fan_speeds (fan_speed);
949
951
#endif
950
952
do_blocking_move_to (xyz_pos_t (MPC_TUNING_POS));
@@ -958,12 +960,12 @@ volatile bool Temperature::raw_temps_ready = false;
958
960
#endif
959
961
960
962
millis_t ms = millis (), next_report_ms = ms, next_test_ms = ms + 10000UL ;
961
- celsius_float_t current_temp = degHotend (active_extruder ),
963
+ celsius_float_t current_temp = degHotend (e ),
962
964
ambient_temp = current_temp;
963
965
964
966
wait_for_heatup = true ;
965
967
for (;;) { // Can be interrupted with M108
966
- if (housekeeping (ms, current_temp, next_report_ms)) return ;
968
+ if (housekeeping (ms, e, current_temp, next_report_ms)) return ;
967
969
968
970
if (ELAPSED (ms, next_test_ms)) {
969
971
if (current_temp >= ambient_temp) {
@@ -977,7 +979,7 @@ volatile bool Temperature::raw_temps_ready = false;
977
979
wait_for_heatup = false ;
978
980
979
981
#if HAS_FAN
980
- set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder , 0 );
982
+ set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e , 0 );
981
983
planner.sync_fan_speeds (fan_speed);
982
984
#endif
983
985
@@ -995,7 +997,7 @@ volatile bool Temperature::raw_temps_ready = false;
995
997
996
998
wait_for_heatup = true ;
997
999
for (;;) { // Can be interrupted with M108
998
- if (housekeeping (ms, current_temp, next_report_ms)) return ;
1000
+ if (housekeeping (ms, e, current_temp, next_report_ms)) return ;
999
1001
1000
1002
if (ELAPSED (ms, next_test_ms)) {
1001
1003
// Record samples between 100C and 200C
@@ -1054,16 +1056,16 @@ volatile bool Temperature::raw_temps_ready = false;
1054
1056
1055
1057
wait_for_heatup = true ;
1056
1058
for (;;) { // Can be interrupted with M108
1057
- if (housekeeping (ms, current_temp, next_report_ms)) return ;
1059
+ if (housekeeping (ms, e, current_temp, next_report_ms)) return ;
1058
1060
1059
1061
if (ELAPSED (ms, next_test_ms)) {
1060
- hotend.soft_pwm_amount = (int )get_pid_output_hotend (active_extruder ) >> 1 ;
1062
+ hotend.soft_pwm_amount = (int )get_pid_output_hotend (e ) >> 1 ;
1061
1063
1062
1064
if (ELAPSED (ms, settle_end_ms) && !ELAPSED (ms, test_end_ms) && TERN1 (HAS_FAN, !fan0_done))
1063
1065
total_energy_fan0 += mpc.heater_power * hotend.soft_pwm_amount / 127 * MPC_dT + (last_temp - current_temp) * mpc.block_heat_capacity ;
1064
1066
#if HAS_FAN
1065
1067
else if (ELAPSED (ms, test_end_ms) && !fan0_done) {
1066
- set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder , 255 );
1068
+ set_fan_speed (EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e , 255 );
1067
1069
planner.sync_fan_speeds (fan_speed);
1068
1070
settle_end_ms = ms + settle_time;
1069
1071
test_end_ms = settle_end_ms + test_duration;
@@ -1451,7 +1453,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
1451
1453
1452
1454
float ambient_xfer_coeff = mpc.ambient_xfer_coeff_fan0 ;
1453
1455
#if ENABLED(MPC_INCLUDE_FAN)
1454
- const uint8_t fan_index = EITHER (MPC_FAN_0_ACTIVE_HOTEND, MPC_FAN_0_ALL_HOTENDS ) ? 0 : ee;
1456
+ const uint8_t fan_index = EITHER (MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND ) ? 0 : ee;
1455
1457
const float fan_fraction = TERN_ (MPC_FAN_0_ACTIVE_HOTEND, !this_hotend ? 0 .0f : ) fan_speed[fan_index] * RECIPROCAL (255 );
1456
1458
ambient_xfer_coeff += fan_fraction * mpc.fan255_adjustment ;
1457
1459
#endif
0 commit comments