Selaa lähdekoodia

Implement reverse menu direction in ultralcd.cpp

Scott Lahteine 9 vuotta sitten
vanhempi
commit
fbef2f5b61
1 muutettua tiedostoa jossa 62 lisäystä ja 16 poistoa
  1. 62
    16
      Marlin/ultralcd.cpp

+ 62
- 16
Marlin/ultralcd.cpp Näytä tiedosto

@@ -7,6 +7,25 @@
7 7
 #include "stepper.h"
8 8
 #include "configuration_store.h"
9 9
 
10
+/**
11
+ * REVERSE_MENU_DIRECTION
12
+ *
13
+ * To reverse the menu direction we need a general way to reverse
14
+ * the direction of the encoder everywhere. So encoderDirection is
15
+ * added to allow the encoder to go the other way.
16
+ *
17
+ * This behavior is limited to scrolling Menus and SD card listings,
18
+ * and is disabled in other contexts.
19
+ */
20
+#if ENABLED(REVERSE_MENU_DIRECTION)
21
+  int8_t encoderDirection = 1;
22
+  #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
23
+  #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
24
+#else
25
+  #define ENCODER_DIRECTION_NORMAL() ;
26
+  #define ENCODER_DIRECTION_MENUS() ;
27
+#endif
28
+
10 29
 int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
11 30
 
12 31
 bool encoderRateMultiplierEnabled;
@@ -130,6 +149,7 @@ static void lcd_status_screen();
130 149
    * START_MENU generates the init code for a menu function
131 150
    */
132 151
   #define START_MENU() do { \
152
+    ENCODER_DIRECTION_MENUS(); \
133 153
     encoderRateMultiplierEnabled = false; \
134 154
     if (encoderPosition > 0x8000) encoderPosition = 0; \
135 155
     uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
@@ -280,6 +300,7 @@ static void lcd_goto_previous_menu() { lcd_goto_menu(prevMenu, true, prevEncoder
280 300
  */
281 301
 
282 302
 static void lcd_status_screen() {
303
+  ENCODER_DIRECTION_NORMAL();
283 304
   encoderRateMultiplierEnabled = false;
284 305
 
285 306
   #if ENABLED(LCD_PROGRESS_BAR)
@@ -464,6 +485,7 @@ void lcd_set_home_offsets() {
464 485
 #if ENABLED(BABYSTEPPING)
465 486
 
466 487
   static void _lcd_babystep(int axis, const char* msg) {
488
+    ENCODER_DIRECTION_NORMAL(); 
467 489
     if (encoderPosition != 0) {
468 490
       babystepsTodo[axis] += BABYSTEP_MULTIPLICATOR * (int)encoderPosition;
469 491
       encoderPosition = 0;
@@ -828,6 +850,7 @@ float move_menu_scale;
828 850
 static void lcd_move_menu_axis();
829 851
 
830 852
 static void _lcd_move(const char* name, AxisEnum axis, int min, int max) {
853
+  ENCODER_DIRECTION_NORMAL(); 
831 854
   if ((encoderPosition != 0) && (movesplanned() <= 3)) {
832 855
     refresh_cmd_timeout();
833 856
     current_position[axis] += float((int)encoderPosition) * move_menu_scale;
@@ -855,6 +878,7 @@ static void lcd_move_e(
855 878
     uint8_t e
856 879
   #endif
857 880
 ) {
881
+  ENCODER_DIRECTION_NORMAL(); 
858 882
   #if EXTRUDERS > 1
859 883
     unsigned short original_active_extruder = active_extruder;
860 884
     active_extruder = e;
@@ -1263,6 +1287,7 @@ static void lcd_control_volumetric_menu() {
1263 1287
  */
1264 1288
 #if ENABLED(HAS_LCD_CONTRAST)
1265 1289
   static void lcd_set_contrast() {
1290
+    ENCODER_DIRECTION_NORMAL();
1266 1291
     if (encoderPosition != 0) {
1267 1292
       #if ENABLED(U8GLIB_LM6059_AF)
1268 1293
         lcd_contrast += encoderPosition;
@@ -1331,6 +1356,7 @@ static void lcd_control_volumetric_menu() {
1331 1356
    *
1332 1357
    */
1333 1358
   void lcd_sdcard_menu() {
1359
+    ENCODER_DIRECTION_MENUS();
1334 1360
     if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
1335 1361
     uint16_t fileCnt = card.getnrfilenames();
1336 1362
     START_MENU();
@@ -1371,9 +1397,31 @@ static void lcd_control_volumetric_menu() {
1371 1397
  *
1372 1398
  * Functions for editing single values
1373 1399
  *
1400
+ * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
1401
+ *
1402
+ * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
1403
+ *
1404
+ *   bool _menu_edit_int3();
1405
+ *   void menu_edit_int3(); // edit int (interactively)
1406
+ *   void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
1407
+ *   static void _menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
1408
+ *   static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
1409
+ *   static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callback); // edit int with callback
1410
+ *
1411
+ * You can then use one of the menu macros to present the edit interface:
1412
+ *   MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
1413
+ *
1414
+ * This expands into a more primitive menu item:
1415
+ *   MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
1416
+ *
1417
+ *
1418
+ * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
1419
+ *     
1420
+ *       menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
1374 1421
  */
1375 1422
 #define menu_edit_type(_type, _name, _strFunc, scale) \
1376 1423
   bool _menu_edit_ ## _name () { \
1424
+    ENCODER_DIRECTION_NORMAL(); \
1377 1425
     bool isClicked = LCD_CLICKED; \
1378 1426
     if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
1379 1427
     if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
@@ -1937,28 +1985,25 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
1937 1985
       buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
1938 1986
     #endif //!NEWPANEL
1939 1987
 
1988
+    #if ENABLED(REVERSE_MENU_DIRECTION)
1989
+      #define ENCODER_DIFF_CW  (encoderDiff += encoderDirection)
1990
+      #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
1991
+    #else
1992
+      #define ENCODER_DIFF_CW  (encoderDiff++)
1993
+      #define ENCODER_DIFF_CCW (encoderDiff--)
1994
+    #endif
1995
+    #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
1996
+
1940 1997
     //manage encoder rotation
1941 1998
     uint8_t enc = 0;
1942 1999
     if (buttons & EN_A) enc |= B01;
1943 2000
     if (buttons & EN_B) enc |= B10;
1944 2001
     if (enc != lastEncoderBits) {
1945 2002
       switch (enc) {
1946
-        case encrot0:
1947
-          if (lastEncoderBits == encrot3) encoderDiff++;
1948
-          else if (lastEncoderBits == encrot1) encoderDiff--;
1949
-          break;
1950
-        case encrot1:
1951
-          if (lastEncoderBits == encrot0) encoderDiff++;
1952
-          else if (lastEncoderBits == encrot2) encoderDiff--;
1953
-          break;
1954
-        case encrot2:
1955
-          if (lastEncoderBits == encrot1) encoderDiff++;
1956
-          else if (lastEncoderBits == encrot3) encoderDiff--;
1957
-          break;
1958
-        case encrot3:
1959
-          if (lastEncoderBits == encrot2) encoderDiff++;
1960
-          else if (lastEncoderBits == encrot0) encoderDiff--;
1961
-          break;
2003
+        case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
2004
+        case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
2005
+        case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
2006
+        case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
1962 2007
       }
1963 2008
     }
1964 2009
     lastEncoderBits = enc;
@@ -2242,6 +2287,7 @@ char* ftostr52(const float& x) {
2242 2287
    *   - Click saves the Z and goes to the next mesh point
2243 2288
    */
2244 2289
   static void _lcd_level_bed() {
2290
+    ENCODER_DIRECTION_NORMAL(); 
2245 2291
     if ((encoderPosition != 0) && (movesplanned() <= 3)) {
2246 2292
       refresh_cmd_timeout();
2247 2293
       current_position[Z_AXIS] += float((int)encoderPosition) * (MBL_Z_STEP);

Loading…
Peruuta
Tallenna