Quellcode durchsuchen

Prevent duplication of PSTRs to save memory (#15435)

Marcio Teixeira vor 4 Jahren
Ursprung
Commit
e3ff27c95a
3 geänderte Dateien mit 22 neuen und 21 gelöschten Zeilen
  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 Datei anzeigen

112
 /////////// Common Menu Actions ////////////
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
 /////////// Menu Editing Actions ///////////
118
 /////////// Menu Editing Actions ///////////

+ 18
- 17
Marlin/src/lcd/menu/menu.h Datei anzeigen

111
 ////////////////////////////////////////////
111
 ////////////////////////////////////////////
112
 
112
 
113
 #define _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(TYPE, NAME, STRFUNC) \
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
     DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(STRFUNC(*(data))); \
115
     DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(STRFUNC(*(data))); \
117
   } \
116
   } \
118
   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), ...) { \
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
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5);            // 12345      right-justified
140
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5);            // 12345      right-justified
142
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5_25);         // 12345      right-justified (25 increment)
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
 /////////////// Menu Actions ///////////////
147
 /////////////// Menu Actions ///////////////
150
 
149
 
151
 class MenuItem_back {
150
 class MenuItem_back {
152
   public:
151
   public:
153
-    static inline void action() {
152
+    static inline void action(PGM_P const dummy=nullptr) {
154
       ui.goto_previous_screen(
153
       ui.goto_previous_screen(
155
         #if ENABLED(TURBO_BACK_MENU_ITEM)
154
         #if ENABLED(TURBO_BACK_MENU_ITEM)
156
           true
155
           true
157
         #endif
156
         #endif
158
       );
157
       );
158
+      UNUSED(dummy);
159
     }
159
     }
160
 };
160
 };
161
 
161
 
162
 class MenuItem_submenu {
162
 class MenuItem_submenu {
163
   public:
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
 class MenuItem_gcode {
167
 class MenuItem_gcode {
168
   public:
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
 class MenuItem_function {
172
 class MenuItem_function {
173
   public:
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
  *     MenuItem_function::action(lcd_sdcard_pause)
306
  *     MenuItem_function::action(lcd_sdcard_pause)
307
  *
307
  *
308
  *   MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
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
  *     MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
310
  *     MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
311
  *
311
  *
312
  */
312
  */
313
 #define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, V...) do { \
313
 #define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, V...) do { \
314
     _skipStatic = false; \
314
     _skipStatic = false; \
315
     if (_menuLineNr == _thisItemNr) { \
315
     if (_menuLineNr == _thisItemNr) { \
316
+      PGM_P const plabel = PLABEL; \
316
       if (encoderLine == _thisItemNr && ui.use_click()) { \
317
       if (encoderLine == _thisItemNr && ui.use_click()) { \
317
         _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
318
         _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
318
-        MenuItem_##TYPE ::action ## VARIANT(V); \
319
+        MenuItem_##TYPE ::action ## VARIANT(plabel, ##V); \
319
         if (screen_changed) return; \
320
         if (screen_changed) return; \
320
       } \
321
       } \
321
       if (ui.should_draw()) \
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
   ++_thisItemNr; \
325
   ++_thisItemNr; \
325
 }while(0)
326
 }while(0)
348
 
349
 
349
 #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
350
 #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
350
 #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
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
 /////////////// Menu Screens ///////////////
360
 /////////////// Menu Screens ///////////////

+ 3
- 3
Marlin/src/lcd/menu/menu_media.cpp Datei anzeigen

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

Laden…
Abbrechen
Speichern