Reduce ultralcd.cpp redundancies

This commit is contained in:
Scott Lahteine 2014-12-18 07:30:05 -08:00
parent e69313fc2b
commit 63e1665fa9

View file

@ -184,6 +184,14 @@ menuFunc_t callbackFunc;
// place-holders for Ki and Kd edits // place-holders for Ki and Kd edits
float raw_Ki, raw_Kd; float raw_Ki, raw_Kd;
static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
if (currentMenu != menu) {
currentMenu = menu;
encoderPosition = encoder;
if (feedback) lcd_quick_feedback();
}
}
/* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */ /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
static void lcd_status_screen() static void lcd_status_screen()
{ {
@ -218,9 +226,7 @@ static void lcd_status_screen()
if (current_click) if (current_click)
{ {
currentMenu = lcd_main_menu; lcd_goto_menu(lcd_main_menu);
encoderPosition = 0;
lcd_quick_feedback();
lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it. lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
#ifdef FILAMENT_LCD_DISPLAY #ifdef FILAMENT_LCD_DISPLAY
message_millis=millis(); //get status message to show up for a while message_millis=millis(); //get status message to show up for a while
@ -263,10 +269,8 @@ static void lcd_status_screen()
#ifdef ULTIPANEL #ifdef ULTIPANEL
static void lcd_return_to_status() static void lcd_return_to_status()
{ {
encoderPosition = 0; lcd_goto_menu(lcd_status_screen, 0, false);
currentMenu = lcd_status_screen;
} }
static void lcd_sdcard_pause() static void lcd_sdcard_pause()
{ {
card.pauseSDPrint(); card.pauseSDPrint();
@ -357,65 +361,20 @@ void lcd_set_home_offsets()
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
static void lcd_babystep_x()
{
if (encoderPosition != 0)
{
babystepsTodo[X_AXIS]+=(int)encoderPosition;
encoderPosition=0;
lcdDrawUpdate = 1;
}
if (lcdDrawUpdate)
{
lcd_implementation_drawedit(PSTR(MSG_BABYSTEPPING_X),"");
}
if (LCD_CLICKED)
{
lcd_quick_feedback();
currentMenu = lcd_tune_menu;
encoderPosition = 0;
}
}
static void lcd_babystep_y() static void _lcd_babystep(int axis, const char *msg) {
{ if (encoderPosition != 0) {
if (encoderPosition != 0) babystepsTodo[axis] += (int)encoderPosition;
{
babystepsTodo[Y_AXIS]+=(int)encoderPosition;
encoderPosition = 0; encoderPosition = 0;
lcdDrawUpdate = 1; lcdDrawUpdate = 1;
} }
if (lcdDrawUpdate) if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(msg), "");
{ if (LCD_CLICKED) lcd_goto_menu(lcd_tune_menu);
lcd_implementation_drawedit(PSTR(MSG_BABYSTEPPING_Y),"");
}
if (LCD_CLICKED)
{
lcd_quick_feedback();
currentMenu = lcd_tune_menu;
encoderPosition = 0;
}
} }
static void lcd_babystep_x() { _lcd_babystep(X_AXIS, MSG_BABYSTEPPING_X); }
static void lcd_babystep_y() { _lcd_babystep(Y_AXIS, MSG_BABYSTEPPING_Y); }
static void lcd_babystep_z() { _lcd_babystep(Z_AXIS, MSG_BABYSTEPPING_Z); }
static void lcd_babystep_z()
{
if (encoderPosition != 0)
{
babystepsTodo[Z_AXIS]+=BABYSTEP_Z_MULTIPLICATOR*(int)encoderPosition;
encoderPosition=0;
lcdDrawUpdate = 1;
}
if (lcdDrawUpdate)
{
lcd_implementation_drawedit(PSTR(MSG_BABYSTEPPING_Z),"");
}
if (LCD_CLICKED)
{
lcd_quick_feedback();
currentMenu = lcd_tune_menu;
encoderPosition = 0;
}
}
#endif //BABYSTEPPING #endif //BABYSTEPPING
static void lcd_tune_menu() static void lcd_tune_menu()
@ -644,96 +603,28 @@ static void lcd_prepare_menu()
float move_menu_scale; float move_menu_scale;
static void lcd_move_menu_axis(); static void lcd_move_menu_axis();
static void lcd_move_x() static void _lcd_move(const char *name, int axis, int min, int max) {
{ if (encoderPosition != 0) {
if (encoderPosition != 0)
{
refresh_cmd_timeout(); refresh_cmd_timeout();
current_position[X_AXIS] += float((int)encoderPosition) * move_menu_scale; current_position[axis] += float((int)encoderPosition) * move_menu_scale;
if (min_software_endstops && current_position[X_AXIS] < X_MIN_POS) if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
current_position[X_AXIS] = X_MIN_POS; if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
if (max_software_endstops && current_position[X_AXIS] > X_MAX_POS)
current_position[X_AXIS] = X_MAX_POS;
encoderPosition = 0; encoderPosition = 0;
#ifdef DELTA #ifdef DELTA
calculate_delta(current_position); calculate_delta(current_position);
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder); plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
#else #else
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
#endif #endif
lcdDrawUpdate = 1; lcdDrawUpdate = 1;
} }
if (lcdDrawUpdate) if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
{ if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
lcd_implementation_drawedit(PSTR("X"), ftostr31(current_position[X_AXIS]));
}
if (LCD_CLICKED)
{
lcd_quick_feedback();
currentMenu = lcd_move_menu_axis;
encoderPosition = 0;
}
}
static void lcd_move_y()
{
if (encoderPosition != 0)
{
refresh_cmd_timeout();
current_position[Y_AXIS] += float((int)encoderPosition) * move_menu_scale;
if (min_software_endstops && current_position[Y_AXIS] < Y_MIN_POS)
current_position[Y_AXIS] = Y_MIN_POS;
if (max_software_endstops && current_position[Y_AXIS] > Y_MAX_POS)
current_position[Y_AXIS] = Y_MAX_POS;
encoderPosition = 0;
#ifdef DELTA
calculate_delta(current_position);
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[Y_AXIS]/60, active_extruder);
#else
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Y_AXIS]/60, active_extruder);
#endif
lcdDrawUpdate = 1;
}
if (lcdDrawUpdate)
{
lcd_implementation_drawedit(PSTR("Y"), ftostr31(current_position[Y_AXIS]));
}
if (LCD_CLICKED)
{
lcd_quick_feedback();
currentMenu = lcd_move_menu_axis;
encoderPosition = 0;
}
}
static void lcd_move_z()
{
if (encoderPosition != 0)
{
refresh_cmd_timeout();
current_position[Z_AXIS] += float((int)encoderPosition) * move_menu_scale;
if (min_software_endstops && current_position[Z_AXIS] < Z_MIN_POS)
current_position[Z_AXIS] = Z_MIN_POS;
if (max_software_endstops && current_position[Z_AXIS] > Z_MAX_POS)
current_position[Z_AXIS] = Z_MAX_POS;
encoderPosition = 0;
#ifdef DELTA
calculate_delta(current_position);
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS]/60, active_extruder);
#else
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS]/60, active_extruder);
#endif
lcdDrawUpdate = 1;
}
if (lcdDrawUpdate)
{
lcd_implementation_drawedit(PSTR("Z"), ftostr31(current_position[Z_AXIS]));
}
if (LCD_CLICKED)
{
lcd_quick_feedback();
currentMenu = lcd_move_menu_axis;
encoderPosition = 0;
}
} }
static void lcd_move_x() { _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS); }
static void lcd_move_y() { _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
static void lcd_move_z() { _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
static void lcd_move_e() static void lcd_move_e()
{ {
if (encoderPosition != 0) if (encoderPosition != 0)
@ -752,12 +643,7 @@ static void lcd_move_e()
{ {
lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS])); lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
} }
if (LCD_CLICKED) if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
{
lcd_quick_feedback();
currentMenu = lcd_move_menu_axis;
encoderPosition = 0;
}
} }
static void lcd_move_menu_axis() static void lcd_move_menu_axis()
@ -951,12 +837,7 @@ static void lcd_set_contrast()
{ {
lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast)); lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
} }
if (LCD_CLICKED) if (LCD_CLICKED) lcd_goto_menu(lcd_control_menu);
{
lcd_quick_feedback();
currentMenu = lcd_control_menu;
encoderPosition = 0;
}
} }
#endif #endif
@ -979,7 +860,8 @@ static void lcd_control_retract_menu()
MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999); MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
END_MENU(); END_MENU();
} }
#endif
#endif //FWRETRACT
#if SDCARDDETECT == -1 #if SDCARDDETECT == -1
static void lcd_sd_refresh() static void lcd_sd_refresh()
@ -1052,27 +934,12 @@ void lcd_sdcard_menu()
if (LCD_CLICKED) \ if (LCD_CLICKED) \
{ \ { \
*((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \ *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
lcd_quick_feedback(); \ lcd_goto_menu(prevMenu, prevEncoderPosition); \
currentMenu = prevMenu; \
encoderPosition = prevEncoderPosition; \
} \ } \
} \ } \
void menu_edit_callback_ ## _name () \ void menu_edit_callback_ ## _name () { \
{ \ menu_edit_ ## _name (); \
if ((int32_t)encoderPosition < 0) \ if (LCD_CLICKED) (*callbackFunc)(); \
encoderPosition = 0; \
if ((int32_t)encoderPosition > maxEditValue) \
encoderPosition = maxEditValue; \
if (lcdDrawUpdate) \
lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
if (LCD_CLICKED) \
{ \
*((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
lcd_quick_feedback(); \
currentMenu = prevMenu; \
encoderPosition = prevEncoderPosition; \
(*callbackFunc)();\
} \
} \ } \
static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \ static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
{ \ { \
@ -1157,24 +1024,10 @@ static void lcd_quick_feedback()
} }
/** Menu action functions **/ /** Menu action functions **/
static void menu_action_back(menuFunc_t data) static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
{ static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
currentMenu = data; static void menu_action_gcode(const char* pgcode) { enquecommand_P(pgcode); }
encoderPosition = 0; static void menu_action_function(menuFunc_t data) { (*data)(); }
}
static void menu_action_submenu(menuFunc_t data)
{
currentMenu = data;
encoderPosition = 0;
}
static void menu_action_gcode(const char* pgcode)
{
enquecommand_P(pgcode);
}
static void menu_action_function(menuFunc_t data)
{
(*data)();
}
static void menu_action_sdfile(const char* filename, char* longFilename) static void menu_action_sdfile(const char* filename, char* longFilename)
{ {
char cmd[30]; char cmd[30];
@ -1459,10 +1312,8 @@ void lcd_buttons_update()
//manage encoder rotation //manage encoder rotation
uint8_t enc=0; uint8_t enc=0;
if(buttons&EN_A) if (buttons & EN_A) enc |= B01;
enc|=(1<<0); if (buttons & EN_B) enc |= B10;
if(buttons&EN_B)
enc|=(1<<1);
if(enc != lastEncoderBits) if(enc != lastEncoderBits)
{ {
switch(enc) switch(enc)
@ -1611,6 +1462,7 @@ char *itostr31(const int &xx)
return conv; return conv;
} }
// Convert int to rj string with 123 or -12 format
char *itostr3(const int &x) char *itostr3(const int &x)
{ {
int xx = x; int xx = x;
@ -1653,46 +1505,24 @@ char *itostr3left(const int &xx)
return conv; return conv;
} }
char *itostr4(const int &xx) // Convert int to rj string with 1234 format
{ char *itostr4(const int &xx) {
if (xx >= 1000) conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
conv[0]=(xx/1000)%10+'0'; conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
else conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
conv[0]=' '; conv[3] = xx % 10 + '0';
if (xx >= 100)
conv[1]=(xx/100)%10+'0';
else
conv[1]=' ';
if (xx >= 10)
conv[2]=(xx/10)%10+'0';
else
conv[2]=' ';
conv[3]=(xx)%10+'0';
conv[4] = 0; conv[4] = 0;
return conv; return conv;
} }
// convert float to string with 12345 format // convert float to rj string with 12345 format
char *ftostr5(const float &x) char *ftostr5(const float &x) {
{
long xx = abs(x); long xx = abs(x);
if (xx >= 10000) conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
conv[0]=(xx/10000)%10+'0'; conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
else conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
conv[0]=' '; conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
if (xx >= 1000) conv[4] = xx % 10 + '0';
conv[1]=(xx/1000)%10+'0';
else
conv[1]=' ';
if (xx >= 100)
conv[2]=(xx/100)%10+'0';
else
conv[2]=' ';
if (xx >= 10)
conv[3]=(xx/10)%10+'0';
else
conv[3]=' ';
conv[4]=(xx)%10+'0';
conv[5] = 0; conv[5] = 0;
return conv; return conv;
} }