LCD menu optimalization - lcd_draw_edit removed

This commit is contained in:
Robert Pelnar 2018-07-19 16:57:31 +02:00
parent 3cb3ec9975
commit b46953c790
5 changed files with 172 additions and 183 deletions

View file

@ -844,44 +844,6 @@ void lcd_buttons_update(void)
}
void lcd_drawedit(const char* pstr, char* value)
{
lcd_set_cursor(1, 1);
lcd_puts_P(pstr);
lcd_print(':');
#if LCD_WIDTH < 20
lcd_set_cursor(LCD_WIDTH - strlen(value), 1);
#else
lcd_set_cursor(LCD_WIDTH -1 - strlen(value), 1);
#endif
lcd_print(value);
}
void lcd_drawedit_2(const char* pstr, char* value)
{
lcd_set_cursor(0, 1);
lcd_puts_P(pstr);
lcd_print(':');
lcd_set_cursor((LCD_WIDTH - strlen(value))/2, 3);
lcd_print(value);
lcd_print(" mm");
}
////////////////////////////////////////////////////////////////////////////////
// Custom character data

View file

@ -217,8 +217,6 @@ extern void lcd_set_custom_characters_progress(void);
extern void lcd_set_custom_characters_nextpage(void);
extern void lcd_set_custom_characters_degree(void);
extern void lcd_drawedit(const char* pstr, char* value);
extern void lcd_drawedit_2(const char* pstr, char* value);
#endif //_LCD_H

View file

@ -225,7 +225,11 @@ uint8_t menu_item_gcode_P(const char* str, const char* str_gcode)
}
const char menu_20x_space[] PROGMEM = " ";
const char menu_fmt_int3[] PROGMEM = "%c%.15S:%s%3d";
const char menu_fmt_float31[] PROGMEM = "%c%.12S:%s%+06.3f";
void menu_draw_int3(char chr, const char* str, int16_t val)
{
int text_len = strlen_P(str);
@ -236,6 +240,15 @@ void menu_draw_int3(char chr, const char* str, int16_t val)
lcd_printf_P(menu_fmt_int3, chr, str, spaces, val);
}
void menu_draw_float31(char chr, const char* str, float val)
{
int text_len = strlen_P(str);
if (text_len > 12) text_len = 12;
char spaces[21];
strcpy_P(spaces, menu_20x_space);
spaces[12 - text_len] = 0;
lcd_printf_P(menu_draw_float31, chr, str, spaces, val);
}
#define _menu_data (*((menu_data_edit_t*)menu_data))
void _menu_edit_int3(void)
@ -277,6 +290,7 @@ uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int
menu_item++;
return 0;
}
#undef _menu_data

View file

@ -89,7 +89,15 @@ extern uint8_t menu_item_gcode_P(const char* str, const char* str_gcode);
extern const char menu_fmt_int3[];
extern const char menu_fmt_float31[];
extern void menu_draw_int3(char chr, const char* str, int16_t val);
extern void menu_draw_float31(char chr, const char* str, float val);
extern void _menu_edit_int3(void);
#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { if (menu_item_edit_int3(str, pval, minval, maxval)) return; } while (0)
//#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) MENU_ITEM_EDIT(int3, str, pval, minval, maxval)
extern uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int16_t max_val);

View file

@ -2616,16 +2616,18 @@ void lcd_menu_statistics()
}
static void _lcd_move(const char *name, int axis, int min, int max) {
static void _lcd_move(const char *name, int axis, int min, int max)
{
if (!menuData._lcd_moveMenu.initialized)
{
menuData._lcd_moveMenu.endstopsEnabledPrevious = enable_endstops(false);
menuData._lcd_moveMenu.initialized = true;
}
if (lcd_encoder != 0) {
if (lcd_encoder != 0)
{
refresh_cmd_timeout();
if (! planner_queue_full()) {
if (! planner_queue_full())
{
current_position[axis] += float((int)lcd_encoder) * move_menu_scale;
if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
@ -2635,7 +2637,11 @@ static void _lcd_move(const char *name, int axis, int min, int max) {
lcd_draw_update = 1;
}
}
if (lcd_draw_update) lcd_drawedit(name, ftostr31(current_position[axis]));
if (lcd_draw_update)
{
lcd_set_cursor(0, 1);
menu_draw_float31(' ', name, current_position[axis]);
}
if (menuExiting || LCD_CLICKED) (void)enable_endstops(menuData._lcd_moveMenu.endstopsEnabledPrevious);
if (LCD_CLICKED) menu_back();
}
@ -2643,11 +2649,13 @@ static void _lcd_move(const char *name, int axis, int min, int max) {
static void lcd_move_e()
{
if (degHotend0() > EXTRUDE_MINTEMP) {
if (degHotend0() > EXTRUDE_MINTEMP)
{
if (lcd_encoder != 0)
{
refresh_cmd_timeout();
if (! planner_queue_full()) {
if (! planner_queue_full())
{
current_position[E_AXIS] += float((int)lcd_encoder) * move_menu_scale;
lcd_encoder = 0;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS] / 60, active_extruder);
@ -2656,27 +2664,27 @@ static void lcd_move_e()
}
if (lcd_draw_update)
{
lcd_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
lcd_set_cursor(0, 1);
menu_draw_float31(' ', name, current_position[E_AXIS]);
}
if (LCD_CLICKED) menu_back();
}
else {
}
else
{
lcd_clear();
lcd_set_cursor(0, 0);
lcd_puts_P(_T(MSG_ERROR));
lcd_set_cursor(0, 2);
lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
delay(2000);
lcd_return_to_status();
}
}
/**
* @brief Show measured Y distance of front calibration points from Y_MIN_POS
*
* If those points are detected too close to edge of reachable area, their confidence is lowered.
* This functionality is applied more often for MK2 printers.
*/
//@brief Show measured Y distance of front calibration points from Y_MIN_POS
//If those points are detected too close to edge of reachable area, their confidence is lowered.
//This functionality is applied more often for MK2 printers.
static void lcd_menu_xyz_y_min()
{
//|01234567890123456789|
@ -2708,9 +2716,8 @@ static void lcd_menu_xyz_y_min()
if (lcd_clicked())
menu_goto(lcd_menu_xyz_skew, 0, true, true);
}
/**
* @brief Show measured axis skewness
*/
//@brief Show measured axis skewness
float _deg(float rad)
{
return rad * 180 / M_PI;
@ -2807,7 +2814,8 @@ static void lcd_move_z() {
*/
static void _lcd_babystep(int axis, const char *msg)
{
if (menuData.babyStep.status == 0) {
if (menuData.babyStep.status == 0)
{
// Menu was entered.
// Initialize its status.
menuData.babyStep.status = 1;
@ -2830,12 +2838,13 @@ static void _lcd_babystep(int axis, const char *msg)
if (lcd_encoder != 0)
{
if (homing_flag) lcd_encoder = 0;
menuData.babyStep.babystepMem[axis] += (int)lcd_encoder;
if (axis == 2) {
if (axis == 2)
{
if (menuData.babyStep.babystepMem[axis] < Z_BABYSTEP_MIN) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
else if (menuData.babyStep.babystepMem[axis] > Z_BABYSTEP_MAX) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MAX; //0
else {
else
{
CRITICAL_SECTION_START
babystepsTodo[axis] += (int)lcd_encoder;
CRITICAL_SECTION_END
@ -2848,12 +2857,12 @@ static void _lcd_babystep(int axis, const char *msg)
}
if (lcd_draw_update)
lcd_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
if (LCD_CLICKED || menuExiting) {
if (LCD_CLICKED || menuExiting)
{
// Only update the EEPROM when leaving the menu.
EEPROM_save_B(
(axis == X_AXIS) ? EEPROM_BABYSTEP_X : ((axis == Y_AXIS) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
&menuData.babyStep.babystepMem[axis]);
if(Z_AXIS == axis) calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
}
if (LCD_CLICKED) menu_back();
@ -7520,7 +7529,6 @@ void menu_lcd_lcdupdate_func(void)
lcd_draw_update = 2;
lcd_oldcardstatus = IS_SD_INSERTED;
lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
if (lcd_oldcardstatus)
{
card.initsd();
@ -7534,10 +7542,8 @@ void menu_lcd_lcdupdate_func(void)
}
}
#endif//CARDINSERTED
if (lcd_next_update_millis < millis())
{
if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
{
if (lcd_draw_update == 0)
@ -7556,7 +7562,8 @@ void menu_lcd_lcdupdate_func(void)
// Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
// to give it a chance to save its state.
// This is useful for example, when the babystep value has to be written into EEPROM.
if (menu_menu != NULL) {
if (menu_menu != NULL)
{
menuExiting = true;
(*menu_menu)();
menuExiting = false;