Просмотр исходного кода

Group and adjust LCD buttons code

Scott Lahteine 7 лет назад
Родитель
Сommit
1af98519cd
2 измененных файлов: 43 добавлений и 37 удалений
  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 Просмотреть файл

45
     #include "../feature/pause.h"
45
     #include "../feature/pause.h"
46
   #endif
46
   #endif
47
 
47
 
48
-
49
   bool lcd_hasstatus();
48
   bool lcd_hasstatus();
50
   void lcd_setstatus(const char* message, const bool persist=false);
49
   void lcd_setstatus(const char* message, const bool persist=false);
51
   void lcd_setstatusPGM(const char* message, const int8_t level=0);
50
   void lcd_setstatusPGM(const char* message, const int8_t level=0);
90
   #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
89
   #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
91
   #define BUTTON_PRESSED(BN) !READ(BTN_## BN)
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
     extern bool defer_return_to_status;
94
     extern bool defer_return_to_status;
96
 
95
 
114
 
113
 
115
     void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder=0);
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
     void lcd_completion_feedback(const bool good=true);
116
     void lcd_completion_feedback(const bool good=true);
139
 
117
 
140
     #if ENABLED(ADVANCED_PAUSE_FEATURE)
118
     #if ENABLED(ADVANCED_PAUSE_FEATURE)
142
       void lcd_advanced_pause_show_message(const AdvancedPauseMessage message,
120
       void lcd_advanced_pause_show_message(const AdvancedPauseMessage message,
143
                                            const AdvancedPauseMode mode=ADVANCED_PAUSE_MODE_PAUSE_PRINT,
121
                                            const AdvancedPauseMode mode=ADVANCED_PAUSE_MODE_PAUSE_PRINT,
144
                                            const uint8_t extruder=active_extruder);
122
                                            const uint8_t extruder=active_extruder);
145
-    #endif // ADVANCED_PAUSE_FEATURE
123
+    #endif
146
 
124
 
147
     #if ENABLED(G26_MESH_VALIDATION)
125
     #if ENABLED(G26_MESH_VALIDATION)
148
       void lcd_chirp();
126
       void lcd_chirp();
155
       float lcd_z_offset_edit();
133
       float lcd_z_offset_edit();
156
     #endif
134
     #endif
157
 
135
 
158
-  #else
159
-
160
-    inline void lcd_buttons_update() {}
161
-
162
   #endif
136
   #endif
163
 
137
 
164
   #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
138
   #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
243
   constexpr bool lcd_wait_for_move = false;
217
   constexpr bool lcd_wait_for_move = false;
244
 
218
 
245
   inline void lcd_refresh() {}
219
   inline void lcd_refresh() {}
246
-  inline void lcd_buttons_update() {}
247
   inline bool lcd_hasstatus() { return false; }
220
   inline bool lcd_hasstatus() { return false; }
248
   inline void lcd_setstatus(const char* const message, const bool persist=false) { UNUSED(message); UNUSED(persist); }
221
   inline void lcd_setstatus(const char* const message, const bool persist=false) { UNUSED(message); UNUSED(persist); }
249
   inline void lcd_setstatusPGM(const char* const message, const int8_t level=0) { UNUSED(message); UNUSED(level); }
222
   inline void lcd_setstatusPGM(const char* const message, const int8_t level=0) { UNUSED(message); UNUSED(level); }
253
 
226
 
254
 #endif // ULTRA_LCD
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
 #define LCD_MESSAGEPGM(x)      lcd_setstatusPGM(PSTR(x))
262
 #define LCD_MESSAGEPGM(x)      lcd_setstatusPGM(PSTR(x))
257
 #define LCD_ALERTMESSAGEPGM(x) lcd_setalertstatusPGM(PSTR(x))
263
 #define LCD_ALERTMESSAGEPGM(x) lcd_setalertstatusPGM(PSTR(x))
258
 
264
 

+ 8
- 8
Marlin/src/lcd/ultralcd_common_HD44780.h Просмотреть файл

72
     #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
72
     #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
73
 
73
 
74
     // button and encoder bit positions within 'buttons'
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
     #undef LCD_CLICKED
81
     #undef LCD_CLICKED
82
     #if BUTTON_EXISTS(ENC)
82
     #if BUTTON_EXISTS(ENC)
83
       // the pause/stop/restart button is connected to BTN_ENC when used
83
       // the pause/stop/restart button is connected to BTN_ENC when used
84
       #define B_ST (EN_C)                            // Map the pause/stop/resume button into its normalized functional name
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
     #else
86
     #else
87
-      #define LCD_CLICKED (buttons&(B_MI|B_RI))
87
+      #define LCD_CLICKED (buttons & (B_MI|B_RI))
88
     #endif
88
     #endif
89
 
89
 
90
     // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
90
     // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
96
 
96
 
97
       #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
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
       #undef LCD_CLICKED
101
       #undef LCD_CLICKED
102
       #define LCD_CLICKED (buttons & B_MI)
102
       #define LCD_CLICKED (buttons & B_MI)

Загрузка…
Отмена
Сохранить