Ver código fonte

Add encoder rate multiplier

wgm4321 9 anos atrás
pai
commit
65e1fc71be
2 arquivos alterados com 107 adições e 29 exclusões
  1. 5
    0
      Marlin/Configuration_adv.h
  2. 102
    29
      Marlin/ultralcd.cpp

+ 5
- 0
Marlin/Configuration_adv.h Ver arquivo

@@ -284,6 +284,11 @@
284 284
 //=============================Additional Features===========================
285 285
 //===========================================================================
286 286
 
287
+#define ENCODER_RATE_MULTIPLIER	 		// If defined, certain menu edit operations automatically multiply the steps when the encoder is moved quickly
288
+#define ENCODER_10X_STEPS_PER_SEC 75	// If the encoder steps per sec exceed this value, multiple the steps moved by ten to quickly advance the value
289
+#define ENCODER_100X_STEPS_PER_SEC 160  // If the encoder steps per sec exceed this value, multiple the steps moved by 100 to really quickly advance the value
290
+#define ENCODER_RATE_MULTIPLIER_DEBUG   // If defined, output the encoder steps per second value
291
+
287 292
 //#define CHDK 4        //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/
288 293
 #define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again
289 294
 

+ 102
- 29
Marlin/ultralcd.cpp Ver arquivo

@@ -10,6 +10,9 @@
10 10
 
11 11
 int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
12 12
 
13
+bool encoderRateMultiplierEnabled;
14
+int32_t lastEncoderMovementMillis;
15
+
13 16
 /* Configuration settings */
14 17
 int plaPreheatHotendTemp;
15 18
 int plaPreheatHPBTemp;
@@ -101,24 +104,25 @@ static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned l
101 104
 #define ENCODER_FEEDRATE_DEADZONE 10
102 105
 
103 106
 #if !defined(LCD_I2C_VIKI)
104
-  #ifndef ENCODER_STEPS_PER_MENU_ITEM
105
-    #define ENCODER_STEPS_PER_MENU_ITEM 5
106
-  #endif
107
-  #ifndef ENCODER_PULSES_PER_STEP
108
-    #define ENCODER_PULSES_PER_STEP 1
109
-  #endif
107
+#ifndef ENCODER_STEPS_PER_MENU_ITEM
108
+#define ENCODER_STEPS_PER_MENU_ITEM 5
109
+#endif
110
+#ifndef ENCODER_PULSES_PER_STEP
111
+#define ENCODER_PULSES_PER_STEP 1
112
+#endif
110 113
 #else
111
-  #ifndef ENCODER_STEPS_PER_MENU_ITEM
112
-    #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
113
-  #endif
114
-  #ifndef ENCODER_PULSES_PER_STEP
115
-    #define ENCODER_PULSES_PER_STEP 1
116
-  #endif
114
+#ifndef ENCODER_STEPS_PER_MENU_ITEM
115
+#define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
116
+#endif
117
+#ifndef ENCODER_PULSES_PER_STEP
118
+#define ENCODER_PULSES_PER_STEP 1
119
+#endif
117 120
 #endif
118 121
 
119 122
 
120 123
 /* Helper macros for menus */
121 124
 #define START_MENU() do { \
125
+	encoderRateMultiplierEnabled = false; \
122 126
     if (encoderPosition > 0x8000) encoderPosition = 0; \
123 127
     if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
124 128
     uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
@@ -143,9 +147,38 @@ static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned l
143 147
     }\
144 148
     _menuItemNr++;\
145 149
 } while(0)
150
+#ifdef ENCODER_RATE_MULTIPLIER
151
+#define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
152
+    if (_menuItemNr == _lineNr) { \
153
+        if (lcdDrawUpdate) { \
154
+            const char* _label_pstr = PSTR(label); \
155
+            if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
156
+                lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
157
+									            }else{\
158
+                lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
159
+									            }\
160
+						        }\
161
+        if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
162
+            lcd_quick_feedback(); \
163
+			encoderRateMultiplierEnabled = true; \
164
+			lastEncoderMovementMillis = 0; \
165
+            menu_action_ ## type ( args ); \
166
+            return;\
167
+				        }\
168
+		    }\
169
+    _menuItemNr++;\
170
+} while(0)
171
+#endif
146 172
 #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
147 173
 #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
148 174
 #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
175
+#ifdef ENCODER_RATE_MULTIPLIER
176
+#define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
177
+#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
178
+#else
179
+#define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
180
+#define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
181
+#endif
149 182
 #define END_MENU() \
150 183
     if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
151 184
     if ((uint8_t)(encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) - LCD_HEIGHT + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
@@ -205,6 +238,7 @@ static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool
205 238
 /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
206 239
 static void lcd_status_screen()
207 240
 {
241
+	encoderRateMultiplierEnabled = false;
208 242
   #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
209 243
     uint16_t mil = millis();
210 244
     #ifndef PROGRESS_MSG_ONCE
@@ -423,23 +457,23 @@ static void lcd_tune_menu()
423 457
     MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
424 458
     MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);
425 459
 #if TEMP_SENSOR_0 != 0
426
-    MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
460
+    MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
427 461
 #endif
428 462
 #if TEMP_SENSOR_1 != 0
429
-    MENU_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
463
+	MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
430 464
 #endif
431 465
 #if TEMP_SENSOR_2 != 0
432
-    MENU_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
466
+	MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
433 467
 #endif
434 468
 #if TEMP_SENSOR_3 != 0
435
-    MENU_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
469
+	MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
436 470
 #endif
437 471
 
438 472
 
439 473
 #if TEMP_SENSOR_BED != 0
440
-    MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
474
+	MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
441 475
 #endif
442
-    MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
476
+	MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
443 477
     MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);
444 478
     MENU_ITEM_EDIT(int3, MSG_FLOW " 0", &extruder_multiply[0], 10, 999);
445 479
 #if TEMP_SENSOR_1 != 0
@@ -816,21 +850,21 @@ static void lcd_control_temperature_menu()
816 850
   START_MENU();
817 851
   MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
818 852
 #if TEMP_SENSOR_0 != 0
819
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
853
+  MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
820 854
 #endif
821 855
 #if TEMP_SENSOR_1 != 0 && EXTRUDERS > 1
822
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
856
+  MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
823 857
 #endif
824 858
 #if TEMP_SENSOR_2 != 0 && EXTRUDERS > 2
825
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
859
+  MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
826 860
 #endif
827 861
 #if TEMP_SENSOR_3 != 0 && EXTRUDERS > 3
828
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
862
+  MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
829 863
 #endif
830 864
 #if TEMP_SENSOR_BED != 0
831
-  MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
865
+  MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
832 866
 #endif
833
-  MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
867
+  MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
834 868
 #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
835 869
   MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
836 870
   MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
@@ -961,13 +995,13 @@ static void lcd_control_volumetric_menu()
961 995
 	MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
962 996
 
963 997
 	if (volumetric_enabled) {
964
-		MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_0, &filament_size[0], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
998
+		MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_0, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
965 999
 #if EXTRUDERS > 1
966
-		MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_1, &filament_size[1], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
1000
+		MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_1, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
967 1001
 #if EXTRUDERS > 2
968
-		MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_2, &filament_size[2], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
1002
+		MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_2, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
969 1003
 #if EXTRUDERS > 3
970
-		MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_3, &filament_size[3], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
1004
+		MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_3, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
971 1005
 #endif //EXTRUDERS > 3
972 1006
 #endif //EXTRUDERS > 2
973 1007
 #endif //EXTRUDERS > 1
@@ -1322,8 +1356,47 @@ void lcd_update()
1322 1356
 		#endif
1323 1357
         if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
1324 1358
         {
1359
+			int32_t encoderMultiplier = 1;
1360
+
1361
+#ifdef ENCODER_RATE_MULTIPLIER
1362
+			if (encoderRateMultiplierEnabled)
1363
+			{
1364
+				int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
1365
+
1366
+				if (lastEncoderMovementMillis != 0)
1367
+				{
1368
+					// Note that the rate is always calculated between to passes through the 
1369
+					// loop and that the abs of the encoderDiff value is tracked.
1370
+					float encoderStepRate =
1371
+						(float)(encoderMovementSteps) / ((float)(millis() - lastEncoderMovementMillis)) * 1000.0;
1372
+
1373
+					if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC)
1374
+					{
1375
+						encoderMultiplier = 100;
1376
+					}
1377
+					else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC)
1378
+					{
1379
+						encoderMultiplier = 10;
1380
+					}
1381
+
1382
+#ifdef ENCODER_RATE_MULTIPLIER_DEBUG
1383
+					SERIAL_ECHO_START;
1384
+					SERIAL_ECHO("Enc Step Rate: ");
1385
+					SERIAL_ECHO(encoderStepRate);
1386
+					SERIAL_ECHO("  Multiplier: ");
1387
+					SERIAL_ECHO(encoderMultiplier);
1388
+					SERIAL_ECHO("  ENCODER_10X_STEPS_PER_SEC: ");
1389
+					SERIAL_ECHO(ENCODER_10X_STEPS_PER_SEC);
1390
+					SERIAL_ECHO("  ENCODER_100X_STEPS_PER_SEC: ");
1391
+					SERIAL_ECHOLN(ENCODER_100X_STEPS_PER_SEC);
1392
+#endif
1393
+				}
1394
+
1395
+				lastEncoderMovementMillis = millis();
1396
+			}
1397
+#endif
1325 1398
             lcdDrawUpdate = 1;
1326
-            encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
1399
+			encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
1327 1400
             encoderDiff = 0;
1328 1401
             timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
1329 1402
         }

Carregando…
Cancelar
Salvar