瀏覽代碼

Prevent duplication of PSTRs to save memory (#15435)

Marcio Teixeira 4 年之前
父節點
當前提交
e3ff27c95a
共有 3 個檔案被更改,包括 22 行新增21 行删除
  1. 1
    1
      Marlin/src/lcd/menu/menu.cpp
  2. 18
    17
      Marlin/src/lcd/menu/menu.h
  3. 3
    3
      Marlin/src/lcd/menu/menu_media.cpp

+ 1
- 1
Marlin/src/lcd/menu/menu.cpp 查看文件

@@ -112,7 +112,7 @@ void MarlinUI::goto_previous_screen(
112 112
 /////////// Common Menu Actions ////////////
113 113
 ////////////////////////////////////////////
114 114
 
115
-void MenuItem_gcode::action(PGM_P const pgcode) { queue.inject_P(pgcode); }
115
+void MenuItem_gcode::action(PGM_P const, PGM_P const pgcode) { queue.inject_P(pgcode); }
116 116
 
117 117
 ////////////////////////////////////////////
118 118
 /////////// Menu Editing Actions ///////////

+ 18
- 17
Marlin/src/lcd/menu/menu.h 查看文件

@@ -111,8 +111,7 @@ FORCE_INLINE void draw_menu_item_edit_P(const bool sel, const uint8_t row, PGM_P
111 111
 ////////////////////////////////////////////
112 112
 
113 113
 #define _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(TYPE, NAME, STRFUNC) \
114
-  FORCE_INLINE void draw_menu_item_edit_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const pstr2, TYPE * const data, ...) { \
115
-    UNUSED(pstr2); \
114
+  FORCE_INLINE void draw_menu_item_edit_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, TYPE * const data, ...) { \
116 115
     DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(STRFUNC(*(data))); \
117 116
   } \
118 117
   FORCE_INLINE void draw_menu_item_edit_accessor_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const pstr2, TYPE (*pget)(), void (*pset)(TYPE), ...) { \
@@ -141,8 +140,8 @@ DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52sign);      // +123.45
141 140
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5);            // 12345      right-justified
142 141
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5_25);         // 12345      right-justified (25 increment)
143 142
 
144
-#define draw_menu_item_edit_bool(sel, row, pstr, pstr2, data, ...)           DRAW_BOOL_SETTING(sel, row, pstr, data)
145
-#define draw_menu_item_edit_accessor_bool(sel, row, pstr, pstr2, pget, pset) DRAW_BOOL_SETTING(sel, row, pstr, data)
143
+#define draw_menu_item_edit_bool(sel, row, pstr, data, ...)           DRAW_BOOL_SETTING(sel, row, pstr, data)
144
+#define draw_menu_item_edit_accessor_bool(sel, row, pstr, pget, pset) DRAW_BOOL_SETTING(sel, row, pstr, data)
146 145
 
147 146
 ////////////////////////////////////////////
148 147
 /////////////// Menu Actions ///////////////
@@ -150,28 +149,29 @@ DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5_25);         // 12345      right-justif
150 149
 
151 150
 class MenuItem_back {
152 151
   public:
153
-    static inline void action() {
152
+    static inline void action(PGM_P const dummy=nullptr) {
154 153
       ui.goto_previous_screen(
155 154
         #if ENABLED(TURBO_BACK_MENU_ITEM)
156 155
           true
157 156
         #endif
158 157
       );
158
+      UNUSED(dummy);
159 159
     }
160 160
 };
161 161
 
162 162
 class MenuItem_submenu {
163 163
   public:
164
-    static inline void action(const screenFunc_t func) { ui.save_previous_screen(); ui.goto_screen(func); }
164
+    static inline void action(PGM_P const, const screenFunc_t func) { ui.save_previous_screen(); ui.goto_screen(func); }
165 165
 };
166 166
 
167 167
 class MenuItem_gcode {
168 168
   public:
169
-    static void action(const char * const pgcode);
169
+    static void action(PGM_P const, const char * const pgcode);
170 170
 };
171 171
 
172 172
 class MenuItem_function {
173 173
   public:
174
-    static inline void action(const menuAction_t func) { (*func)(); };
174
+    static inline void action(PGM_P const, const menuAction_t func) { (*func)(); };
175 175
 };
176 176
 
177 177
 ////////////////////////////////////////////
@@ -306,20 +306,21 @@ class MenuItem_bool {
306 306
  *     MenuItem_function::action(lcd_sdcard_pause)
307 307
  *
308 308
  *   MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
309
- *     draw_menu_item_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
309
+ *     draw_menu_item_edit_int3(sel, row, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
310 310
  *     MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
311 311
  *
312 312
  */
313 313
 #define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, V...) do { \
314 314
     _skipStatic = false; \
315 315
     if (_menuLineNr == _thisItemNr) { \
316
+      PGM_P const plabel = PLABEL; \
316 317
       if (encoderLine == _thisItemNr && ui.use_click()) { \
317 318
         _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
318
-        MenuItem_##TYPE ::action ## VARIANT(V); \
319
+        MenuItem_##TYPE ::action ## VARIANT(plabel, ##V); \
319 320
         if (screen_changed) return; \
320 321
       } \
321 322
       if (ui.should_draw()) \
322
-        draw_menu_item ## VARIANT ## _ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ##V); \
323
+        draw_menu_item ## VARIANT ## _ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, plabel, ##V); \
323 324
     } \
324 325
   ++_thisItemNr; \
325 326
 }while(0)
@@ -348,12 +349,12 @@ class MenuItem_bool {
348 349
 
349 350
 #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
350 351
 #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
351
-#define MENU_ITEM_P(TYPE, PLABEL, V...)                       _MENU_ITEM_VARIANT_P(TYPE,      , false, PLABEL,                   ##V)
352
-#define MENU_ITEM(TYPE, LABEL, V...)                          _MENU_ITEM_VARIANT_P(TYPE,      , false, PSTR(LABEL),              ##V)
353
-#define MENU_ITEM_EDIT(TYPE, LABEL, V...)                     _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ##V)
354
-#define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...)            _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ##V)
355
-#define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, V...)          _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), PSTR(LABEL), ##V)
356
-#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), PSTR(LABEL), ##V)
352
+#define MENU_ITEM_P(TYPE, PLABEL, V...)                       _MENU_ITEM_VARIANT_P(TYPE,      , false, PLABEL,      ##V)
353
+#define MENU_ITEM(TYPE, LABEL, V...)                          _MENU_ITEM_VARIANT_P(TYPE,      , false, PSTR(LABEL), ##V)
354
+#define MENU_ITEM_EDIT(TYPE, LABEL, V...)                     _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), ##V)
355
+#define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...)            _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), ##V)
356
+#define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, V...)          _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), ##V)
357
+#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), ##V)
357 358
 
358 359
 ////////////////////////////////////////////
359 360
 /////////////// Menu Screens ///////////////

+ 3
- 3
Marlin/src/lcd/menu/menu_media.cpp 查看文件

@@ -97,7 +97,7 @@ inline void sdcard_start_selected_file() {
97 97
 
98 98
 class MenuItem_sdfile {
99 99
   public:
100
-    static void action(CardReader &) {
100
+    static void action(PGM_P const pstr, CardReader &) {
101 101
       #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
102 102
         // Save menu state for the selected file
103 103
         sd_encoder_position = ui.encoderPosition;
@@ -105,7 +105,7 @@ class MenuItem_sdfile {
105 105
         sd_items = screen_items;
106 106
       #endif
107 107
       #if ENABLED(SD_MENU_CONFIRM_START)
108
-        MenuItem_submenu::action(menu_sd_confirm);
108
+        MenuItem_submenu::action(pstr, menu_sd_confirm);
109 109
       #else
110 110
         sdcard_start_selected_file();
111 111
       #endif
@@ -114,7 +114,7 @@ class MenuItem_sdfile {
114 114
 
115 115
 class MenuItem_sdfolder {
116 116
   public:
117
-    static void action(CardReader &theCard) {
117
+    static void action(PGM_P const, CardReader &theCard) {
118 118
       card.cd(theCard.filename);
119 119
       encoderTopLine = 0;
120 120
       ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);

Loading…
取消
儲存