From 2bfc6fe1b06b341e80bd0da85e2cccee484c21f8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Sep 2016 19:56:03 -0500 Subject: [PATCH 1/3] Move XYZ constants closer to the top --- Marlin/Marlin_main.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 497aabd22..a0722ba56 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -555,6 +555,26 @@ static bool send_ok[BUFSIZE]; #define KEEPALIVE_STATE(n) ; #endif // HOST_KEEPALIVE_FEATURE +#define DEFINE_PGM_READ_ANY(type, reader) \ + static inline type pgm_read_any(const type *p) \ + { return pgm_read_##reader##_near(p); } + +DEFINE_PGM_READ_ANY(float, float); +DEFINE_PGM_READ_ANY(signed char, byte); + +#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \ + static const PROGMEM type array##_P[XYZ] = \ + { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }; \ + static inline type array(int axis) \ + { return pgm_read_any(&array##_P[axis]); } + +XYZ_CONSTS_FROM_CONFIG(float, base_min_pos, MIN_POS); +XYZ_CONSTS_FROM_CONFIG(float, base_max_pos, MAX_POS); +XYZ_CONSTS_FROM_CONFIG(float, base_home_pos, HOME_POS); +XYZ_CONSTS_FROM_CONFIG(float, max_length, MAX_LENGTH); +XYZ_CONSTS_FROM_CONFIG(float, home_bump_mm, HOME_BUMP_MM); +XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR); + /** * *************************************************************************** * ******************************** FUNCTIONS ******************************** @@ -1406,26 +1426,6 @@ bool get_target_extruder_from_command(int code) { return false; } -#define DEFINE_PGM_READ_ANY(type, reader) \ - static inline type pgm_read_any(const type *p) \ - { return pgm_read_##reader##_near(p); } - -DEFINE_PGM_READ_ANY(float, float); -DEFINE_PGM_READ_ANY(signed char, byte); - -#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \ - static const PROGMEM type array##_P[XYZ] = \ - { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }; \ - static inline type array(int axis) \ - { return pgm_read_any(&array##_P[axis]); } - -XYZ_CONSTS_FROM_CONFIG(float, base_min_pos, MIN_POS); -XYZ_CONSTS_FROM_CONFIG(float, base_max_pos, MAX_POS); -XYZ_CONSTS_FROM_CONFIG(float, base_home_pos, HOME_POS); -XYZ_CONSTS_FROM_CONFIG(float, max_length, MAX_LENGTH); -XYZ_CONSTS_FROM_CONFIG(float, home_bump_mm, HOME_BUMP_MM); -XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR); - #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE) bool extruder_duplication_enabled = false; // Used in Dual X mode 2 #endif From 68ba45572e2c189abf4b8f06c9719d5aa1f47940 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Sep 2016 21:09:30 -0500 Subject: [PATCH 2/3] Don't say "heating complete" unless done --- Marlin/Marlin_main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index a0722ba56..db10b778b 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -4816,7 +4816,8 @@ inline void gcode_M109() { } while (wait_for_heatup && TEMP_CONDITIONS); - LCD_MESSAGEPGM(MSG_HEATING_COMPLETE); + if (wait_for_heatup) LCD_MESSAGEPGM(MSG_HEATING_COMPLETE); + KEEPALIVE_STATE(IN_HANDLER); } @@ -4934,7 +4935,7 @@ inline void gcode_M109() { } while (wait_for_heatup && TEMP_BED_CONDITIONS); - LCD_MESSAGEPGM(MSG_BED_DONE); + if (wait_for_heatup) LCD_MESSAGEPGM(MSG_BED_DONE); KEEPALIVE_STATE(IN_HANDLER); } From 6ac9d895ca5006d7fb33b071b9995f70fcbc5ae1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Sep 2016 23:57:12 -0500 Subject: [PATCH 3/3] Tweak Filament Width variables --- Marlin/Marlin.h | 12 ++++++------ Marlin/Marlin_main.cpp | 14 ++++++-------- Marlin/planner.cpp | 12 ++++++------ Marlin/temperature.cpp | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 581f078f7..da9bc0de9 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -342,12 +342,12 @@ float code_value_temp_diff(); #endif #if ENABLED(FILAMENT_WIDTH_SENSOR) - extern float filament_width_nominal; //holds the theoretical filament diameter i.e., 3.00 or 1.75 - extern bool filament_sensor; //indicates that filament sensor readings should control extrusion - extern float filament_width_meas; //holds the filament diameter as accurately measured - extern int8_t measurement_delay[]; //ring buffer to delay measurement - extern int filwidth_delay_index1, filwidth_delay_index2; //ring buffer index. used by planner, temperature, and main code - extern int meas_delay_cm; //delay distance + extern bool filament_sensor; // Flag that filament sensor readings should control extrusion + extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75 + filament_width_meas; // Measured filament diameter + extern int8_t measurement_delay[]; // Ring buffer to delay measurement + extern int filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code + extern int meas_delay_cm; // Delay distance #endif #if ENABLED(FILAMENT_CHANGE_FEATURE) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index db10b778b..7ab7af853 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -500,13 +500,11 @@ static uint8_t target_extruder; #endif #if ENABLED(FILAMENT_WIDTH_SENSOR) - //Variables for Filament Sensor input - float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA; //Set nominal filament width, can be changed with M404 bool filament_sensor = false; //M405 turns on filament_sensor control, M406 turns it off - float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter - int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; //ring buffer to delay measurement store extruder factor after subtracting 100 - int filwidth_delay_index1 = 0; //index into ring buffer - int filwidth_delay_index2 = -1; //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized + float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA, // Nominal filament width. Change with M404 + filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; // Measured filament diameter + int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100 + int filwidth_delay_index[2] = { 0, -1 }; // Indexes into ring buffer int meas_delay_cm = MEASUREMENT_DELAY_CM; //distance delay setting #endif @@ -6137,13 +6135,13 @@ inline void gcode_M400() { stepper.synchronize(); } if (code_seen('D')) meas_delay_cm = code_value_int(); NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY); - if (filwidth_delay_index2 == -1) { // Initialize the ring buffer if not done since startup + if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup int temp_ratio = thermalManager.widthFil_to_size_ratio(); for (uint8_t i = 0; i < COUNT(measurement_delay); ++i) measurement_delay[i] = temp_ratio - 100; // Subtract 100 to scale within a signed byte - filwidth_delay_index1 = filwidth_delay_index2 = 0; + filwidth_delay_index[0] = filwidth_delay_index[1] = 0; } filament_sensor = true; diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 3a1ffd139..066c1445b 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -868,7 +868,7 @@ void Planner::check_axes_activity() { static float filwidth_e_count = 0, filwidth_delay_dist = 0; //FMM update ring buffer used for delay with filament measurements - if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index2 >= 0) { //only for extruder with filament sensor and if ring buffer is initialized + if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index[1] >= 0) { //only for extruder with filament sensor and if ring buffer is initialized const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10; @@ -883,16 +883,16 @@ void Planner::check_axes_activity() { while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM; // Convert into an index into the measurement array - filwidth_delay_index1 = (int)(filwidth_delay_dist * 0.1 + 0.0001); + filwidth_delay_index[0] = (int)(filwidth_delay_dist * 0.1 + 0.0001); // If the index has changed (must have gone forward)... - if (filwidth_delay_index1 != filwidth_delay_index2) { + if (filwidth_delay_index[0] != filwidth_delay_index[1]) { filwidth_e_count = 0; // Reset the E movement counter int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char do { - filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot - measurement_delay[filwidth_delay_index2] = meas_sample; // Store the measurement - } while (filwidth_delay_index1 != filwidth_delay_index2); // More slots to fill? + filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot + measurement_delay[filwidth_delay_index[1]] = meas_sample; // Store the measurement + } while (filwidth_delay_index[0] != filwidth_delay_index[1]); // More slots to fill? } } } diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index c6122a4c6..084559d03 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -755,7 +755,7 @@ void Temperature::manage_heater() { // Control the extruder rate based on the width sensor #if ENABLED(FILAMENT_WIDTH_SENSOR) if (filament_sensor) { - meas_shift_index = filwidth_delay_index1 - meas_delay_cm; + meas_shift_index = filwidth_delay_index[0] - meas_delay_cm; if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed // Get the delayed info and add 100 to reconstitute to a percent of