瀏覽代碼

Merge pull request #6810 from thinkyhead/bf_lcd_live_editing

Add "live editing" option to LCD menus
Scott Lahteine 7 年之前
父節點
當前提交
ea906e4da7
共有 4 個文件被更改,包括 37 次插入55 次删除
  1. 3
    3
      Marlin/configuration_store.cpp
  2. 31
    49
      Marlin/ultralcd.cpp
  3. 2
    2
      Marlin/ultralcd.h
  4. 1
    1
      Marlin/ultralcd_impl_DOGM.h

+ 3
- 3
Marlin/configuration_store.cpp 查看文件

@@ -123,7 +123,7 @@
123 123
  *  490  M304 PID  thermalManager.bedKp, .bedKi, .bedKd (float x3)
124 124
  *
125 125
  * DOGLCD:                                          2 bytes
126
- *  502  M250 C    lcd_contrast                     (int)
126
+ *  502  M250 C    lcd_contrast                     (uint16_t)
127 127
  *
128 128
  * FWRETRACT:                                       29 bytes
129 129
  *  504  M209 S    autoretract_enabled              (bool)
@@ -502,7 +502,7 @@ void MarlinSettings::postprocess() {
502 502
     #endif
503 503
 
504 504
     #if !HAS_LCD_CONTRAST
505
-      const int lcd_contrast = 32;
505
+      const uint16_t lcd_contrast = 32;
506 506
     #endif
507 507
     EEPROM_WRITE(lcd_contrast);
508 508
 
@@ -883,7 +883,7 @@ void MarlinSettings::postprocess() {
883 883
       #endif
884 884
 
885 885
       #if !HAS_LCD_CONTRAST
886
-        int lcd_contrast;
886
+        uint16_t lcd_contrast;
887 887
       #endif
888 888
       EEPROM_READ(lcd_contrast);
889 889
 

+ 31
- 49
Marlin/ultralcd.cpp 查看文件

@@ -148,10 +148,6 @@ uint16_t max_display_update_time = 0;
148 148
     void lcd_dac_write_eeprom();
149 149
   #endif
150 150
 
151
-  #if HAS_LCD_CONTRAST
152
-    void lcd_set_contrast();
153
-  #endif
154
-
155 151
   #if ENABLED(FWRETRACT)
156 152
     void lcd_control_retract_menu();
157 153
   #endif
@@ -181,7 +177,7 @@ uint16_t max_display_update_time = 0;
181 177
     void menu_edit_callback_ ## _name(); \
182 178
     void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
183 179
     void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
184
-    void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback); \
180
+    void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
185 181
     typedef void _name##_void
186 182
 
187 183
   DECLARE_MENU_EDIT_TYPE(int, int3);
@@ -419,6 +415,7 @@ uint16_t max_display_update_time = 0;
419 415
   void *editValue;
420 416
   int32_t minEditValue, maxEditValue;
421 417
   screenFunc_t callbackFunc;
418
+  bool liveEdit;
422 419
 
423 420
   // Manual Moves
424 421
   const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
@@ -590,7 +587,7 @@ void lcd_status_screen() {
590 587
     }
591 588
 
592 589
     #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
593
-      int new_frm = feedrate_percentage + (int32_t)encoderPosition;
590
+      const int new_frm = feedrate_percentage + (int32_t)encoderPosition;
594 591
       // Dead zone at 100% feedrate
595 592
       if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
596 593
         feedrate_percentage = 100;
@@ -2465,6 +2462,17 @@ void kill_screen(const char* lcd_msg) {
2465 2462
    *
2466 2463
    */
2467 2464
 
2465
+  /**
2466
+   *
2467
+   * Callback for LCD contrast
2468
+   *
2469
+   */
2470
+  #if HAS_LCD_CONTRAST
2471
+
2472
+    void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
2473
+
2474
+  #endif // HAS_LCD_CONTRAST
2475
+
2468 2476
   #if ENABLED(EEPROM_SETTINGS)
2469 2477
     static void lcd_store_settings()   { lcd_completion_feedback(settings.save()); }
2470 2478
     static void lcd_load_settings()    { lcd_completion_feedback(settings.load()); }
@@ -2483,8 +2491,7 @@ void kill_screen(const char* lcd_msg) {
2483 2491
     MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
2484 2492
 
2485 2493
     #if HAS_LCD_CONTRAST
2486
-      //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
2487
-      MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
2494
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
2488 2495
     #endif
2489 2496
     #if ENABLED(FWRETRACT)
2490 2497
       MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
@@ -2955,32 +2962,6 @@ void kill_screen(const char* lcd_msg) {
2955 2962
 
2956 2963
   /**
2957 2964
    *
2958
-   * "Control" > "Contrast" submenu
2959
-   *
2960
-   */
2961
-  #if HAS_LCD_CONTRAST
2962
-    void lcd_set_contrast() {
2963
-      if (lcd_clicked) { return lcd_goto_previous_menu(); }
2964
-      ENCODER_DIRECTION_NORMAL();
2965
-      if (encoderPosition) {
2966
-        set_lcd_contrast(lcd_contrast + encoderPosition);
2967
-        encoderPosition = 0;
2968
-        lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2969
-      }
2970
-      if (lcdDrawUpdate) {
2971
-        lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
2972
-          #if LCD_CONTRAST_MAX >= 100
2973
-            itostr3(lcd_contrast)
2974
-          #else
2975
-            itostr2(lcd_contrast)
2976
-          #endif
2977
-        );
2978
-      }
2979
-    }
2980
-  #endif // HAS_LCD_CONTRAST
2981
-
2982
-  /**
2983
-   *
2984 2965
    * "Control" > "Retract" submenu
2985 2966
    *
2986 2967
    */
@@ -3492,7 +3473,7 @@ void kill_screen(const char* lcd_msg) {
3492 3473
    *   void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
3493 3474
    *   void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3494 3475
    *   void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
3495
-   *   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
3476
+   *   void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback, const bool live); // edit int with callback
3496 3477
    *
3497 3478
    * You can then use one of the menu macros to present the edit interface:
3498 3479
    *   MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
@@ -3500,29 +3481,27 @@ void kill_screen(const char* lcd_msg) {
3500 3481
    * This expands into a more primitive menu item:
3501 3482
    *   MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
3502 3483
    *
3503
-   *
3504
-   * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
3505
-   *
3484
+   * ...which calls:
3506 3485
    *       menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
3507 3486
    */
3508 3487
   #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
3509
-    bool _menu_edit_ ## _name () { \
3488
+    bool _menu_edit_ ## _name() { \
3510 3489
       ENCODER_DIRECTION_NORMAL(); \
3511 3490
       if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
3512 3491
       if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
3513 3492
       if (lcdDrawUpdate) \
3514 3493
         lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
3515
-      if (lcd_clicked) { \
3494
+      if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
3516 3495
         _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
3517
-        if (editValue != NULL) \
3518
-          *((_type*)editValue) = value; \
3519
-        lcd_goto_previous_menu(); \
3496
+        if (editValue != NULL) *((_type*)editValue) = value; \
3497
+        if (liveEdit) (*callbackFunc)(); \
3498
+        if (lcd_clicked) lcd_goto_previous_menu(); \
3520 3499
       } \
3521 3500
       return lcd_clicked; \
3522 3501
     } \
3523
-    void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
3524
-    void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
3525
-    void _menu_action_setting_edit_ ## _name (const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
3502
+    void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
3503
+    void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
3504
+    void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
3526 3505
       lcd_save_previous_screen(); \
3527 3506
       \
3528 3507
       lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
@@ -3533,14 +3512,15 @@ void kill_screen(const char* lcd_msg) {
3533 3512
       maxEditValue = maxValue * _scale - minEditValue; \
3534 3513
       encoderPosition = (*ptr) * _scale - minEditValue; \
3535 3514
     } \
3536
-    void menu_action_setting_edit_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
3515
+    void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
3537 3516
       _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
3538 3517
       currentScreen = menu_edit_ ## _name; \
3539 3518
     } \
3540
-    void menu_action_setting_edit_callback_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback) { \
3519
+    void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
3541 3520
       _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
3542 3521
       currentScreen = menu_edit_callback_ ## _name; \
3543 3522
       callbackFunc = callback; \
3523
+      liveEdit = live; \
3544 3524
     } \
3545 3525
     typedef void _name
3546 3526
 
@@ -3641,7 +3621,7 @@ void kill_screen(const char* lcd_msg) {
3641 3621
 
3642 3622
   #endif // SDSUPPORT
3643 3623
 
3644
-  void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
3624
+  void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
3645 3625
   void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
3646 3626
     menu_action_setting_edit_bool(pstr, ptr);
3647 3627
     (*callback)();
@@ -4071,10 +4051,12 @@ void lcd_setalertstatuspgm(const char * const message) {
4071 4051
 void lcd_reset_alert_level() { lcd_status_message_level = 0; }
4072 4052
 
4073 4053
 #if HAS_LCD_CONTRAST
4054
+
4074 4055
   void set_lcd_contrast(const int value) {
4075 4056
     lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
4076 4057
     u8g.setContrast(lcd_contrast);
4077 4058
   }
4059
+
4078 4060
 #endif
4079 4061
 
4080 4062
 #if ENABLED(ULTIPANEL)

+ 2
- 2
Marlin/ultralcd.h 查看文件

@@ -55,8 +55,8 @@
55 55
   #endif
56 56
 
57 57
   #if ENABLED(DOGLCD)
58
-    extern int lcd_contrast;
59
-    void set_lcd_contrast(int value);
58
+    extern uint16_t lcd_contrast;
59
+    void set_lcd_contrast(uint16_t value);
60 60
   #elif ENABLED(SHOW_BOOTSCREEN)
61 61
     void bootscreen();
62 62
   #endif

+ 1
- 1
Marlin/ultralcd_impl_DOGM.h 查看文件

@@ -195,7 +195,7 @@
195 195
 
196 196
 #include "utf_mapper.h"
197 197
 
198
-int lcd_contrast;
198
+uint16_t lcd_contrast;
199 199
 static char currentfont = 0;
200 200
 
201 201
 // The current graphical page being rendered

Loading…
取消
儲存