Browse Source

EXTENSIBLE_UI Joystick support (#15303)

Marcio Teixeira 5 years ago
parent
commit
7f117bfc60

+ 46
- 30
Marlin/src/feature/joystick.cpp View File

36
 
36
 
37
 Joystick joystick;
37
 Joystick joystick;
38
 
38
 
39
+#if ENABLED(EXTENSIBLE_UI)
40
+  #include "../lcd/extensible_ui/ui_api.h"
41
+#endif
42
+
39
 #if HAS_JOY_ADC_X
43
 #if HAS_JOY_ADC_X
40
   temp_info_t Joystick::x; // = { 0 }
44
   temp_info_t Joystick::x; // = { 0 }
41
 #endif
45
 #endif
65
   }
69
   }
66
 #endif
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
 #if ENABLED(POLL_JOG)
106
 #if ENABLED(POLL_JOG)
99
 
107
 
122
     float norm_jog[XYZ] = { 0 };
130
     float norm_jog[XYZ] = { 0 };
123
 
131
 
124
     // Use ADC values and defined limits. The active zone is normalized: -1..0 (dead) 0..1
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
     // Other non-joystick poll-based jogging could be implemented here
137
     // Other non-joystick poll-based jogging could be implemented here
128
     // with "jogging" encapsulated as a more general class.
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
     // Jogging value maps continuously (quadratic relationship) to feedrate
146
     // Jogging value maps continuously (quadratic relationship) to feedrate
131
     float move_dist[XYZ] = { 0 }, hypot2 = 0;
147
     float move_dist[XYZ] = { 0 }, hypot2 = 0;
132
     LOOP_XYZ(i) if (norm_jog[i]) {
148
     LOOP_XYZ(i) if (norm_jog[i]) {

+ 1
- 1
Marlin/src/feature/joystick.h View File

46
     #if ENABLED(JOYSTICK_DEBUG)
46
     #if ENABLED(JOYSTICK_DEBUG)
47
       static void report();
47
       static void report();
48
     #endif
48
     #endif
49
-    static void calculate(float norm_jog[XYZ]);
49
+    static void calculate(float (&norm_jog)[XYZ]);
50
     static void inject_jog_moves();
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 View File

156
         if (!UIData::flags.bits.touch_debouncing) {
156
         if (!UIData::flags.bits.touch_debouncing) {
157
           if (tag == pressed_tag) {
157
           if (tag == pressed_tag) {
158
             // The user is holding down a button.
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
               touch_timer.start();
164
               touch_timer.start();
163
             }
165
             }
164
           }
166
           }

+ 1
- 7
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_confirm_home_e.cpp View File

36
 bool BioConfirmHomeE::onTouchEnd(uint8_t tag) {
36
 bool BioConfirmHomeE::onTouchEnd(uint8_t tag) {
37
   switch (tag) {
37
   switch (tag) {
38
     case 1:
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
       current_screen.forget();
40
       current_screen.forget();
47
       break;
41
       break;
48
     case 2:
42
     case 2:

+ 1
- 4
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_confirm_home_xyz.cpp View File

36
 bool BioConfirmHomeXYZ::onTouchEnd(uint8_t tag) {
36
 bool BioConfirmHomeXYZ::onTouchEnd(uint8_t tag) {
37
   switch (tag) {
37
   switch (tag) {
38
     case 1:
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
       current_screen.forget();
40
       current_screen.forget();
44
       break;
41
       break;
45
     case 2:
42
     case 2:

+ 1
- 0
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_printing_dialog_box.cpp View File

141
 }
141
 }
142
 
142
 
143
 void BioPrintingDialogBox::onIdle() {
143
 void BioPrintingDialogBox::onIdle() {
144
+  reset_menu_timeout();
144
   if (refresh_timer.elapsed(STATUS_UPDATE_INTERVAL)) {
145
   if (refresh_timer.elapsed(STATUS_UPDATE_INTERVAL)) {
145
     onRefresh();
146
     onRefresh();
146
     refresh_timer.start();
147
     refresh_timer.start();

+ 32
- 18
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_status_screen.cpp View File

37
 #define POLY(A) PolyUI::poly_reader_t(A, sizeof(A)/sizeof(A[0]))
37
 #define POLY(A) PolyUI::poly_reader_t(A, sizeof(A)/sizeof(A[0]))
38
 
38
 
39
 const uint8_t shadow_depth = 5;
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
 using namespace FTDI;
44
 using namespace FTDI;
42
 using namespace Theme;
45
 using namespace Theme;
248
 }
251
 }
249
 
252
 
250
 bool StatusScreen::onTouchStart(uint8_t) {
253
 bool StatusScreen::onTouchStart(uint8_t) {
251
-  increment = fine_motion ? 0.25 : 1;
254
+  increment = min_speed;
252
   return true;
255
   return true;
253
 }
256
 }
254
 
257
 
263
         jog_xy = true;
266
         jog_xy = true;
264
         injectCommands_P(PSTR("M17"));
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
       break;
274
       break;
267
     case 9:  GOTO_SCREEN(FilesScreen); break;
275
     case 9:  GOTO_SCREEN(FilesScreen); break;
268
     case 10: GOTO_SCREEN(MainMenu); break;
276
     case 10: GOTO_SCREEN(MainMenu); break;
280
 
288
 
281
 bool StatusScreen::onTouchHeld(uint8_t tag) {
289
 bool StatusScreen::onTouchHeld(uint8_t tag) {
282
   if (tag >= 1 && tag <= 4 && !jog_xy) return false;
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
   switch (tag) {
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
   return false;
316
   return false;
303
 }
317
 }
304
 
318
 

+ 1
- 1
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/main_menu.cpp View File

69
     #else
69
     #else
70
       #define GRID_ROWS 5
70
       #define GRID_ROWS 5
71
       #define GRID_COLS 2
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
         #if ENABLED(NOZZLE_CLEAN_FEATURE)
73
         #if ENABLED(NOZZLE_CLEAN_FEATURE)
74
          .enabled(1)
74
          .enabled(1)
75
         #else
75
         #else

+ 19
- 6
Marlin/src/lcd/extensible_ui/ui_api.cpp View File

102
   #include "../../feature/host_actions.h"
102
   #include "../../feature/host_actions.h"
103
 #endif
103
 #endif
104
 
104
 
105
-static struct {
106
-  uint8_t printer_killed  : 1;
107
-  uint8_t manual_motion : 1;
108
-} flags;
109
-
110
 namespace ExtUI {
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
   #ifdef __SAM3X8E__
115
   #ifdef __SAM3X8E__
112
     /**
116
     /**
113
      * Implement a special millis() to allow time measurement
117
      * Implement a special millis() to allow time measurement
193
     #endif
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
   bool isHeaterIdle(const extruder_t extruder) {
208
   bool isHeaterIdle(const extruder_t extruder) {
197
     return false
209
     return false
198
       #if HOTENDS && HEATER_IDLE_HANDLER
210
       #if HOTENDS && HEATER_IDLE_HANDLER
1037
 }
1049
 }
1038
 
1050
 
1039
 void MarlinUI::kill_screen(PGM_P const msg) {
1051
 void MarlinUI::kill_screen(PGM_P const msg) {
1052
+  using namespace ExtUI;
1040
   if (!flags.printer_killed) {
1053
   if (!flags.printer_killed) {
1041
     flags.printer_killed = true;
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 View File

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

Loading…
Cancel
Save