From 5daae818e1ceab4ddeb4486619f77c569a95522e Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 24 Aug 2018 17:33:43 +0200 Subject: [PATCH] Convert menu_item_edit to template function. --- Firmware/menu.cpp | 19 +++++++++++++------ Firmware/menu.h | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 7fa17746..b588e718 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -269,8 +269,11 @@ const char menu_fmt_float31[] PROGMEM = "%c%.12S:%s%+06.1f"; const char menu_fmt_float13[] PROGMEM = "%c%.12S:%s%+06.3f"; +template +void menu_draw_P(char chr, const char* str, int16_t val); -void menu_draw_int3(char chr, const char* str, int16_t val) +template<> +void menu_draw_P(char chr, const char* str, int16_t val) { int text_len = strlen_P(str); if (text_len > 15) text_len = 15; @@ -302,7 +305,8 @@ void menu_draw_float13(char chr, const char* str, float val) lcd_printf_P(menu_fmt_float13, chr, str, spaces, val); } -void _menu_edit_int3(void) +template +void _menu_edit_P(void) { menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (lcd_draw_update) @@ -310,7 +314,7 @@ void _menu_edit_int3(void) if (lcd_encoder < _md->minEditValue) lcd_encoder = _md->minEditValue; if (lcd_encoder > _md->maxEditValue) lcd_encoder = _md->maxEditValue; lcd_set_cursor(0, 1); - menu_draw_int3(' ', _md->editLabel, (int)lcd_encoder); + menu_draw_P(' ', _md->editLabel, (int)lcd_encoder); } if (LCD_CLICKED) { @@ -319,7 +323,8 @@ void _menu_edit_int3(void) } } -uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int16_t max_val) +template +uint8_t menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val) { menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (menu_item == menu_line) @@ -327,11 +332,11 @@ uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int if (lcd_draw_update) { lcd_set_cursor(0, menu_row); - menu_draw_int3((lcd_encoder == menu_item)?'>':' ', str, *pval); + menu_draw_P((lcd_encoder == menu_item)?'>':' ', str, *pval); } if (menu_clicked && (lcd_encoder == menu_item)) { - menu_submenu_no_reset(_menu_edit_int3); + menu_submenu_no_reset(_menu_edit_P); _md->editLabel = str; _md->editValue = pval; _md->minEditValue = min_val; @@ -344,6 +349,8 @@ uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int return 0; } +template uint8_t menu_item_edit_P(const char* str, int16_t *pval, int16_t min_val, int16_t max_val); + #undef _menu_data diff --git a/Firmware/menu.h b/Firmware/menu.h index af6f3896..59167246 100644 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -104,9 +104,10 @@ extern void menu_draw_float13(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) do { if (menu_item_edit_P(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); +template +extern uint8_t menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val); #endif //_MENU_H