Explorar el Código

EXTENSIBLE_UI Joystick support (#15303)

Marcio Teixeira hace 5 años
padre
commit
7f117bfc60

+ 46
- 30
Marlin/src/feature/joystick.cpp Ver fichero

@@ -36,6 +36,10 @@
36 36
 
37 37
 Joystick joystick;
38 38
 
39
+#if ENABLED(EXTENSIBLE_UI)
40
+  #include "../lcd/extensible_ui/ui_api.h"
41
+#endif
42
+
39 43
 #if HAS_JOY_ADC_X
40 44
   temp_info_t Joystick::x; // = { 0 }
41 45
 #endif
@@ -65,35 +69,39 @@ Joystick joystick;
65 69
   }
66 70
 #endif
67 71
 
68
-void Joystick::calculate(float norm_jog[XYZ]) {
69
-  // Do nothing if enable pin (active-low) is not LOW
70
-  #if HAS_JOY_ADC_EN
71
-    if (READ(JOY_EN_PIN)) return;
72
-  #endif
73
-
74
-  auto _normalize_joy = [](float &adc, const int16_t raw, const int16_t (&joy_limits)[4]) {
75
-    if (WITHIN(raw, joy_limits[0], joy_limits[3])) {
76
-      // within limits, check deadzone
77
-      if (raw > joy_limits[2])
78
-        adc = (raw - joy_limits[2]) / float(joy_limits[3] - joy_limits[2]);
79
-      else if (raw < joy_limits[1])
80
-        adc = (raw - joy_limits[1]) / float(joy_limits[1] - joy_limits[0]);  // negative value
81
-    }
82
-  };
83
-
84
-  #if HAS_JOY_ADC_X
85
-    static constexpr int16_t joy_x_limits[4] = JOY_X_LIMITS;
86
-    _normalize_joy(norm_jog[X_AXIS], x.raw, joy_x_limits);
87
-  #endif
88
-  #if HAS_JOY_ADC_Y
89
-    static constexpr int16_t joy_y_limits[4] = JOY_Y_LIMITS;
90
-    _normalize_joy(norm_jog[Y_AXIS], y.raw, joy_y_limits);
91
-  #endif
92
-  #if HAS_JOY_ADC_Z
93
-    static constexpr int16_t joy_z_limits[4] = JOY_Z_LIMITS;
94
-    _normalize_joy(norm_jog[Z_AXIS], z.raw, joy_z_limits);
95
-  #endif
96
-}
72
+#if HAS_JOY_ADC_X || HAS_JOY_ADC_Y || HAS_JOY_ADC_Z
73
+
74
+  void Joystick::calculate(float (&norm_jog)[XYZ]) {
75
+    // Do nothing if enable pin (active-low) is not LOW
76
+    #if HAS_JOY_ADC_EN
77
+      if (READ(JOY_EN_PIN)) return;
78
+    #endif
79
+
80
+    auto _normalize_joy = [](float &adc, const int16_t raw, const int16_t (&joy_limits)[4]) {
81
+      if (WITHIN(raw, joy_limits[0], joy_limits[3])) {
82
+        // within limits, check deadzone
83
+        if (raw > joy_limits[2])
84
+          adc = (raw - joy_limits[2]) / float(joy_limits[3] - joy_limits[2]);
85
+        else if (raw < joy_limits[1])
86
+          adc = (raw - joy_limits[1]) / float(joy_limits[1] - joy_limits[0]);  // negative value
87
+      }
88
+    };
89
+
90
+    #if HAS_JOY_ADC_X
91
+      static constexpr int16_t joy_x_limits[4] = JOY_X_LIMITS;
92
+      _normalize_joy(norm_jog[X_AXIS], x.raw, joy_x_limits);
93
+    #endif
94
+    #if HAS_JOY_ADC_Y
95
+      static constexpr int16_t joy_y_limits[4] = JOY_Y_LIMITS;
96
+      _normalize_joy(norm_jog[Y_AXIS], y.raw, joy_y_limits);
97
+    #endif
98
+    #if HAS_JOY_ADC_Z
99
+      static constexpr int16_t joy_z_limits[4] = JOY_Z_LIMITS;
100
+      _normalize_joy(norm_jog[Z_AXIS], z.raw, joy_z_limits);
101
+    #endif
102
+  }
103
+
104
+#endif
97 105
 
98 106
 #if ENABLED(POLL_JOG)
99 107
 
@@ -122,11 +130,19 @@ void Joystick::calculate(float norm_jog[XYZ]) {
122 130
     float norm_jog[XYZ] = { 0 };
123 131
 
124 132
     // Use ADC values and defined limits. The active zone is normalized: -1..0 (dead) 0..1
125
-    joystick.calculate(norm_jog);
133
+    #if HAS_JOY_ADC_X || HAS_JOY_ADC_Y || HAS_JOY_ADC_Z
134
+      joystick.calculate(norm_jog);
135
+    #endif
126 136
 
127 137
     // Other non-joystick poll-based jogging could be implemented here
128 138
     // with "jogging" encapsulated as a more general class.
129 139
 
140
+    #if ENABLED(EXTENSIBLE_UI)
141
+      norm_jog[X_AXIS] = ExtUI::norm_jog[X_AXIS];
142
+      norm_jog[Y_AXIS] = ExtUI::norm_jog[Y_AXIS];
143
+      norm_jog[Z_AXIS] = ExtUI::norm_jog[Z_AXIS];
144
+    #endif
145
+
130 146
     // Jogging value maps continuously (quadratic relationship) to feedrate
131 147
     float move_dist[XYZ] = { 0 }, hypot2 = 0;
132 148
     LOOP_XYZ(i) if (norm_jog[i]) {

+ 1
- 1
Marlin/src/feature/joystick.h Ver fichero

@@ -46,7 +46,7 @@ class Joystick {
46 46
     #if ENABLED(JOYSTICK_DEBUG)
47 47
       static void report();
48 48
     #endif
49
-    static void calculate(float norm_jog[XYZ]);
49
+    static void calculate(float (&norm_jog)[XYZ]);
50 50
     static void inject_jog_moves();
51 51
 };
52 52
 

+ 5
- 3
Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/event_loop.cpp Ver fichero

@@ -156,9 +156,11 @@ namespace FTDI {
156 156
         if (!UIData::flags.bits.touch_debouncing) {
157 157
           if (tag == pressed_tag) {
158 158
             // The user is holding down a button.
159
-            if (touch_timer.elapsed(1000 / TOUCH_REPEATS_PER_SECOND) && current_screen.onTouchHeld(tag)) {
160
-              current_screen.onRefresh();
161
-              if (UIData::flags.bits.touch_repeat_sound) sound.play(repeat_sound);
159
+            if (touch_timer.elapsed(1000 / TOUCH_REPEATS_PER_SECOND)) {
160
+              if (current_screen.onTouchHeld(tag)) {
161
+                current_screen.onRefresh();
162
+                if (UIData::flags.bits.touch_repeat_sound) sound.play(repeat_sound);
163
+              }
162 164
               touch_timer.start();
163 165
             }
164 166
           }

+ 1
- 7
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_confirm_home_e.cpp Ver fichero

@@ -36,13 +36,7 @@ void BioConfirmHomeE::onRedraw(draw_mode_t) {
36 36
 bool BioConfirmHomeE::onTouchEnd(uint8_t tag) {
37 37
   switch (tag) {
38 38
     case 1:
39
-      SpinnerDialogBox::enqueueAndWait_P(F(
40
-        "G112\n"                            /* Home extruder */
41
-        LULZBOT_AXIS_LEVELING_COMMANDS      /* Level X axis */
42
-        "G0 X115 Z50 F6000\n"               /* Goto loading position */
43
-        "M400\n"                            /* Wait for moves to finish */
44
-        "M18 X Y"                           /* Unlock motors */
45
-      ));
39
+      SpinnerDialogBox::enqueueAndWait_P(F(LULZBOT_HOME_E_COMMANDS));
46 40
       current_screen.forget();
47 41
       break;
48 42
     case 2:

+ 1
- 4
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_confirm_home_xyz.cpp Ver fichero

@@ -36,10 +36,7 @@ void BioConfirmHomeXYZ::onRedraw(draw_mode_t) {
36 36
 bool BioConfirmHomeXYZ::onTouchEnd(uint8_t tag) {
37 37
   switch (tag) {
38 38
     case 1:
39
-      SpinnerDialogBox::enqueueAndWait_P(F(
40
-        "G28 X Y Z\n"             /* Home all axis */
41
-        "G0 X115 Z50 F6000"       /* Move to park position */
42
-      ));
39
+      SpinnerDialogBox::enqueueAndWait_P(F(LULZBOT_HOME_XYZ_COMMANDS));
43 40
       current_screen.forget();
44 41
       break;
45 42
     case 2:

+ 1
- 0
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_printing_dialog_box.cpp Ver fichero

@@ -141,6 +141,7 @@ void BioPrintingDialogBox::setStatusMessage(const char* message) {
141 141
 }
142 142
 
143 143
 void BioPrintingDialogBox::onIdle() {
144
+  reset_menu_timeout();
144 145
   if (refresh_timer.elapsed(STATUS_UPDATE_INTERVAL)) {
145 146
     onRefresh();
146 147
     refresh_timer.start();

+ 32
- 18
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_status_screen.cpp Ver fichero

@@ -37,6 +37,9 @@
37 37
 #define POLY(A) PolyUI::poly_reader_t(A, sizeof(A)/sizeof(A[0]))
38 38
 
39 39
 const uint8_t shadow_depth = 5;
40
+const float   max_speed = 0.30;
41
+const float   min_speed = 0.05;
42
+const uint8_t num_speeds = 10;
40 43
 
41 44
 using namespace FTDI;
42 45
 using namespace Theme;
@@ -248,7 +251,7 @@ void StatusScreen::onRedraw(draw_mode_t what) {
248 251
 }
249 252
 
250 253
 bool StatusScreen::onTouchStart(uint8_t) {
251
-  increment = fine_motion ? 0.25 : 1;
254
+  increment = min_speed;
252 255
   return true;
253 256
 }
254 257
 
@@ -263,6 +266,11 @@ bool StatusScreen::onTouchEnd(uint8_t tag) {
263 266
         jog_xy = true;
264 267
         injectCommands_P(PSTR("M17"));
265 268
       }
269
+      jog(0,  0,  0);
270
+      break;
271
+    case 5:
272
+    case 6:
273
+      jog(0,  0,  0);
266 274
       break;
267 275
     case 9:  GOTO_SCREEN(FilesScreen); break;
268 276
     case 10: GOTO_SCREEN(MainMenu); break;
@@ -280,25 +288,31 @@ bool StatusScreen::onTouchEnd(uint8_t tag) {
280 288
 
281 289
 bool StatusScreen::onTouchHeld(uint8_t tag) {
282 290
   if (tag >= 1 && tag <= 4 && !jog_xy) return false;
283
-  if (ExtUI::isMoving()) return false; // Don't allow moves to accumulate
284
-  #define UI_INCREMENT_AXIS(axis) MoveAxisScreen::setManualFeedrate(axis, increment); UI_INCREMENT(AxisPosition_mm, axis);
285
-  #define UI_DECREMENT_AXIS(axis) MoveAxisScreen::setManualFeedrate(axis, increment); UI_DECREMENT(AxisPosition_mm, axis);
291
+  const float s = fine_motion ? min_speed : increment;
286 292
   switch (tag) {
287
-    case 1: UI_DECREMENT_AXIS(X);  break;
288
-    case 2: UI_INCREMENT_AXIS(X);  break;
289
-    case 4: UI_DECREMENT_AXIS(Y);  break; // NOTE: Y directions inverted because bed rather than needle moves
290
-    case 3: UI_INCREMENT_AXIS(Y);  break;
291
-    case 5: UI_DECREMENT_AXIS(Z);  break;
292
-    case 6: UI_INCREMENT_AXIS(Z);  break;
293
-    case 7: UI_DECREMENT_AXIS(E0); break;
294
-    case 8: UI_INCREMENT_AXIS(E0); break;
295
-    default: return false;
293
+    case 1: jog(-s,  0,  0); break;
294
+    case 2: jog( s,  0,  0); break;
295
+    case 4: jog( 0, -s,  0); break; // NOTE: Y directions inverted because bed rather than needle moves
296
+    case 3: jog( 0,  s,  0); break;
297
+    case 5: jog( 0,  0, -s); break;
298
+    case 6: jog( 0,  0,  s); break;
299
+    case 7:
300
+      if (ExtUI::isMoving()) return false;
301
+      MoveAxisScreen::setManualFeedrate(E0, 1);
302
+      UI_INCREMENT(AxisPosition_mm, E0);
303
+      current_screen.onRefresh();
304
+      break;
305
+    case 8:
306
+      if (ExtUI::isMoving()) return false;
307
+      MoveAxisScreen::setManualFeedrate(E0, 1);
308
+      UI_DECREMENT(AxisPosition_mm, E0);
309
+      current_screen.onRefresh();
310
+      break;
311
+    default:
312
+      return false;
296 313
   }
297
-  #undef UI_DECREMENT_AXIS
298
-  #undef UI_INCREMENT_AXIS
299
-  if (increment < 10 && !fine_motion)
300
-    increment += 0.5;
301
-  current_screen.onRefresh();
314
+  if (increment < max_speed)
315
+    increment += (max_speed - min_speed) / num_speeds;
302 316
   return false;
303 317
 }
304 318
 

+ 1
- 1
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/main_menu.cpp Ver fichero

@@ -69,7 +69,7 @@ void MainMenu::onRedraw(draw_mode_t what) {
69 69
     #else
70 70
       #define GRID_ROWS 5
71 71
       #define GRID_COLS 2
72
-        .tag(2).button( BTN_POS(1,1), BTN_SIZE(1,1), GET_TEXT(AUTO_HOME))
72
+        .tag(2).button( BTN_POS(1,1), BTN_SIZE(1,1), GET_TEXTF(AUTO_HOME))
73 73
         #if ENABLED(NOZZLE_CLEAN_FEATURE)
74 74
          .enabled(1)
75 75
         #else

+ 19
- 6
Marlin/src/lcd/extensible_ui/ui_api.cpp Ver fichero

@@ -102,12 +102,16 @@
102 102
   #include "../../feature/host_actions.h"
103 103
 #endif
104 104
 
105
-static struct {
106
-  uint8_t printer_killed  : 1;
107
-  uint8_t manual_motion : 1;
108
-} flags;
109
-
110 105
 namespace ExtUI {
106
+  static struct {
107
+    uint8_t printer_killed  : 1;
108
+    uint8_t manual_motion   : 1;
109
+  } flags;
110
+
111
+  #if ENABLED(JOYSTICK)
112
+    float norm_jog[XYZ];
113
+  #endif
114
+
111 115
   #ifdef __SAM3X8E__
112 116
     /**
113 117
      * Implement a special millis() to allow time measurement
@@ -193,6 +197,14 @@ namespace ExtUI {
193 197
     #endif
194 198
   }
195 199
 
200
+  void jog(float dx, float dy, float dz) {
201
+    #if ENABLED(JOYSTICK)
202
+      norm_jog[X] = dx;
203
+      norm_jog[Y] = dy;
204
+      norm_jog[Z] = dz;
205
+    #endif
206
+  }
207
+
196 208
   bool isHeaterIdle(const extruder_t extruder) {
197 209
     return false
198 210
       #if HOTENDS && HEATER_IDLE_HANDLER
@@ -1037,9 +1049,10 @@ void MarlinUI::update() {
1037 1049
 }
1038 1050
 
1039 1051
 void MarlinUI::kill_screen(PGM_P const msg) {
1052
+  using namespace ExtUI;
1040 1053
   if (!flags.printer_killed) {
1041 1054
     flags.printer_killed = true;
1042
-    ExtUI::onPrinterKilled(msg);
1055
+    onPrinterKilled(msg);
1043 1056
   }
1044 1057
 }
1045 1058
 

+ 7
- 0
Marlin/src/lcd/extensible_ui/ui_api.h Ver fichero

@@ -45,6 +45,11 @@
45 45
 #include "../../inc/MarlinConfig.h"
46 46
 
47 47
 namespace ExtUI {
48
+
49
+  #if ENABLED(JOYSTICK)
50
+    extern float norm_jog[];
51
+  #endif
52
+
48 53
   // The ExtUI implementation can store up to this many bytes
49 54
   // in the EEPROM when the methods onStoreSettings and
50 55
   // onLoadSettings are called.
@@ -79,6 +84,8 @@ namespace ExtUI {
79 84
   void enableHeater(const heater_t);
80 85
   void enableHeater(const extruder_t);
81 86
 
87
+  void jog(float dx, float dy, float dz);
88
+
82 89
   /**
83 90
    * Getters and setters
84 91
    * Should be used by the EXTENSIBLE_UI to query or change Marlin's state.

Loading…
Cancelar
Guardar