Add helpers for custom text in menu items (#12214)

For some features it can be useful to write custom text in a menu item. This commit provides helpers to make this easier.
This commit is contained in:
Scott Lahteine 2018-10-25 15:17:53 -05:00 committed by GitHub
parent e8031b1152
commit bf9dd4f4cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 22 deletions

View File

@ -121,6 +121,13 @@ LCDViewAction lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
uint16_t max_display_update_time = 0; uint16_t max_display_update_time = 0;
millis_t next_lcd_update_ms; millis_t next_lcd_update_ms;
#if HAS_LCD_CONTRAST
void set_lcd_contrast(const int16_t value) {
lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
u8g.setContrast(lcd_contrast);
}
#endif
#if ENABLED(ULTIPANEL) #if ENABLED(ULTIPANEL)
#define DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(_type, _name, _strFunc) \ #define DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(_type, _name, _strFunc) \
@ -339,6 +346,12 @@ millis_t next_lcd_update_ms;
#define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0) #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
#define MENU_ITEM_ADDON_START(X) \
if (lcdDrawUpdate && _menuLineNr == _thisItemNr - 1) { \
SETCURSOR(X, _lcdLineNr)
#define MENU_ITEM_ADDON_END() } (0)
// Used to print static text with no visible cursor. // Used to print static text with no visible cursor.
// Parameters: label [, bool center [, bool invert [, char *value] ] ] // Parameters: label [, bool center [, bool invert [, char *value] ] ]
#define STATIC_ITEM_P(LABEL, ...) do{ \ #define STATIC_ITEM_P(LABEL, ...) do{ \
@ -3264,21 +3277,11 @@ void lcd_quick_feedback(const bool clear_buttons) {
* "Motion" > "Move Axis" submenu * "Motion" > "Move Axis" submenu
* *
*/ */
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
#define _MOVE_XYZ_ALLOWED (all_axes_homed())
#else
#define _MOVE_XYZ_ALLOWED true
#endif
#if ENABLED(DELTA) #if ENABLED(DELTA)
#define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
void lcd_lower_z_to_clip_height() { void lcd_lower_z_to_clip_height() {
line_to_z(delta_clip_start_height); line_to_z(delta_clip_start_height);
lcd_synchronize(); lcd_synchronize();
} }
#else
#define _MOVE_XY_ALLOWED true
#endif #endif
void lcd_move_menu() { void lcd_move_menu() {
@ -3289,8 +3292,18 @@ void lcd_quick_feedback(const bool clear_buttons) {
MENU_ITEM_EDIT(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled); MENU_ITEM_EDIT(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled);
#endif #endif
if (_MOVE_XYZ_ALLOWED) { #if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
if (_MOVE_XY_ALLOWED) { const bool do_move_xyz = all_axes_homed();
#else
constexpr bool do_move_xyz = true;
#endif
if (do_move_xyz) {
#if ENABLED(DELTA)
const bool do_move_xy = current_position[Z_AXIS] <= delta_clip_start_height;
#else
constexpr bool do_move_xy = true;
#endif
if (do_move_xy) {
MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount); MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount); MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
} }
@ -5804,15 +5817,6 @@ void lcd_setalertstatusPGM(PGM_P const message) {
void lcd_reset_alert_level() { lcd_status_message_level = 0; } void lcd_reset_alert_level() { lcd_status_message_level = 0; }
#if HAS_LCD_CONTRAST
void set_lcd_contrast(const int16_t value) {
lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
u8g.setContrast(lcd_contrast);
}
#endif
#if ENABLED(ULTIPANEL) #if ENABLED(ULTIPANEL)
/** /**

View File

@ -87,11 +87,19 @@
uint8_t get_ADC_keyValue(); uint8_t get_ADC_keyValue();
#endif #endif
#if ENABLED(DOGLCD) #if HAS_LCD_CONTRAST
extern int16_t lcd_contrast; extern int16_t lcd_contrast;
void set_lcd_contrast(const int16_t value); void set_lcd_contrast(const int16_t value);
#endif #endif
#if ENABLED(DOGLCD)
#define SETCURSOR(col, row) lcd_moveto(col * (DOG_CHAR_WIDTH), (row + 1) * row_height)
#define SETCURSOR_RJ(len, row) lcd_moveto(LCD_PIXEL_WIDTH - len * (DOG_CHAR_WIDTH), (row + 1) * row_height)
#else
#define SETCURSOR(col, row) lcd_moveto(col, row)
#define SETCURSOR_RJ(len, row) lcd_moveto(LCD_WIDTH - len, row)
#endif
#if ENABLED(SHOW_BOOTSCREEN) #if ENABLED(SHOW_BOOTSCREEN)
void lcd_bootscreen(); void lcd_bootscreen();
#endif #endif