Add live editing option to LCD menu

This commit is contained in:
Scott Lahteine 2017-05-20 19:54:23 -05:00
parent 0e1f0efc4b
commit 11fc9564c9
4 changed files with 37 additions and 55 deletions

View File

@ -123,7 +123,7 @@
* 490 M304 PID thermalManager.bedKp, .bedKi, .bedKd (float x3) * 490 M304 PID thermalManager.bedKp, .bedKi, .bedKd (float x3)
* *
* DOGLCD: 2 bytes * DOGLCD: 2 bytes
* 502 M250 C lcd_contrast (int) * 502 M250 C lcd_contrast (uint16_t)
* *
* FWRETRACT: 29 bytes * FWRETRACT: 29 bytes
* 504 M209 S autoretract_enabled (bool) * 504 M209 S autoretract_enabled (bool)
@ -502,7 +502,7 @@ void MarlinSettings::postprocess() {
#endif #endif
#if !HAS_LCD_CONTRAST #if !HAS_LCD_CONTRAST
const int lcd_contrast = 32; const uint16_t lcd_contrast = 32;
#endif #endif
EEPROM_WRITE(lcd_contrast); EEPROM_WRITE(lcd_contrast);
@ -883,7 +883,7 @@ void MarlinSettings::postprocess() {
#endif #endif
#if !HAS_LCD_CONTRAST #if !HAS_LCD_CONTRAST
int lcd_contrast; uint16_t lcd_contrast;
#endif #endif
EEPROM_READ(lcd_contrast); EEPROM_READ(lcd_contrast);

View File

@ -148,10 +148,6 @@ uint16_t max_display_update_time = 0;
void lcd_dac_write_eeprom(); void lcd_dac_write_eeprom();
#endif #endif
#if HAS_LCD_CONTRAST
void lcd_set_contrast();
#endif
#if ENABLED(FWRETRACT) #if ENABLED(FWRETRACT)
void lcd_control_retract_menu(); void lcd_control_retract_menu();
#endif #endif
@ -181,7 +177,7 @@ uint16_t max_display_update_time = 0;
void menu_edit_callback_ ## _name(); \ 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_ ## _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 typedef void _name##_void
DECLARE_MENU_EDIT_TYPE(int, int3); DECLARE_MENU_EDIT_TYPE(int, int3);
@ -419,6 +415,7 @@ uint16_t max_display_update_time = 0;
void *editValue; void *editValue;
int32_t minEditValue, maxEditValue; int32_t minEditValue, maxEditValue;
screenFunc_t callbackFunc; screenFunc_t callbackFunc;
bool liveEdit;
// Manual Moves // Manual Moves
const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE; const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
@ -590,7 +587,7 @@ void lcd_status_screen() {
} }
#if ENABLED(ULTIPANEL_FEEDMULTIPLY) #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 // Dead zone at 100% feedrate
if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) { if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
feedrate_percentage = 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) #if ENABLED(EEPROM_SETTINGS)
static void lcd_store_settings() { lcd_completion_feedback(settings.save()); } static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
static void lcd_load_settings() { lcd_completion_feedback(settings.load()); } 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); MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
#if HAS_LCD_CONTRAST #if HAS_LCD_CONTRAST
//MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63); MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
#endif #endif
#if ENABLED(FWRETRACT) #if ENABLED(FWRETRACT)
MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu); MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
@ -2953,32 +2960,6 @@ void kill_screen(const char* lcd_msg) {
END_MENU(); 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 * "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_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_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: * You can then use one of the menu macros to present the edit interface:
* MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999) * 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: * This expands into a more primitive menu item:
* MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999) * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
* *
* * ...which calls:
* Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
*
* menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999) * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
*/ */
#define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \ #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
bool _menu_edit_ ## _name () { \ bool _menu_edit_ ## _name() { \
ENCODER_DIRECTION_NORMAL(); \ ENCODER_DIRECTION_NORMAL(); \
if ((int32_t)encoderPosition < 0) encoderPosition = 0; \ if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \ if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
if (lcdDrawUpdate) \ if (lcdDrawUpdate) \
lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \ 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); \ _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
if (editValue != NULL) \ if (editValue != NULL) *((_type*)editValue) = value; \
*((_type*)editValue) = value; \ if (liveEdit) (*callbackFunc)(); \
lcd_goto_previous_menu(); \ if (lcd_clicked) lcd_goto_previous_menu(); \
} \ } \
return lcd_clicked; \ return lcd_clicked; \
} \ } \
void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \ void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \ 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_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
lcd_save_previous_screen(); \ lcd_save_previous_screen(); \
\ \
lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \ lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
@ -3533,14 +3512,15 @@ void kill_screen(const char* lcd_msg) {
maxEditValue = maxValue * _scale - minEditValue; \ maxEditValue = maxValue * _scale - minEditValue; \
encoderPosition = (*ptr) * _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); \ _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
currentScreen = menu_edit_ ## _name; \ 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); \ _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
currentScreen = menu_edit_callback_ ## _name; \ currentScreen = menu_edit_callback_ ## _name; \
callbackFunc = callback; \ callbackFunc = callback; \
liveEdit = live; \
} \ } \
typedef void _name typedef void _name
@ -3641,7 +3621,7 @@ void kill_screen(const char* lcd_msg) {
#endif // SDSUPPORT #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) { void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
menu_action_setting_edit_bool(pstr, ptr); menu_action_setting_edit_bool(pstr, ptr);
(*callback)(); (*callback)();
@ -4071,10 +4051,12 @@ void lcd_setalertstatuspgm(const char * 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 #if HAS_LCD_CONTRAST
void set_lcd_contrast(const int value) { void set_lcd_contrast(const int value) {
lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
u8g.setContrast(lcd_contrast); u8g.setContrast(lcd_contrast);
} }
#endif #endif
#if ENABLED(ULTIPANEL) #if ENABLED(ULTIPANEL)

View File

@ -55,8 +55,8 @@
#endif #endif
#if ENABLED(DOGLCD) #if ENABLED(DOGLCD)
extern int lcd_contrast; extern uint16_t lcd_contrast;
void set_lcd_contrast(int value); void set_lcd_contrast(uint16_t value);
#elif ENABLED(SHOW_BOOTSCREEN) #elif ENABLED(SHOW_BOOTSCREEN)
void bootscreen(); void bootscreen();
#endif #endif

View File

@ -195,7 +195,7 @@
#include "utf_mapper.h" #include "utf_mapper.h"
int lcd_contrast; uint16_t lcd_contrast;
static char currentfont = 0; static char currentfont = 0;
// The current graphical page being rendered // The current graphical page being rendered