Merge pull request #3574 from leptun/extra_optimizations

More optimizations for 3.12 to fit
This commit is contained in:
Alex Voinea 2022-08-29 19:25:46 +03:00 committed by GitHub
commit 4e7d686b83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 55 deletions

View file

@ -641,7 +641,6 @@ void crashdet_detected(uint8_t mask)
lcd_setstatus(msg); lcd_setstatus(msg);
gcode_G28(true, true, false); //home X and Y gcode_G28(true, true, false); //home X and Y
st_synchronize();
if (automatic_recovery_after_crash) { if (automatic_recovery_after_crash) {
enquecommand_P(PSTR("CRASH_RECOVER")); enquecommand_P(PSTR("CRASH_RECOVER"));
@ -9746,7 +9745,6 @@ if(0)
lcd_update_enable(true); lcd_update_enable(true);
*/ */
eFilamentAction=FilamentAction::AutoLoad; eFilamentAction=FilamentAction::AutoLoad;
bFilamentFirstRun=false;
if(target_temperature[0] >= extrude_min_temp){ if(target_temperature[0] >= extrude_min_temp){
bFilamentPreheatState=true; bFilamentPreheatState=true;
// mFilamentItem(target_temperature[0],target_temperature_bed); // mFilamentItem(target_temperature[0],target_temperature_bed);
@ -11315,7 +11313,7 @@ void restore_print_from_eeprom(bool mbl_was_active) {
int feedmultiply_rec; int feedmultiply_rec;
uint8_t fan_speed_rec; uint8_t fan_speed_rec;
char cmd[48]; char cmd[48];
char filename[13]; char filename[FILENAME_LENGTH];
uint8_t depth = 0; uint8_t depth = 0;
char dir_name[9]; char dir_name[9];

View file

@ -1015,7 +1015,7 @@ void SdBaseFile::printFatTime( uint16_t fatTime) {
* the value zero, false, is returned for failure. * the value zero, false, is returned for failure.
*/ */
bool SdBaseFile::printName() { bool SdBaseFile::printName() {
char name[13]; char name[FILENAME_LENGTH];
if (!getFilename(name)) return false; if (!getFilename(name)) return false;
MYSERIAL.print(name); MYSERIAL.print(name);
return true; return true;

View file

@ -304,7 +304,7 @@ void CardReader::getAbsFilename(char *t)
while(*t!=0 && cnt< MAXPATHNAMELENGTH) while(*t!=0 && cnt< MAXPATHNAMELENGTH)
{t++;cnt++;} //crawl counter forward. {t++;cnt++;} //crawl counter forward.
} }
if(cnt<MAXPATHNAMELENGTH-13) if(cnt < MAXPATHNAMELENGTH - FILENAME_LENGTH)
file.getFilename(t); file.getFilename(t);
else else
t[0]=0; t[0]=0;

View file

@ -89,7 +89,7 @@ public:
bool logging; bool logging;
bool sdprinting ; bool sdprinting ;
bool cardOK ; bool cardOK ;
char filename[13]; char filename[FILENAME_LENGTH];
// There are scenarios when simple modification time is not enough (on MS Windows) // There are scenarios when simple modification time is not enough (on MS Windows)
// Therefore these timestamps hold the most recent one of creation/modification date/times // Therefore these timestamps hold the most recent one of creation/modification date/times
uint16_t crmodTime, crmodDate; uint16_t crmodTime, crmodDate;

View file

@ -416,7 +416,7 @@ void get_command()
// Line numbers must be first in buffer // Line numbers must be first in buffer
if ((strstr(cmdbuffer+bufindw+CMDHDRSIZE, "PRUSA") == NULL) && if ((strstr_P(cmdbuffer+bufindw+CMDHDRSIZE, PSTR("PRUSA")) == NULL) &&
(cmdbuffer[bufindw+CMDHDRSIZE] == 'N')) { (cmdbuffer[bufindw+CMDHDRSIZE] == 'N')) {
// Line number met. When sending a G-code over a serial line, each line may be stamped with its index, // Line number met. When sending a G-code over a serial line, each line may be stamped with its index,

View file

@ -104,7 +104,7 @@ char *ftostr43(const float &x, uint8_t offset)
//Float to string with 1.23 format //Float to string with 1.23 format
char *ftostr12ns(const float &x) char *ftostr12ns(const float &x)
{ {
long xx = x * 100; int xx = x * 100;
xx = abs(xx); xx = abs(xx);
conv[0] = (xx / 100) % 10 + '0'; conv[0] = (xx / 100) % 10 + '0';

View file

@ -418,9 +418,9 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
for (uint8_t i = 0; i < npts; ++i) { for (uint8_t i = 0; i < npts; ++i) {
float x = vec_x[0] * measured_pts[i * 2] + vec_y[0] * measured_pts[i * 2 + 1] + cntr[0]; float x = vec_x[0] * measured_pts[i * 2] + vec_y[0] * measured_pts[i * 2 + 1] + cntr[0];
float y = vec_x[1] * measured_pts[i * 2] + vec_y[1] * measured_pts[i * 2 + 1] + cntr[1]; float y = vec_x[1] * measured_pts[i * 2] + vec_y[1] * measured_pts[i * 2 + 1] + cntr[1];
float errX = sqr(pgm_read_float(true_pts + i * 2) - x); float errX = pgm_read_float(true_pts + i * 2) - x;
float errY = sqr(pgm_read_float(true_pts + i * 2 + 1) - y); float errY = pgm_read_float(true_pts + i * 2 + 1) - y;
float err = sqrt(errX + errY); float err = hypot(errX, errY);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) { if (verbosity_level >= 10) {
SERIAL_ECHOPGM("point #"); SERIAL_ECHOPGM("point #");
@ -434,15 +434,15 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
if(verbosity_level >= 20) SERIAL_ECHOPGM("Point on first row"); if(verbosity_level >= 20) SERIAL_ECHOPGM("Point on first row");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
float w = point_weight_y(i, measured_pts[2 * i + 1]); float w = point_weight_y(i, measured_pts[2 * i + 1]);
if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X || if (errX > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X ||
(w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y)) { (w != 0.f && errY > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y)) {
result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED; result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM(", weigth Y: "); SERIAL_ECHOPGM(", weigth Y: ");
MYSERIAL.print(w); MYSERIAL.print(w);
if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X) SERIAL_ECHOPGM(", error X > max. error X"); if (errX > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X) SERIAL_ECHOPGM(", error X > max. error X");
if (w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y) SERIAL_ECHOPGM(", error Y > max. error Y"); if (w != 0.f && errY > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y) SERIAL_ECHOPGM(", error Y > max. error Y");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
@ -477,9 +477,9 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
SERIAL_ECHOPGM("error: "); SERIAL_ECHOPGM("error: ");
MYSERIAL.print(err); MYSERIAL.print(err);
SERIAL_ECHOPGM(", error X: "); SERIAL_ECHOPGM(", error X: ");
MYSERIAL.print(sqrt(errX)); MYSERIAL.print(errX);
SERIAL_ECHOPGM(", error Y: "); SERIAL_ECHOPGM(", error Y: ");
MYSERIAL.print(sqrt(errY)); MYSERIAL.print(errY);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
@ -645,7 +645,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
SERIAL_ECHOPGM(", "); SERIAL_ECHOPGM(", ");
MYSERIAL.print(pgm_read_float(true_pts + i * 2 + 1), 5); MYSERIAL.print(pgm_read_float(true_pts + i * 2 + 1), 5);
SERIAL_ECHOPGM("), error: "); SERIAL_ECHOPGM("), error: ");
MYSERIAL.print(sqrt(sqr(measured_pts[i * 2] - x) + sqr(measured_pts[i * 2 + 1] - y))); MYSERIAL.print( hypot(measured_pts[i * 2] - x, measured_pts[i * 2 + 1] - y) );
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
@ -810,7 +810,7 @@ void world2machine_read_valid(float vec_x[2], float vec_y[2], float cntr[2])
else else
{ {
// Length of the vec_x shall be close to unity. // Length of the vec_x shall be close to unity.
float l = sqrt(vec_x[0] * vec_x[0] + vec_x[1] * vec_x[1]); float l = hypot(vec_x[0], vec_x[1]);
if (l < 0.9 || l > 1.1) if (l < 0.9 || l > 1.1)
{ {
#if 0 #if 0
@ -821,7 +821,7 @@ void world2machine_read_valid(float vec_x[2], float vec_y[2], float cntr[2])
reset = true; reset = true;
} }
// Length of the vec_y shall be close to unity. // Length of the vec_y shall be close to unity.
l = sqrt(vec_y[0] * vec_y[0] + vec_y[1] * vec_y[1]); l = hypot(vec_y[0], vec_y[1]);
if (l < 0.9 || l > 1.1) if (l < 0.9 || l > 1.1)
{ {
#if 0 #if 0
@ -832,7 +832,7 @@ void world2machine_read_valid(float vec_x[2], float vec_y[2], float cntr[2])
reset = true; reset = true;
} }
// Correction of the zero point shall be reasonably small. // Correction of the zero point shall be reasonably small.
l = sqrt(cntr[0] * cntr[0] + cntr[1] * cntr[1]); l = hypot(cntr[0], cntr[1]);
if (l > 15.f) if (l > 15.f)
{ {
#if 0 #if 0
@ -1579,7 +1579,7 @@ inline bool improve_bed_induction_sensor_point()
// Trim the vector from center_old_[x,y] to destination[x,y] by the bed dimensions. // Trim the vector from center_old_[x,y] to destination[x,y] by the bed dimensions.
float vx = destination[X_AXIS] - center_old_x; float vx = destination[X_AXIS] - center_old_x;
float vy = destination[Y_AXIS] - center_old_y; float vy = destination[Y_AXIS] - center_old_y;
float l = sqrt(vx*vx+vy*vy); float l = hypot(vx, vy);
float t; float t;
if (destination[X_AXIS] < X_MIN_POS) { if (destination[X_AXIS] < X_MIN_POS) {
// Exiting the bed at xmin. // Exiting the bed at xmin.
@ -2441,16 +2441,16 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) { if (verbosity_level >= 10) {
// Length of the vec_x // Length of the vec_x
float l = sqrt(vec_x[0] * vec_x[0] + vec_x[1] * vec_x[1]); float l = hypot(vec_x[0], vec_x[1]);
SERIAL_ECHOLNPGM("X vector length:"); SERIAL_ECHOLNPGM("X vector length:");
MYSERIAL.println(l); MYSERIAL.println(l);
// Length of the vec_y // Length of the vec_y
l = sqrt(vec_y[0] * vec_y[0] + vec_y[1] * vec_y[1]); l = hypot(vec_y[0], vec_y[1]);
SERIAL_ECHOLNPGM("Y vector length:"); SERIAL_ECHOLNPGM("Y vector length:");
MYSERIAL.println(l); MYSERIAL.println(l);
// Zero point correction // Zero point correction
l = sqrt(cntr[0] * cntr[0] + cntr[1] * cntr[1]); l = hypot(cntr[0], cntr[1]);
SERIAL_ECHOLNPGM("Zero point correction:"); SERIAL_ECHOLNPGM("Zero point correction:");
MYSERIAL.println(l); MYSERIAL.println(l);

View file

@ -99,8 +99,6 @@ static float previous_speed[NUM_AXIS]; // Speed of previous path line segment
static float previous_nominal_speed; // Nominal speed of previous path line segment static float previous_nominal_speed; // Nominal speed of previous path line segment
static float previous_safe_speed; // Exit speed limited by a jerk to full halt of a previous last segment. static float previous_safe_speed; // Exit speed limited by a jerk to full halt of a previous last segment.
uint8_t maxlimit_status;
#ifdef AUTOTEMP #ifdef AUTOTEMP
float autotemp_max=250; float autotemp_max=250;
float autotemp_min=210; float autotemp_min=210;
@ -658,7 +656,7 @@ void planner_reset_position()
// Apply inverse world correction matrix. // Apply inverse world correction matrix.
machine2world(current_position[X_AXIS], current_position[Y_AXIS]); machine2world(current_position[X_AXIS], current_position[Y_AXIS]);
memcpy(destination, current_position, sizeof(destination)); set_destination_to_current();
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
memcpy(position_float, current_position, sizeof(position_float)); memcpy(position_float, current_position, sizeof(position_float));
#endif #endif

View file

@ -1737,7 +1737,7 @@ static void lcd_support_menu()
if (((menu_item - 1) == menu_line) && lcd_draw_update) { if (((menu_item - 1) == menu_line) && lcd_draw_update) {
lcd_set_cursor(2, menu_row); lcd_set_cursor(2, menu_row);
ip4_to_str(_md->ip_str, (uint8_t*)(&_md->ip)); ip4_to_str(_md->ip_str, (uint8_t*)(&_md->ip));
lcd_printf_P(PSTR("%s"), _md->ip_str); lcd_print(_md->ip_str);
} }
} }
@ -1750,7 +1750,7 @@ static void lcd_support_menu()
if (((menu_item - 1) == menu_line) && lcd_draw_update) { if (((menu_item - 1) == menu_line) && lcd_draw_update) {
lcd_set_cursor(2, menu_row); lcd_set_cursor(2, menu_row);
ip4_to_str(_md->ip_str, (uint8_t*)(&IP_address)); ip4_to_str(_md->ip_str, (uint8_t*)(&IP_address));
lcd_printf_P(PSTR("%s"), _md->ip_str); lcd_print(_md->ip_str);
} }
} }
@ -1833,7 +1833,6 @@ void lcd_set_filament_oq_meass()
FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad' FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
bool bFilamentFirstRun;
bool bFilamentPreheatState; bool bFilamentPreheatState;
bool bFilamentAction=false; bool bFilamentAction=false;
static bool bFilamentWaitingFlag=false; static bool bFilamentWaitingFlag=false;
@ -2343,7 +2342,6 @@ static void lcd_menu_AutoLoadFilament()
static void preheat_or_continue() static void preheat_or_continue()
{ {
bFilamentFirstRun = false;
if (target_temperature[0] >= extrude_min_temp) if (target_temperature[0] >= extrude_min_temp)
{ {
bFilamentPreheatState = true; bFilamentPreheatState = true;
@ -2684,8 +2682,6 @@ static void lcd_babystep_z()
lcd_draw_update = 1; lcd_draw_update = 1;
//SERIAL_ECHO("Z baby step: "); //SERIAL_ECHO("Z baby step: ");
//SERIAL_ECHO(_md->babystepMem[2]); //SERIAL_ECHO(_md->babystepMem[2]);
// Wait 90 seconds before closing the live adjust dialog.
lcd_timeoutToStatus.start();
} }
if (lcd_encoder != 0) if (lcd_encoder != 0)
@ -3569,11 +3565,7 @@ void lcd_menu_show_sensors_state() // NOT static due to using ins
{ {
lcd_timeoutToStatus.stop(); lcd_timeoutToStatus.stop();
lcd_show_sensors_state(); lcd_show_sensors_state();
if(LCD_CLICKED) menu_back_if_clicked();
{
lcd_timeoutToStatus.start();
menu_back();
}
} }
void prusa_statistics_err(char c){ void prusa_statistics_err(char c){
@ -5584,7 +5576,6 @@ static void mmu_cut_filament_menu()
else else
{ {
eFilamentAction=FilamentAction::MmuCut; eFilamentAction=FilamentAction::MmuCut;
bFilamentFirstRun=false;
if(target_temperature[0] >= extrude_min_temp) if(target_temperature[0] >= extrude_min_temp)
{ {
bFilamentPreheatState=true; bFilamentPreheatState=true;
@ -5983,10 +5974,8 @@ static void lcd_main_menu()
else else
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
{ {
bFilamentFirstRun=true;
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament); MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
} }
bFilamentFirstRun=true;
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament); MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
} }
MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu); MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
@ -6171,15 +6160,17 @@ static void lcd_tune_menu()
#ifdef TMC2130 #ifdef TMC2130
if(!farm_mode) if(!farm_mode)
{ {
if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set); if (SilentModeMenu == SILENT_MODE_NORMAL) {
else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set); MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
if (lcd_crash_detect_enabled()) {
if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
{ } else {
if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch); MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch); }
} else {
MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
} }
else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
} }
#else //TMC2130 #else //TMC2130
if (!farm_mode) { //dont show in menu if we are in farm mode if (!farm_mode) { //dont show in menu if we are in farm mode

View file

@ -182,7 +182,6 @@ enum class FilamentAction : uint_least8_t
}; };
extern FilamentAction eFilamentAction; extern FilamentAction eFilamentAction;
extern bool bFilamentFirstRun;
extern bool bFilamentPreheatState; extern bool bFilamentPreheatState;
extern bool bFilamentAction; extern bool bFilamentAction;
void mFilamentItem(uint16_t nTemp,uint16_t nTempBed); void mFilamentItem(uint16_t nTemp,uint16_t nTempBed);