瀏覽代碼

Drop the accessor form for LCD value editing

Scott Lahteine 8 年之前
父節點
當前提交
ccda63c473
共有 4 個檔案被更改,包括 25 行新增67 行删除
  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 查看文件

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

+ 15
- 17
Marlin/configuration_store.cpp 查看文件

578
     // Linear Advance
578
     // Linear Advance
579
     //
579
     //
580
 
580
 
581
-    float extruder_advance_k = 0.0f, advance_ed_ratio = 0.0f;
582
-
583
     #if ENABLED(LIN_ADVANCE)
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
     #endif
588
     #endif
587
 
589
 
588
-    EEPROM_WRITE(extruder_advance_k);
589
-    EEPROM_WRITE(advance_ed_ratio);
590
-
591
     if (!eeprom_write_error) {
590
     if (!eeprom_write_error) {
592
 
591
 
593
       const uint16_t final_checksum = eeprom_checksum,
592
       const uint16_t final_checksum = eeprom_checksum,
922
       // Linear Advance
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
       #if ENABLED(LIN_ADVANCE)
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
       #endif
930
       #endif
933
 
931
 
934
       if (eeprom_checksum == stored_checksum) {
932
       if (eeprom_checksum == stored_checksum) {
1187
   #endif
1185
   #endif
1188
 
1186
 
1189
   #if ENABLED(LIN_ADVANCE)
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
   #endif
1190
   #endif
1193
 
1191
 
1194
   postprocess();
1192
   postprocess();
1658
         SERIAL_ECHOLNPGM("Linear Advance:");
1656
         SERIAL_ECHOLNPGM("Linear Advance:");
1659
       }
1657
       }
1660
       CONFIG_ECHO_START;
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
     #endif
1661
     #endif
1664
   }
1662
   }
1665
 
1663
 

+ 4
- 9
Marlin/planner.h 查看文件

168
       static float z_fade_height, inverse_z_fade_height;
168
       static float z_fade_height, inverse_z_fade_height;
169
     #endif
169
     #endif
170
 
170
 
171
+    #if ENABLED(LIN_ADVANCE)
172
+      static float extruder_advance_k, advance_ed_ratio;
173
+    #endif
174
+
171
   private:
175
   private:
172
 
176
 
173
     /**
177
     /**
209
 
213
 
210
     #if ENABLED(LIN_ADVANCE)
214
     #if ENABLED(LIN_ADVANCE)
211
       static float position_float[NUM_AXIS];
215
       static float position_float[NUM_AXIS];
212
-      static float extruder_advance_k;
213
-      static float advance_ed_ratio;
214
     #endif
216
     #endif
215
 
217
 
216
     #if ENABLED(ULTRA_LCD)
218
     #if ENABLED(ULTRA_LCD)
266
 
268
 
267
     #endif
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
      * Planner::_buffer_line
272
      * Planner::_buffer_line
278
      *
273
      *

+ 2
- 37
Marlin/ultralcd.cpp 查看文件

181
     void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
181
     void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
182
     void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
182
     void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
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); \
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
     typedef void _name##_void
184
     typedef void _name##_void
187
 
185
 
188
   DECLARE_MENU_EDIT_TYPE(int, int3);
186
   DECLARE_MENU_EDIT_TYPE(int, int3);
197
 
195
 
198
   void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
196
   void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
199
   void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
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
   #if ENABLED(SDSUPPORT)
199
   #if ENABLED(SDSUPPORT)
203
     void lcd_sdcard_menu();
200
     void lcd_sdcard_menu();
300
   #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
297
   #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
301
   #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
298
   #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
302
   #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
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
   #if ENABLED(ENCODER_RATE_MULTIPLIER)
300
   #if ENABLED(ENCODER_RATE_MULTIPLIER)
305
     #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
301
     #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
306
     #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
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
   #else //!ENCODER_RATE_MULTIPLIER
303
   #else //!ENCODER_RATE_MULTIPLIER
309
     #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
304
     #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
310
     #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
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
   #endif //!ENCODER_RATE_MULTIPLIER
306
   #endif //!ENCODER_RATE_MULTIPLIER
313
 
307
 
314
   /**
308
   /**
421
 
415
 
422
   // Value Editing
416
   // Value Editing
423
   const char *editLabel;
417
   const char *editLabel;
424
-  void *editValue, *editSetter;
418
+  void *editValue;
425
   int32_t minEditValue, maxEditValue;
419
   int32_t minEditValue, maxEditValue;
426
   screenFunc_t callbackFunc;
420
   screenFunc_t callbackFunc;
427
 
421
 
2571
     MENU_BACK(MSG_CONTROL);
2565
     MENU_BACK(MSG_CONTROL);
2572
 
2566
 
2573
     #if ENABLED(LIN_ADVANCE)
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
     #endif
2569
     #endif
2576
 
2570
 
2577
     MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
2571
     MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
3128
    *   void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3122
    *   void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3129
    *   void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3123
    *   void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3130
    *   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
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
    * You can then use one of the menu macros to present the edit interface:
3126
    * You can then use one of the menu macros to present the edit interface:
3135
    *   MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
3127
    *   MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
3141
    * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
3133
    * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
3142
    *
3134
    *
3143
    *       menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
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
   #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
3137
   #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
3149
     bool _menu_edit_ ## _name () { \
3138
     bool _menu_edit_ ## _name () { \
3156
         _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
3145
         _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
3157
         if (editValue != NULL) \
3146
         if (editValue != NULL) \
3158
           *((_type*)editValue) = value; \
3147
           *((_type*)editValue) = value; \
3159
-        else if (editSetter != NULL) \
3160
-          ((void (*)(_type))editSetter)(value); \
3161
         lcd_goto_previous_menu(); \
3148
         lcd_goto_previous_menu(); \
3162
       } \
3149
       } \
3163
       return lcd_clicked; \
3150
       return lcd_clicked; \
3171
       \
3158
       \
3172
       editLabel = pstr; \
3159
       editLabel = pstr; \
3173
       editValue = ptr; \
3160
       editValue = ptr; \
3174
-      editSetter = NULL; \
3175
       minEditValue = minValue * _scale; \
3161
       minEditValue = minValue * _scale; \
3176
       maxEditValue = maxValue * _scale - minEditValue; \
3162
       maxEditValue = maxValue * _scale - minEditValue; \
3177
       encoderPosition = (*ptr) * _scale - minEditValue; \
3163
       encoderPosition = (*ptr) * _scale - minEditValue; \
3185
       currentScreen = menu_edit_callback_ ## _name; \
3171
       currentScreen = menu_edit_callback_ ## _name; \
3186
       callbackFunc = callback; \
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
     typedef void _name
3174
     typedef void _name
3205
 
3175
 
3206
   DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
3176
   DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
3305
     menu_action_setting_edit_bool(pstr, ptr);
3275
     menu_action_setting_edit_bool(pstr, ptr);
3306
     (*callback)();
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
 #endif // ULTIPANEL
3279
 #endif // ULTIPANEL
3315
 
3280
 

Loading…
取消
儲存