Add live editing option to LCD menu
This commit is contained in:
parent
0e1f0efc4b
commit
11fc9564c9
@ -123,7 +123,7 @@
|
||||
* 490 M304 PID thermalManager.bedKp, .bedKi, .bedKd (float x3)
|
||||
*
|
||||
* DOGLCD: 2 bytes
|
||||
* 502 M250 C lcd_contrast (int)
|
||||
* 502 M250 C lcd_contrast (uint16_t)
|
||||
*
|
||||
* FWRETRACT: 29 bytes
|
||||
* 504 M209 S autoretract_enabled (bool)
|
||||
@ -502,7 +502,7 @@ void MarlinSettings::postprocess() {
|
||||
#endif
|
||||
|
||||
#if !HAS_LCD_CONTRAST
|
||||
const int lcd_contrast = 32;
|
||||
const uint16_t lcd_contrast = 32;
|
||||
#endif
|
||||
EEPROM_WRITE(lcd_contrast);
|
||||
|
||||
@ -883,7 +883,7 @@ void MarlinSettings::postprocess() {
|
||||
#endif
|
||||
|
||||
#if !HAS_LCD_CONTRAST
|
||||
int lcd_contrast;
|
||||
uint16_t lcd_contrast;
|
||||
#endif
|
||||
EEPROM_READ(lcd_contrast);
|
||||
|
||||
|
@ -148,10 +148,6 @@ uint16_t max_display_update_time = 0;
|
||||
void lcd_dac_write_eeprom();
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_CONTRAST
|
||||
void lcd_set_contrast();
|
||||
#endif
|
||||
|
||||
#if ENABLED(FWRETRACT)
|
||||
void lcd_control_retract_menu();
|
||||
#endif
|
||||
@ -181,7 +177,7 @@ uint16_t max_display_update_time = 0;
|
||||
void menu_edit_callback_ ## _name(); \
|
||||
void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
|
||||
void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
|
||||
void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback); \
|
||||
void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
|
||||
typedef void _name##_void
|
||||
|
||||
DECLARE_MENU_EDIT_TYPE(int, int3);
|
||||
@ -419,6 +415,7 @@ uint16_t max_display_update_time = 0;
|
||||
void *editValue;
|
||||
int32_t minEditValue, maxEditValue;
|
||||
screenFunc_t callbackFunc;
|
||||
bool liveEdit;
|
||||
|
||||
// Manual Moves
|
||||
const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
|
||||
@ -590,7 +587,7 @@ void lcd_status_screen() {
|
||||
}
|
||||
|
||||
#if ENABLED(ULTIPANEL_FEEDMULTIPLY)
|
||||
int new_frm = feedrate_percentage + (int32_t)encoderPosition;
|
||||
const int new_frm = feedrate_percentage + (int32_t)encoderPosition;
|
||||
// Dead zone at 100% feedrate
|
||||
if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
|
||||
feedrate_percentage = 100;
|
||||
@ -2465,6 +2462,17 @@ void kill_screen(const char* lcd_msg) {
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Callback for LCD contrast
|
||||
*
|
||||
*/
|
||||
#if HAS_LCD_CONTRAST
|
||||
|
||||
void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
|
||||
|
||||
#endif // HAS_LCD_CONTRAST
|
||||
|
||||
#if ENABLED(EEPROM_SETTINGS)
|
||||
static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
|
||||
static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
|
||||
@ -2483,8 +2491,7 @@ void kill_screen(const char* lcd_msg) {
|
||||
MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
|
||||
|
||||
#if HAS_LCD_CONTRAST
|
||||
//MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
|
||||
MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
|
||||
MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
|
||||
#endif
|
||||
#if ENABLED(FWRETRACT)
|
||||
MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
|
||||
@ -2953,32 +2960,6 @@ void kill_screen(const char* lcd_msg) {
|
||||
END_MENU();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* "Control" > "Contrast" submenu
|
||||
*
|
||||
*/
|
||||
#if HAS_LCD_CONTRAST
|
||||
void lcd_set_contrast() {
|
||||
if (lcd_clicked) { return lcd_goto_previous_menu(); }
|
||||
ENCODER_DIRECTION_NORMAL();
|
||||
if (encoderPosition) {
|
||||
set_lcd_contrast(lcd_contrast + encoderPosition);
|
||||
encoderPosition = 0;
|
||||
lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
|
||||
}
|
||||
if (lcdDrawUpdate) {
|
||||
lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
|
||||
#if LCD_CONTRAST_MAX >= 100
|
||||
itostr3(lcd_contrast)
|
||||
#else
|
||||
itostr2(lcd_contrast)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif // HAS_LCD_CONTRAST
|
||||
|
||||
/**
|
||||
*
|
||||
* "Control" > "Retract" submenu
|
||||
@ -3492,7 +3473,7 @@ void kill_screen(const char* lcd_msg) {
|
||||
* void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
|
||||
* void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
|
||||
* void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
|
||||
* void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback); // edit int with callback
|
||||
* void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback, const bool live); // edit int with callback
|
||||
*
|
||||
* You can then use one of the menu macros to present the edit interface:
|
||||
* MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
|
||||
@ -3500,29 +3481,27 @@ void kill_screen(const char* lcd_msg) {
|
||||
* This expands into a more primitive menu item:
|
||||
* MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
|
||||
*
|
||||
*
|
||||
* Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
|
||||
*
|
||||
* ...which calls:
|
||||
* menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
|
||||
*/
|
||||
#define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
|
||||
bool _menu_edit_ ## _name () { \
|
||||
bool _menu_edit_ ## _name() { \
|
||||
ENCODER_DIRECTION_NORMAL(); \
|
||||
if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
|
||||
if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
|
||||
if (lcdDrawUpdate) \
|
||||
lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
|
||||
if (lcd_clicked) { \
|
||||
if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
|
||||
_type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
|
||||
if (editValue != NULL) \
|
||||
*((_type*)editValue) = value; \
|
||||
lcd_goto_previous_menu(); \
|
||||
if (editValue != NULL) *((_type*)editValue) = value; \
|
||||
if (liveEdit) (*callbackFunc)(); \
|
||||
if (lcd_clicked) lcd_goto_previous_menu(); \
|
||||
} \
|
||||
return lcd_clicked; \
|
||||
} \
|
||||
void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
|
||||
void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
|
||||
void _menu_action_setting_edit_ ## _name (const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
|
||||
void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
|
||||
void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
|
||||
void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
|
||||
lcd_save_previous_screen(); \
|
||||
\
|
||||
lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
|
||||
@ -3533,14 +3512,15 @@ void kill_screen(const char* lcd_msg) {
|
||||
maxEditValue = maxValue * _scale - minEditValue; \
|
||||
encoderPosition = (*ptr) * _scale - minEditValue; \
|
||||
} \
|
||||
void menu_action_setting_edit_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
|
||||
void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
|
||||
_menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
|
||||
currentScreen = menu_edit_ ## _name; \
|
||||
} \
|
||||
void menu_action_setting_edit_callback_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback) { \
|
||||
void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
|
||||
_menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
|
||||
currentScreen = menu_edit_callback_ ## _name; \
|
||||
callbackFunc = callback; \
|
||||
liveEdit = live; \
|
||||
} \
|
||||
typedef void _name
|
||||
|
||||
@ -3641,7 +3621,7 @@ void kill_screen(const char* lcd_msg) {
|
||||
|
||||
#endif // SDSUPPORT
|
||||
|
||||
void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
|
||||
void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
|
||||
void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
|
||||
menu_action_setting_edit_bool(pstr, ptr);
|
||||
(*callback)();
|
||||
@ -4071,10 +4051,12 @@ void lcd_setalertstatuspgm(const char * const message) {
|
||||
void lcd_reset_alert_level() { lcd_status_message_level = 0; }
|
||||
|
||||
#if HAS_LCD_CONTRAST
|
||||
|
||||
void set_lcd_contrast(const int value) {
|
||||
lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
|
||||
u8g.setContrast(lcd_contrast);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLED(ULTIPANEL)
|
||||
|
@ -55,8 +55,8 @@
|
||||
#endif
|
||||
|
||||
#if ENABLED(DOGLCD)
|
||||
extern int lcd_contrast;
|
||||
void set_lcd_contrast(int value);
|
||||
extern uint16_t lcd_contrast;
|
||||
void set_lcd_contrast(uint16_t value);
|
||||
#elif ENABLED(SHOW_BOOTSCREEN)
|
||||
void bootscreen();
|
||||
#endif
|
||||
|
@ -195,7 +195,7 @@
|
||||
|
||||
#include "utf_mapper.h"
|
||||
|
||||
int lcd_contrast;
|
||||
uint16_t lcd_contrast;
|
||||
static char currentfont = 0;
|
||||
|
||||
// The current graphical page being rendered
|
||||
|
Loading…
Reference in New Issue
Block a user