Refactor. Move lcd_commands_func1() to first_lay_cal.cpp and rename it to lay1cal_square(). Remove its constant parameters. Move remaining G1 code to lay1cal_meander(). Saves 6B of FLASH memory.

This commit is contained in:
Marek Bel 2019-06-12 01:36:48 +02:00
parent 60cc3d58ec
commit d528a53526
3 changed files with 47 additions and 37 deletions

View File

@ -160,10 +160,49 @@ static const char * const cmd_meander[] PROGMEM =
cmd_meander_15,
};
void lay1cal_meander()
//! @brief Count extrude length
//!
//! @param layer_heigth layer heigth in mm
//! @param extrusion_width extrusion width in mm
//! @param extrusion_length extrusion length in mm
//! @return filament length in mm which needs to be extruded to form line
static constexpr float count_e(float layer_heigth, float extrusion_width, float extrusion_length)
{
return (extrusion_length * layer_heigth * extrusion_width / (M_PI * pow(1.75, 2) / 4));
}
static const float width = 0.4;
static const float length = 20 - width;
static const float extr = count_e(0.2, width, length);
void lay1cal_meander(char *cmd_buffer)
{
for (uint8_t i = 0; i < (sizeof(cmd_meander)/sizeof(cmd_meander[0])); ++i)
{
enquecommand_P(static_cast<char*>(pgm_read_ptr(&cmd_meander[i])));
}
sprintf_P(cmd_buffer, PSTR("G1 X50 Y35 E%-.3f"), extr);
enquecommand(cmd_buffer);
}
//! @brief Print square
//!
//! This function needs to be called 16 times for i from 0 to 15.
//!
//! @par cmd_buffer character buffer needed to format gcodes
//! @par i iteration
void lay1cal_square(char *cmd_buffer, uint8_t i)
{
const float extr_short_segment = count_e(0.2, width, width);
static const char fmt1[] PROGMEM = "G1 X%d Y%-.2f E%-.3f";
static const char fmt2[] PROGMEM = "G1 Y%-.2f E%-.3f";
sprintf_P(cmd_buffer, fmt1, 70, (35 - i*width * 2), extr);
enquecommand(cmd_buffer);
sprintf_P(cmd_buffer, fmt2, (35 - (2 * i + 1)*width), extr_short_segment);
enquecommand(cmd_buffer);
sprintf_P(cmd_buffer, fmt1, 50, (35 - (2 * i + 1)*width), extr);
enquecommand(cmd_buffer);
sprintf_P(cmd_buffer, fmt2, (35 - (i + 1)*width * 2), extr_short_segment);
enquecommand(cmd_buffer);
}

View File

@ -12,8 +12,7 @@
void lay1cal_preheat();
void lay1cal_intro_line(char *cmd_buffer, uint8_t filament);
void lay1cal_before_meander();
void lay1cal_meander();
void lay1cal_meander(char *cmd_buffer);
void lay1cal_square(char *cmd_buffer, uint8_t i);
#endif /* FIRMWARE_FIRST_LAY_CAL_H_ */

View File

@ -246,7 +246,6 @@ static char snmm_stop_print_menu();
#ifdef SDCARD_SORT_ALPHA
static void lcd_sort_type_set();
#endif
static constexpr float count_e(float layer_heigth, float extrusion_width, float extrusion_length);
static void lcd_babystep_z();
static void lcd_send_status();
#ifdef FARM_CONNECT_MESSAGE
@ -1061,21 +1060,6 @@ static void lcd_status_screen()
feedmultiply = 999;
}
//! extracted common code from lcd_commands into a separate function
//! along with the sprintf_P optimization this change gained more than 1.6KB
static void lcd_commands_func1(char *cmd1, uint8_t i, float width, float extr, float extr_short_segment){
static const char fmt1[] PROGMEM = "G1 X%d Y%-.2f E%-.3f";
static const char fmt2[] PROGMEM = "G1 Y%-.2f E%-.3f";
sprintf_P(cmd1, fmt1, 70, (35 - i*width * 2), extr);
enquecommand(cmd1);
sprintf_P(cmd1, fmt2, (35 - (2 * i + 1)*width), extr_short_segment);
enquecommand(cmd1);
sprintf_P(cmd1, fmt1, 50, (35 - (2 * i + 1)*width), extr);
enquecommand(cmd1);
sprintf_P(cmd1, fmt2, (35 - (i + 1)*width * 2), extr_short_segment);
enquecommand(cmd1);
}
void lcd_commands()
{
if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE)
@ -1363,10 +1347,6 @@ void lcd_commands()
{
char cmd1[30];
static uint8_t filament = 0;
const float width = 0.4;
const float length = 20 - width;
const float extr = count_e(0.2, width, length);
const float extr_short_segment = count_e(0.2, width, width);
if(lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
@ -1413,37 +1393,34 @@ void lcd_commands()
lcd_commands_step = 7;
break;
case 7:
lay1cal_meander();
sprintf_P(cmd1, PSTR("G1 X50 Y35 E%-.3f"), extr);
enquecommand(cmd1);
lay1cal_meander(cmd1);
lcd_commands_step = 6;
break;
case 6:
for (uint8_t i = 0; i < 4; i++)
{
lcd_commands_func1(cmd1, i, width, extr, extr_short_segment );
lay1cal_square(cmd1, i);
}
lcd_commands_step = 5;
break;
case 5:
for (uint8_t i = 4; i < 8; i++)
{
lcd_commands_func1(cmd1, i, width, extr, extr_short_segment );
lay1cal_square(cmd1, i);
}
lcd_commands_step = 4;
break;
case 4:
for (uint8_t i = 8; i < 12; i++)
{
lcd_commands_func1(cmd1, i, width, extr, extr_short_segment );
lay1cal_square(cmd1, i);
}
lcd_commands_step = 3;
break;
case 3:
for (uint8_t i = 12; i < 16; i++)
{
lcd_commands_func1(cmd1, i, width, extr, extr_short_segment );
lay1cal_square(cmd1, i);
}
lcd_commands_step = 2;
break;
@ -1663,11 +1640,6 @@ void lcd_commands()
}
static constexpr float count_e(float layer_heigth, float extrusion_width, float extrusion_length) {
//returns filament length in mm which needs to be extrude to form line with extrusion_length * extrusion_width * layer heigth dimensions
return (extrusion_length * layer_heigth * extrusion_width / (M_PI * pow(1.75, 2) / 4));
}
void lcd_return_to_status()
{
lcd_refresh(); // to maybe revive the LCD if static electricity killed it.