Bladeren bron

Group and adjust LCD buttons code

Scott Lahteine 6 jaren geleden
bovenliggende
commit
1af98519cd
2 gewijzigde bestanden met toevoegingen van 43 en 37 verwijderingen
  1. 35
    29
      Marlin/src/lcd/ultralcd.h
  2. 8
    8
      Marlin/src/lcd/ultralcd_common_HD44780.h

+ 35
- 29
Marlin/src/lcd/ultralcd.h Bestand weergeven

@@ -45,7 +45,6 @@
45 45
     #include "../feature/pause.h"
46 46
   #endif
47 47
 
48
-
49 48
   bool lcd_hasstatus();
50 49
   void lcd_setstatus(const char* message, const bool persist=false);
51 50
   void lcd_setstatusPGM(const char* message, const int8_t level=0);
@@ -90,7 +89,7 @@
90 89
   #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
91 90
   #define BUTTON_PRESSED(BN) !READ(BTN_## BN)
92 91
 
93
-  #if ENABLED(ULTIPANEL)
92
+  #if ENABLED(ULTIPANEL) // LCD with a click-wheel input
94 93
 
95 94
     extern bool defer_return_to_status;
96 95
 
@@ -114,27 +113,6 @@
114 113
 
115 114
     void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder=0);
116 115
 
117
-    // Encoder click is directly connected
118
-
119
-    #define BLEN_A 0
120
-    #define BLEN_B 1
121
-
122
-    #define EN_A (_BV(BLEN_A))
123
-    #define EN_B (_BV(BLEN_B))
124
-
125
-    #if BUTTON_EXISTS(ENC)
126
-      #define BLEN_C 2
127
-      #define EN_C (_BV(BLEN_C))
128
-    #endif
129
-
130
-    #if BUTTON_EXISTS(BACK)
131
-      #define BLEN_D 3
132
-      #define EN_D _BV(BLEN_D)
133
-      #define LCD_BACK_CLICKED (buttons & EN_D)
134
-    #endif
135
-
136
-    extern volatile uint8_t buttons;  // The last-checked buttons in a bit array.
137
-    void lcd_buttons_update();
138 116
     void lcd_completion_feedback(const bool good=true);
139 117
 
140 118
     #if ENABLED(ADVANCED_PAUSE_FEATURE)
@@ -142,7 +120,7 @@
142 120
       void lcd_advanced_pause_show_message(const AdvancedPauseMessage message,
143 121
                                            const AdvancedPauseMode mode=ADVANCED_PAUSE_MODE_PAUSE_PRINT,
144 122
                                            const uint8_t extruder=active_extruder);
145
-    #endif // ADVANCED_PAUSE_FEATURE
123
+    #endif
146 124
 
147 125
     #if ENABLED(G26_MESH_VALIDATION)
148 126
       void lcd_chirp();
@@ -155,10 +133,6 @@
155 133
       float lcd_z_offset_edit();
156 134
     #endif
157 135
 
158
-  #else
159
-
160
-    inline void lcd_buttons_update() {}
161
-
162 136
   #endif
163 137
 
164 138
   #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
@@ -243,7 +217,6 @@
243 217
   constexpr bool lcd_wait_for_move = false;
244 218
 
245 219
   inline void lcd_refresh() {}
246
-  inline void lcd_buttons_update() {}
247 220
   inline bool lcd_hasstatus() { return false; }
248 221
   inline void lcd_setstatus(const char* const message, const bool persist=false) { UNUSED(message); UNUSED(persist); }
249 222
   inline void lcd_setstatusPGM(const char* const message, const int8_t level=0) { UNUSED(message); UNUSED(level); }
@@ -253,6 +226,39 @@
253 226
 
254 227
 #endif // ULTRA_LCD
255 228
 
229
+#if ENABLED(ULTIPANEL)
230
+
231
+  #if ENABLED(NEWPANEL) // Uses digital switches, not a shift register
232
+
233
+    // Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
234
+    #define BLEN_A 0
235
+    #define BLEN_B 1
236
+
237
+    #define EN_A _BV(BLEN_A)
238
+    #define EN_B _BV(BLEN_B)
239
+
240
+    #if BUTTON_EXISTS(ENC)
241
+      #define BLEN_C 2
242
+      #define EN_C _BV(BLEN_C)
243
+    #endif
244
+
245
+    #if BUTTON_EXISTS(BACK)
246
+      #define BLEN_D 3
247
+      #define EN_D _BV(BLEN_D)
248
+      #define LCD_BACK_CLICKED (buttons & EN_D)
249
+    #endif
250
+
251
+  #endif // NEWPANEL
252
+
253
+  extern volatile uint8_t buttons;  // The last-checked buttons in a bit array.
254
+  void lcd_buttons_update();
255
+
256
+#else
257
+
258
+  inline void lcd_buttons_update() {}
259
+
260
+#endif
261
+
256 262
 #define LCD_MESSAGEPGM(x)      lcd_setstatusPGM(PSTR(x))
257 263
 #define LCD_ALERTMESSAGEPGM(x) lcd_setalertstatusPGM(PSTR(x))
258 264
 

+ 8
- 8
Marlin/src/lcd/ultralcd_common_HD44780.h Bestand weergeven

@@ -72,19 +72,19 @@ extern volatile uint8_t buttons;  //an extended version of the last checked butt
72 72
     #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
73 73
 
74 74
     // button and encoder bit positions within 'buttons'
75
-    #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET)    // The remaining normalized buttons are all read via I2C
76
-    #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
77
-    #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
78
-    #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
79
-    #define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET)
75
+    #define B_LE (BUTTON_LEFT   << B_I2C_BTN_OFFSET)    // The remaining normalized buttons are all read via I2C
76
+    #define B_UP (BUTTON_UP     << B_I2C_BTN_OFFSET)
77
+    #define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
78
+    #define B_DW (BUTTON_DOWN   << B_I2C_BTN_OFFSET)
79
+    #define B_RI (BUTTON_RIGHT  << B_I2C_BTN_OFFSET)
80 80
 
81 81
     #undef LCD_CLICKED
82 82
     #if BUTTON_EXISTS(ENC)
83 83
       // the pause/stop/restart button is connected to BTN_ENC when used
84 84
       #define B_ST (EN_C)                            // Map the pause/stop/resume button into its normalized functional name
85
-      #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
85
+      #define LCD_CLICKED (buttons & (B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
86 86
     #else
87
-      #define LCD_CLICKED (buttons&(B_MI|B_RI))
87
+      #define LCD_CLICKED (buttons & (B_MI|B_RI))
88 88
     #endif
89 89
 
90 90
     // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
@@ -96,7 +96,7 @@ extern volatile uint8_t buttons;  //an extended version of the last checked butt
96 96
 
97 97
       #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
98 98
 
99
-      #define B_MI (PANELOLU2_ENCODER_C<<B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
99
+      #define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
100 100
 
101 101
       #undef LCD_CLICKED
102 102
       #define LCD_CLICKED (buttons & B_MI)

Laden…
Annuleren
Opslaan