Browse Source

Drop the accessor form for LCD value editing

Scott Lahteine 7 years ago
parent
commit
ccda63c473
4 changed files with 25 additions and 67 deletions
  1. 4
    4
      Marlin/Marlin_main.cpp
  2. 15
    17
      Marlin/configuration_store.cpp
  3. 4
    9
      Marlin/planner.h
  4. 2
    37
      Marlin/ultralcd.cpp

+ 4
- 4
Marlin/Marlin_main.cpp View File

@@ -8858,7 +8858,7 @@ inline void gcode_M503() {
8858 8858
     stepper.synchronize();
8859 8859
 
8860 8860
     const float newK = code_seen('K') ? code_value_float() : -1;
8861
-    if (newK >= 0) planner.set_extruder_advance_k(newK);
8861
+    if (newK >= 0) planner.extruder_advance_k = newK;
8862 8862
 
8863 8863
     float newR = code_seen('R') ? code_value_float() : -1;
8864 8864
     if (newR < 0) {
@@ -8868,12 +8868,12 @@ inline void gcode_M503() {
8868 8868
       if (newD >= 0 && newW >= 0 && newH >= 0)
8869 8869
         newR = newD ? (newW * newH) / (sq(newD * 0.5) * M_PI) : 0;
8870 8870
     }
8871
-    if (newR >= 0) planner.set_advance_ed_ratio(newR);
8871
+    if (newR >= 0) planner.advance_ed_ratio = newR;
8872 8872
 
8873 8873
     SERIAL_ECHO_START;
8874
-    SERIAL_ECHOPAIR("Advance K=", planner.get_extruder_advance_k());
8874
+    SERIAL_ECHOPAIR("Advance K=", planner.extruder_advance_k);
8875 8875
     SERIAL_ECHOPGM(" E/D=");
8876
-    const float ratio = planner.get_advance_ed_ratio();
8876
+    const float ratio = planner.advance_ed_ratio;
8877 8877
     ratio ? SERIAL_ECHO(ratio) : SERIAL_ECHOPGM("Auto");
8878 8878
     SERIAL_EOL;
8879 8879
   }

+ 15
- 17
Marlin/configuration_store.cpp View File

@@ -578,16 +578,15 @@ void MarlinSettings::postprocess() {
578 578
     // Linear Advance
579 579
     //
580 580
 
581
-    float extruder_advance_k = 0.0f, advance_ed_ratio = 0.0f;
582
-
583 581
     #if ENABLED(LIN_ADVANCE)
584
-      extruder_advance_k = planner.get_extruder_advance_k();
585
-      advance_ed_ratio = planner.get_advance_ed_ratio();
582
+      EEPROM_WRITE(planner.extruder_advance_k);
583
+      EEPROM_WRITE(planner.advance_ed_ratio);
584
+    #else
585
+      dummy = 0.0f;
586
+      EEPROM_WRITE(dummy);
587
+      EEPROM_WRITE(dummy);
586 588
     #endif
587 589
 
588
-    EEPROM_WRITE(extruder_advance_k);
589
-    EEPROM_WRITE(advance_ed_ratio);
590
-
591 590
     if (!eeprom_write_error) {
592 591
 
593 592
       const uint16_t final_checksum = eeprom_checksum,
@@ -922,13 +921,12 @@ void MarlinSettings::postprocess() {
922 921
       // Linear Advance
923 922
       //
924 923
 
925
-      float extruder_advance_k, advance_ed_ratio;
926
-      EEPROM_READ(extruder_advance_k);
927
-      EEPROM_READ(advance_ed_ratio);
928
-
929 924
       #if ENABLED(LIN_ADVANCE)
930
-        planner.set_extruder_advance_k(extruder_advance_k);
931
-        planner.set_advance_ed_ratio(advance_ed_ratio);
925
+        EEPROM_READ(planner.extruder_advance_k);
926
+        EEPROM_READ(planner.advance_ed_ratio);
927
+      #else
928
+        EEPROM_READ(dummy);
929
+        EEPROM_READ(dummy);
932 930
       #endif
933 931
 
934 932
       if (eeprom_checksum == stored_checksum) {
@@ -1187,8 +1185,8 @@ void MarlinSettings::reset() {
1187 1185
   #endif
1188 1186
 
1189 1187
   #if ENABLED(LIN_ADVANCE)
1190
-    planner.set_extruder_advance_k(LIN_ADVANCE_K);
1191
-    planner.set_advance_ed_ratio(LIN_ADVANCE_E_D_RATIO);
1188
+    planner.extruder_advance_k = LIN_ADVANCE_K;
1189
+    planner.advance_ed_ratio = LIN_ADVANCE_E_D_RATIO;
1192 1190
   #endif
1193 1191
 
1194 1192
   postprocess();
@@ -1658,8 +1656,8 @@ void MarlinSettings::reset() {
1658 1656
         SERIAL_ECHOLNPGM("Linear Advance:");
1659 1657
       }
1660 1658
       CONFIG_ECHO_START;
1661
-      SERIAL_ECHOPAIR("  M900 K", planner.get_extruder_advance_k());
1662
-      SERIAL_ECHOLNPAIR(" R", planner.get_advance_ed_ratio());
1659
+      SERIAL_ECHOPAIR("  M900 K", planner.extruder_advance_k);
1660
+      SERIAL_ECHOLNPAIR(" R", planner.advance_ed_ratio);
1663 1661
     #endif
1664 1662
   }
1665 1663
 

+ 4
- 9
Marlin/planner.h View File

@@ -168,6 +168,10 @@ class Planner {
168 168
       static float z_fade_height, inverse_z_fade_height;
169 169
     #endif
170 170
 
171
+    #if ENABLED(LIN_ADVANCE)
172
+      static float extruder_advance_k, advance_ed_ratio;
173
+    #endif
174
+
171 175
   private:
172 176
 
173 177
     /**
@@ -209,8 +213,6 @@ class Planner {
209 213
 
210 214
     #if ENABLED(LIN_ADVANCE)
211 215
       static float position_float[NUM_AXIS];
212
-      static float extruder_advance_k;
213
-      static float advance_ed_ratio;
214 216
     #endif
215 217
 
216 218
     #if ENABLED(ULTRA_LCD)
@@ -266,13 +268,6 @@ class Planner {
266 268
 
267 269
     #endif
268 270
 
269
-    #if ENABLED(LIN_ADVANCE)
270
-      static void set_extruder_advance_k(float k) { extruder_advance_k = k; };
271
-      static float get_extruder_advance_k() { return extruder_advance_k; };
272
-      static void set_advance_ed_ratio(float ratio) { advance_ed_ratio = ratio; };
273
-      static float get_advance_ed_ratio() { return advance_ed_ratio; };
274
-    #endif
275
-
276 271
     /**
277 272
      * Planner::_buffer_line
278 273
      *

+ 2
- 37
Marlin/ultralcd.cpp View File

@@ -181,8 +181,6 @@ uint16_t max_display_update_time = 0;
181 181
     void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
182 182
     void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
183 183
     void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback); \
184
-    void _menu_action_setting_edit_accessor_ ## _name(const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue); \
185
-    void menu_action_setting_edit_accessor_ ## _name(const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue); \
186 184
     typedef void _name##_void
187 185
 
188 186
   DECLARE_MENU_EDIT_TYPE(int, int3);
@@ -197,7 +195,6 @@ uint16_t max_display_update_time = 0;
197 195
 
198 196
   void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
199 197
   void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
200
-  void menu_action_setting_edit_accessor_bool(const char* pstr, bool (*pget)(), void (*pset)(bool));
201 198
 
202 199
   #if ENABLED(SDSUPPORT)
203 200
     void lcd_sdcard_menu();
@@ -300,15 +297,12 @@ uint16_t max_display_update_time = 0;
300 297
   #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
301 298
   #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
302 299
   #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
303
-  #define MENU_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
304 300
   #if ENABLED(ENCODER_RATE_MULTIPLIER)
305 301
     #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
306 302
     #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
307
-    #define MENU_MULTIPLIER_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
308 303
   #else //!ENCODER_RATE_MULTIPLIER
309 304
     #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
310 305
     #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
311
-    #define MENU_MULTIPLIER_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
312 306
   #endif //!ENCODER_RATE_MULTIPLIER
313 307
 
314 308
   /**
@@ -421,7 +415,7 @@ uint16_t max_display_update_time = 0;
421 415
 
422 416
   // Value Editing
423 417
   const char *editLabel;
424
-  void *editValue, *editSetter;
418
+  void *editValue;
425 419
   int32_t minEditValue, maxEditValue;
426 420
   screenFunc_t callbackFunc;
427 421
 
@@ -2571,7 +2565,7 @@ void kill_screen(const char* lcd_msg) {
2571 2565
     MENU_BACK(MSG_CONTROL);
2572 2566
 
2573 2567
     #if ENABLED(LIN_ADVANCE)
2574
-      MENU_ITEM_EDIT_ACCESSOR(float3, MSG_ADVANCE_K, planner.get_extruder_advance_k, planner.set_extruder_advance_k, 0, 999);
2568
+      MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
2575 2569
     #endif
2576 2570
 
2577 2571
     MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
@@ -3128,8 +3122,6 @@ void kill_screen(const char* lcd_msg) {
3128 3122
    *   void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3129 3123
    *   void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3130 3124
    *   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
3131
-   *   void _menu_action_setting_edit_accessor_int3(const char * const pstr, int (*pget)(), void (*pset)(int), const int minValue, const int maxValue);
3132
-   *   void menu_action_setting_edit_accessor_int3(const char * const pstr, int (*pget)(), void (*pset)(int), const int minValue, const int maxValue); // edit int via pget and pset accessor functions
3133 3125
    *
3134 3126
    * You can then use one of the menu macros to present the edit interface:
3135 3127
    *   MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
@@ -3141,9 +3133,6 @@ void kill_screen(const char* lcd_msg) {
3141 3133
    * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
3142 3134
    *
3143 3135
    *       menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
3144
-   *
3145
-   * Values that are get/set via functions (As opposed to global variables) can use the accessor form:
3146
-   *   MENU_ITEM_EDIT_ACCESSOR(int3, MSG_SPEED, get_feedrate_percentage, set_feedrate_percentage, 10, 999)
3147 3136
    */
3148 3137
   #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
3149 3138
     bool _menu_edit_ ## _name () { \
@@ -3156,8 +3145,6 @@ void kill_screen(const char* lcd_msg) {
3156 3145
         _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
3157 3146
         if (editValue != NULL) \
3158 3147
           *((_type*)editValue) = value; \
3159
-        else if (editSetter != NULL) \
3160
-          ((void (*)(_type))editSetter)(value); \
3161 3148
         lcd_goto_previous_menu(); \
3162 3149
       } \
3163 3150
       return lcd_clicked; \
@@ -3171,7 +3158,6 @@ void kill_screen(const char* lcd_msg) {
3171 3158
       \
3172 3159
       editLabel = pstr; \
3173 3160
       editValue = ptr; \
3174
-      editSetter = NULL; \
3175 3161
       minEditValue = minValue * _scale; \
3176 3162
       maxEditValue = maxValue * _scale - minEditValue; \
3177 3163
       encoderPosition = (*ptr) * _scale - minEditValue; \
@@ -3185,22 +3171,6 @@ void kill_screen(const char* lcd_msg) {
3185 3171
       currentScreen = menu_edit_callback_ ## _name; \
3186 3172
       callbackFunc = callback; \
3187 3173
     } \
3188
-    void _menu_action_setting_edit_accessor_ ## _name (const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue) { \
3189
-      lcd_save_previous_screen(); \
3190
-      \
3191
-      lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
3192
-      \
3193
-      editLabel = pstr; \
3194
-      editValue = NULL; \
3195
-      editSetter = pset; \
3196
-      minEditValue = minValue * _scale; \
3197
-      maxEditValue = maxValue * _scale - minEditValue; \
3198
-      encoderPosition = pget() * _scale - minEditValue; \
3199
-    } \
3200
-    void menu_action_setting_edit_accessor_ ## _name (const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue) { \
3201
-      _menu_action_setting_edit_accessor_ ## _name(pstr, pget, pset, minValue, maxValue); \
3202
-      currentScreen = menu_edit_ ## _name; \
3203
-    } \
3204 3174
     typedef void _name
3205 3175
 
3206 3176
   DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
@@ -3305,11 +3275,6 @@ void kill_screen(const char* lcd_msg) {
3305 3275
     menu_action_setting_edit_bool(pstr, ptr);
3306 3276
     (*callback)();
3307 3277
   }
3308
-  void menu_action_setting_edit_accessor_bool(const char* pstr, bool (*pget)(), void (*pset)(bool)) {
3309
-    UNUSED(pstr);
3310
-    pset(!pget());
3311
-    lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
3312
-  }
3313 3278
 
3314 3279
 #endif // ULTIPANEL
3315 3280
 

Loading…
Cancel
Save