From 5ad21550c7ab39a898678d6fd28e03caa9c6bd55 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 11 May 2022 18:22:14 +0200 Subject: [PATCH 1/3] Jump to PLA temps in LCD settings when starting from zero Allow the LCD menu update function to preset an initial value during the first encoder increase from the minimal (usually zero) value. This is useful to jump to a more sensible initial value when turning on an heater which is currently disabled. The user is still allowed to decrease the value after the jump, so there's no functional restriction. --- Firmware/menu.cpp | 17 ++++++++++++++--- Firmware/menu.h | 7 ++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 67a9ee9dc4..bde3949320 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -467,6 +467,16 @@ static void _menu_edit_P(void) menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (lcd_draw_update) { + // handle initial value jumping + if (_md->minJumpValue && lcd_encoder) { + if (lcd_encoder > 0 && _md->currentValue == _md->minEditValue) { + _md->currentValue = _md->minJumpValue; + lcd_encoder = 0; + } + // disable after first use and/or if the initial value is not minEditValue + _md->minJumpValue = 0; + } + _md->currentValue += lcd_encoder; lcd_encoder = 0; // Consume knob rotation event @@ -483,7 +493,7 @@ static void _menu_edit_P(void) } template -void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val) +void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val, int16_t jmp_val) { menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (menu_item == menu_line) @@ -501,6 +511,7 @@ void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val) _md->currentValue = *pval; _md->minEditValue = min_val; _md->maxEditValue = max_val; + _md->minJumpValue = jmp_val; menu_item_ret(); return; } @@ -508,8 +519,8 @@ void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val) menu_item++; } -template void menu_item_edit_P(const char* str, int16_t *pval, int16_t min_val, int16_t max_val); -template void menu_item_edit_P(const char* str, uint8_t *pval, int16_t min_val, int16_t max_val); +template void menu_item_edit_P(const char* str, int16_t *pval, int16_t min_val, int16_t max_val, int16_t jmp_val); +template void menu_item_edit_P(const char* str, uint8_t *pval, int16_t min_val, int16_t max_val, int16_t jmp_val); static uint8_t progressbar_block_count = 0; static uint16_t progressbar_total = 0; diff --git a/Firmware/menu.h b/Firmware/menu.h index f3425b81fa..9f764fae44 100755 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -24,6 +24,7 @@ typedef struct int16_t currentValue; int16_t minEditValue; int16_t maxEditValue; + int16_t minJumpValue; } menu_data_edit_t; extern uint8_t menu_data[MENU_DATA_SIZE]; @@ -144,10 +145,10 @@ struct SheetFormatBuffer extern void menu_format_sheet_E(const Sheet &sheet_E, SheetFormatBuffer &buffer); -#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { menu_item_edit_P(str, pval, minval, maxval); } while (0) -//#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) MENU_ITEM_EDIT(int3, str, pval, minval, maxval) +#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { menu_item_edit_P(str, pval, minval, maxval, 0); } while (0) +#define MENU_ITEM_EDIT_int3_jmp_P(str, pval, minval, maxval, jmpval) do { menu_item_edit_P(str, pval, minval, maxval, jmpval); } while (0) template -extern void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val); +extern void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val, int16_t jmp_val); extern void menu_progressbar_init(uint16_t total, const char* title); extern void menu_progressbar_update(uint16_t newVal); From 92202249d91d717e70c1bac2f5059daa3cfd7907 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 20 Aug 2022 14:16:56 +0200 Subject: [PATCH 2/3] Make temperature jumping configurable in the variant file Use this new feature in the Settings -> Temperature menus. --- Firmware/ultralcd.cpp | 6 +++--- Firmware/variants/MK25-RAMBo10a.h | 4 ++++ Firmware/variants/MK25-RAMBo13a.h | 4 ++++ Firmware/variants/MK25S-RAMBo10a.h | 4 ++++ Firmware/variants/MK25S-RAMBo13a.h | 4 ++++ Firmware/variants/MK3-E3DREVO.h | 4 ++++ Firmware/variants/MK3-E3DREVO_HF_60W.h | 4 ++++ Firmware/variants/MK3.h | 4 ++++ Firmware/variants/MK3S-E3DREVO.h | 4 ++++ Firmware/variants/MK3S-E3DREVO_HF_60W.h | 4 ++++ Firmware/variants/MK3S.h | 4 ++++ 11 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index dbcd2edb90..43cecb6945 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4139,12 +4139,12 @@ static void SETTINGS_SILENT_MODE() static void menuitems_temperature_common() { #if TEMP_SENSOR_0 != 0 - MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10); + MENU_ITEM_EDIT_int3_jmp_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10, LCD_JUMP_HOTEND_TEMP); #endif #if TEMP_SENSOR_BED != 0 - MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 5); + MENU_ITEM_EDIT_int3_jmp_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 5, LCD_JUMP_BED_TEMP); #endif - MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255); + MENU_ITEM_EDIT_int3_jmp_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255, LCD_JUMP_FAN_SPEED); } void SETTINGS_FANS_CHECK() { diff --git a/Firmware/variants/MK25-RAMBo10a.h b/Firmware/variants/MK25-RAMBo10a.h index 86d541f89a..099ad329f1 100644 --- a/Firmware/variants/MK25-RAMBo10a.h +++ b/Firmware/variants/MK25-RAMBo10a.h @@ -381,6 +381,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK25-RAMBo13a.h b/Firmware/variants/MK25-RAMBo13a.h index b2410900ea..7cce101be3 100644 --- a/Firmware/variants/MK25-RAMBo13a.h +++ b/Firmware/variants/MK25-RAMBo13a.h @@ -382,6 +382,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK25S-RAMBo10a.h b/Firmware/variants/MK25S-RAMBo10a.h index d01c705a7e..254be0d09a 100644 --- a/Firmware/variants/MK25S-RAMBo10a.h +++ b/Firmware/variants/MK25S-RAMBo10a.h @@ -381,6 +381,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK25S-RAMBo13a.h b/Firmware/variants/MK25S-RAMBo13a.h index a4b77f12be..2c375f9200 100644 --- a/Firmware/variants/MK25S-RAMBo13a.h +++ b/Firmware/variants/MK25S-RAMBo13a.h @@ -382,6 +382,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK3-E3DREVO.h b/Firmware/variants/MK3-E3DREVO.h index 1deab81787..f9e55e4c50 100644 --- a/Firmware/variants/MK3-E3DREVO.h +++ b/Firmware/variants/MK3-E3DREVO.h @@ -527,6 +527,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK3-E3DREVO_HF_60W.h b/Firmware/variants/MK3-E3DREVO_HF_60W.h index 471e6c8b7a..e60d5b3f47 100644 --- a/Firmware/variants/MK3-E3DREVO_HF_60W.h +++ b/Firmware/variants/MK3-E3DREVO_HF_60W.h @@ -528,6 +528,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK3.h b/Firmware/variants/MK3.h index e6ce1915db..78ee31d00a 100644 --- a/Firmware/variants/MK3.h +++ b/Firmware/variants/MK3.h @@ -530,6 +530,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK3S-E3DREVO.h b/Firmware/variants/MK3S-E3DREVO.h index 2ae876f583..030ce2188b 100644 --- a/Firmware/variants/MK3S-E3DREVO.h +++ b/Firmware/variants/MK3S-E3DREVO.h @@ -531,6 +531,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK3S-E3DREVO_HF_60W.h b/Firmware/variants/MK3S-E3DREVO_HF_60W.h index bfaae1fc96..bc5445af1b 100644 --- a/Firmware/variants/MK3S-E3DREVO_HF_60W.h +++ b/Firmware/variants/MK3S-E3DREVO_HF_60W.h @@ -532,6 +532,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/MK3S.h b/Firmware/variants/MK3S.h index 8b9ee71e2c..111d151c33 100644 --- a/Firmware/variants/MK3S.h +++ b/Firmware/variants/MK3S.h @@ -534,6 +534,10 @@ #define FLEX_PREHEAT_HOTEND_TEMP 240 #define FLEX_PREHEAT_HPB_TEMP 50 +#define LCD_JUMP_HOTEND_TEMP 200 +#define LCD_JUMP_BED_TEMP 50 +#define LCD_JUMP_FAN_SPEED 127 + /*------------------------------------ THERMISTORS SETTINGS *------------------------------------*/ From 719db8f537209522243915bdfb34ac7438be5300 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 1 Aug 2023 12:20:27 +0200 Subject: [PATCH 3/3] Optimize menu editing by reducing template duplication Avoid instantiating multiple copies of menu_item_edit_P/_menu_edit_P: perform type switching at runtime. --- Firmware/menu.cpp | 25 +++++++++++++------------ Firmware/menu.h | 11 +++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index bde3949320..2ce6280427 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -461,8 +461,7 @@ void menu_draw_float13(const char* str, float val) lcd_printf_P(menu_fmt_float13, ' ', str, val); } -template -static void _menu_edit_P(void) +static void _menu_edit_P() { menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (lcd_draw_update) @@ -487,28 +486,33 @@ static void _menu_edit_P(void) } if (lcd_clicked()) { - *((T)(_md->editValue)) = _md->currentValue; + if (_md->editValueBits == 8) + *((uint8_t*)(_md->editValuePtr)) = _md->currentValue; + else + *((int16_t*)(_md->editValuePtr)) = _md->currentValue; menu_back_no_reset(); } } -template -void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val, int16_t jmp_val) +void menu_item_edit_P(const char* str, void* pval, uint8_t pbits, int16_t min_val, int16_t max_val, int16_t jmp_val) { menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (menu_item == menu_line) { + int16_t cur_val = (pbits == 8 ? *((uint8_t*)pval) : *((int16_t*)pval)); + if (lcd_draw_update) { lcd_set_cursor(0, menu_row); - menu_draw_P(menu_selection_mark(), str, *pval); + menu_draw_P(menu_selection_mark(), str, cur_val); } if (menu_clicked && (lcd_encoder == menu_item)) { - menu_submenu_no_reset(_menu_edit_P); + menu_submenu_no_reset(_menu_edit_P); _md->editLabel = str; - _md->editValue = pval; - _md->currentValue = *pval; + _md->editValuePtr = pval; + _md->editValueBits = pbits; + _md->currentValue = cur_val; _md->minEditValue = min_val; _md->maxEditValue = max_val; _md->minJumpValue = jmp_val; @@ -519,9 +523,6 @@ void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val, menu_item++; } -template void menu_item_edit_P(const char* str, int16_t *pval, int16_t min_val, int16_t max_val, int16_t jmp_val); -template void menu_item_edit_P(const char* str, uint8_t *pval, int16_t min_val, int16_t max_val, int16_t jmp_val); - static uint8_t progressbar_block_count = 0; static uint16_t progressbar_total = 0; void menu_progressbar_init(uint16_t total, const char* title) diff --git a/Firmware/menu.h b/Firmware/menu.h index 9f764fae44..4475186af0 100755 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -20,7 +20,8 @@ typedef struct { //Variables used when editing values. const char* editLabel; - void* editValue; + uint8_t editValueBits; // 8 or 16 + void* editValuePtr; int16_t currentValue; int16_t minEditValue; int16_t maxEditValue; @@ -144,11 +145,9 @@ struct SheetFormatBuffer extern void menu_format_sheet_E(const Sheet &sheet_E, SheetFormatBuffer &buffer); - -#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { menu_item_edit_P(str, pval, minval, maxval, 0); } while (0) -#define MENU_ITEM_EDIT_int3_jmp_P(str, pval, minval, maxval, jmpval) do { menu_item_edit_P(str, pval, minval, maxval, jmpval); } while (0) -template -extern void menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val, int16_t jmp_val); +#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { menu_item_edit_P(str, pval, sizeof(*pval)*8, minval, maxval, 0); } while (0) +#define MENU_ITEM_EDIT_int3_jmp_P(str, pval, minval, maxval, jmpval) do { menu_item_edit_P(str, pval, sizeof(*pval)*8, minval, maxval, jmpval); } while (0) +extern void menu_item_edit_P(const char* str, void* pval, uint8_t pbits, int16_t min_val, int16_t max_val, int16_t jmp_val); extern void menu_progressbar_init(uint16_t total, const char* title); extern void menu_progressbar_update(uint16_t newVal);