Преглед на файлове

Implement reverse menu direction in ultralcd.cpp

Scott Lahteine преди 9 години
родител
ревизия
fbef2f5b61
променени са 1 файла, в които са добавени 62 реда и са изтрити 16 реда
  1. 62
    16
      Marlin/ultralcd.cpp

+ 62
- 16
Marlin/ultralcd.cpp Целия файл

7
 #include "stepper.h"
7
 #include "stepper.h"
8
 #include "configuration_store.h"
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
 int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
29
 int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
11
 
30
 
12
 bool encoderRateMultiplierEnabled;
31
 bool encoderRateMultiplierEnabled;
130
    * START_MENU generates the init code for a menu function
149
    * START_MENU generates the init code for a menu function
131
    */
150
    */
132
   #define START_MENU() do { \
151
   #define START_MENU() do { \
152
+    ENCODER_DIRECTION_MENUS(); \
133
     encoderRateMultiplierEnabled = false; \
153
     encoderRateMultiplierEnabled = false; \
134
     if (encoderPosition > 0x8000) encoderPosition = 0; \
154
     if (encoderPosition > 0x8000) encoderPosition = 0; \
135
     uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
155
     uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
280
  */
300
  */
281
 
301
 
282
 static void lcd_status_screen() {
302
 static void lcd_status_screen() {
303
+  ENCODER_DIRECTION_NORMAL();
283
   encoderRateMultiplierEnabled = false;
304
   encoderRateMultiplierEnabled = false;
284
 
305
 
285
   #if ENABLED(LCD_PROGRESS_BAR)
306
   #if ENABLED(LCD_PROGRESS_BAR)
464
 #if ENABLED(BABYSTEPPING)
485
 #if ENABLED(BABYSTEPPING)
465
 
486
 
466
   static void _lcd_babystep(int axis, const char* msg) {
487
   static void _lcd_babystep(int axis, const char* msg) {
488
+    ENCODER_DIRECTION_NORMAL(); 
467
     if (encoderPosition != 0) {
489
     if (encoderPosition != 0) {
468
       babystepsTodo[axis] += BABYSTEP_MULTIPLICATOR * (int)encoderPosition;
490
       babystepsTodo[axis] += BABYSTEP_MULTIPLICATOR * (int)encoderPosition;
469
       encoderPosition = 0;
491
       encoderPosition = 0;
828
 static void lcd_move_menu_axis();
850
 static void lcd_move_menu_axis();
829
 
851
 
830
 static void _lcd_move(const char* name, AxisEnum axis, int min, int max) {
852
 static void _lcd_move(const char* name, AxisEnum axis, int min, int max) {
853
+  ENCODER_DIRECTION_NORMAL(); 
831
   if ((encoderPosition != 0) && (movesplanned() <= 3)) {
854
   if ((encoderPosition != 0) && (movesplanned() <= 3)) {
832
     refresh_cmd_timeout();
855
     refresh_cmd_timeout();
833
     current_position[axis] += float((int)encoderPosition) * move_menu_scale;
856
     current_position[axis] += float((int)encoderPosition) * move_menu_scale;
855
     uint8_t e
878
     uint8_t e
856
   #endif
879
   #endif
857
 ) {
880
 ) {
881
+  ENCODER_DIRECTION_NORMAL(); 
858
   #if EXTRUDERS > 1
882
   #if EXTRUDERS > 1
859
     unsigned short original_active_extruder = active_extruder;
883
     unsigned short original_active_extruder = active_extruder;
860
     active_extruder = e;
884
     active_extruder = e;
1263
  */
1287
  */
1264
 #if ENABLED(HAS_LCD_CONTRAST)
1288
 #if ENABLED(HAS_LCD_CONTRAST)
1265
   static void lcd_set_contrast() {
1289
   static void lcd_set_contrast() {
1290
+    ENCODER_DIRECTION_NORMAL();
1266
     if (encoderPosition != 0) {
1291
     if (encoderPosition != 0) {
1267
       #if ENABLED(U8GLIB_LM6059_AF)
1292
       #if ENABLED(U8GLIB_LM6059_AF)
1268
         lcd_contrast += encoderPosition;
1293
         lcd_contrast += encoderPosition;
1331
    *
1356
    *
1332
    */
1357
    */
1333
   void lcd_sdcard_menu() {
1358
   void lcd_sdcard_menu() {
1359
+    ENCODER_DIRECTION_MENUS();
1334
     if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
1360
     if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
1335
     uint16_t fileCnt = card.getnrfilenames();
1361
     uint16_t fileCnt = card.getnrfilenames();
1336
     START_MENU();
1362
     START_MENU();
1371
  *
1397
  *
1372
  * Functions for editing single values
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
 #define menu_edit_type(_type, _name, _strFunc, scale) \
1422
 #define menu_edit_type(_type, _name, _strFunc, scale) \
1376
   bool _menu_edit_ ## _name () { \
1423
   bool _menu_edit_ ## _name () { \
1424
+    ENCODER_DIRECTION_NORMAL(); \
1377
     bool isClicked = LCD_CLICKED; \
1425
     bool isClicked = LCD_CLICKED; \
1378
     if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
1426
     if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
1379
     if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
1427
     if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
1937
       buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
1985
       buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
1938
     #endif //!NEWPANEL
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
     //manage encoder rotation
1997
     //manage encoder rotation
1941
     uint8_t enc = 0;
1998
     uint8_t enc = 0;
1942
     if (buttons & EN_A) enc |= B01;
1999
     if (buttons & EN_A) enc |= B01;
1943
     if (buttons & EN_B) enc |= B10;
2000
     if (buttons & EN_B) enc |= B10;
1944
     if (enc != lastEncoderBits) {
2001
     if (enc != lastEncoderBits) {
1945
       switch (enc) {
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
     lastEncoderBits = enc;
2009
     lastEncoderBits = enc;
2242
    *   - Click saves the Z and goes to the next mesh point
2287
    *   - Click saves the Z and goes to the next mesh point
2243
    */
2288
    */
2244
   static void _lcd_level_bed() {
2289
   static void _lcd_level_bed() {
2290
+    ENCODER_DIRECTION_NORMAL(); 
2245
     if ((encoderPosition != 0) && (movesplanned() <= 3)) {
2291
     if ((encoderPosition != 0) && (movesplanned() <= 3)) {
2246
       refresh_cmd_timeout();
2292
       refresh_cmd_timeout();
2247
       current_position[Z_AXIS] += float((int)encoderPosition) * (MBL_Z_STEP);
2293
       current_position[Z_AXIS] += float((int)encoderPosition) * (MBL_Z_STEP);

Loading…
Отказ
Запис