Skip to content

Commit cf2b453

Browse files
InsanityAutomationthinkyhead
authored andcommitted
🎨 ExtUI "user click" and other tweaks (MarlinFirmware#22122)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 640e557 commit cf2b453

File tree

8 files changed

+123
-101
lines changed

8 files changed

+123
-101
lines changed

Marlin/src/gcode/bedlevel/mbl/G29.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void GcodeSuite::G29() {
7070
return;
7171
}
7272

73-
int8_t ix, iy;
73+
int8_t ix, iy = 0;
7474

7575
switch (state) {
7676
case MeshReport:
@@ -88,6 +88,7 @@ void GcodeSuite::G29() {
8888
mbl_probe_index = 0;
8989
if (!ui.wait_for_move) {
9090
queue.inject_P(parser.seen_test('N') ? PSTR("G28" TERN(CAN_SET_LEVELING_AFTER_G28, "L0", "") "\nG29S2") : PSTR("G29S2"));
91+
TERN_(EXTENSIBLE_UI, ExtUI::onMeshLevelingStart());
9192
return;
9293
}
9394
state = MeshNext;
@@ -109,6 +110,7 @@ void GcodeSuite::G29() {
109110
else {
110111
// Save Z for the previous mesh position
111112
mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
113+
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, current_position.z));
112114
SET_SOFT_ENDSTOP_LOOSE(false);
113115
}
114116
// If there's another point to sample, move there with optional lift.

Marlin/src/lcd/extui/ui_api.cpp

+93-83
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
#include "../marlinui.h"
4949
#include "../../gcode/queue.h"
50+
#include "../../gcode/gcode.h"
5051
#include "../../module/motion.h"
5152
#include "../../module/planner.h"
5253
#include "../../module/probe.h"
@@ -353,14 +354,9 @@ namespace ExtUI {
353354

354355
extruder_t getTool(const uint8_t extruder) {
355356
switch (extruder) {
356-
case 7: return E7;
357-
case 6: return E6;
358-
case 5: return E5;
359-
case 4: return E4;
360-
case 3: return E3;
361-
case 2: return E2;
362-
case 1: return E1;
363-
default: return E0;
357+
default:
358+
case 0: return E0; case 1: return E1; case 2: return E2; case 3: return E3;
359+
case 4: return E4; case 5: return E5; case 6: return E6; case 7: return E7;
364360
}
365361
}
366362

@@ -372,8 +368,8 @@ namespace ExtUI {
372368
switch (axis) {
373369
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
374370
case X: return axis_should_home(X_AXIS);
375-
case Y: return axis_should_home(Y_AXIS);
376-
case Z: return axis_should_home(Z_AXIS);
371+
OPTCODE(HAS_Y_AXIS, case Y: return axis_should_home(Y_AXIS))
372+
OPTCODE(HAS_Z_AXIS, case Z: return axis_should_home(Z_AXIS))
377373
#else
378374
case X: case Y: case Z: return true;
379375
#endif
@@ -385,6 +381,8 @@ namespace ExtUI {
385381
return !thermalManager.tooColdToExtrude(extruder - E0);
386382
}
387383

384+
GcodeSuite::MarlinBusyState getMachineBusyState() { return TERN0(HOST_KEEPALIVE_FEATURE, GcodeSuite::busy_state); }
385+
388386
#if HAS_SOFTWARE_ENDSTOPS
389387
bool getSoftEndstopState() { return soft_endstop._enabled; }
390388
void setSoftEndstopState(const bool value) { soft_endstop._enabled = value; }
@@ -396,18 +394,27 @@ namespace ExtUI {
396394
#if AXIS_IS_TMC(X)
397395
case X: return stepperX.getMilliamps();
398396
#endif
399-
#if AXIS_IS_TMC(X2)
400-
case X2: return stepperX2.getMilliamps();
401-
#endif
402397
#if AXIS_IS_TMC(Y)
403398
case Y: return stepperY.getMilliamps();
404399
#endif
405-
#if AXIS_IS_TMC(Y2)
406-
case Y2: return stepperY2.getMilliamps();
407-
#endif
408400
#if AXIS_IS_TMC(Z)
409401
case Z: return stepperZ.getMilliamps();
410402
#endif
403+
#if AXIS_IS_TMC(I)
404+
case I: return stepperI.getMilliamps();
405+
#endif
406+
#if AXIS_IS_TMC(J)
407+
case J: return stepperJ.getMilliamps();
408+
#endif
409+
#if AXIS_IS_TMC(K)
410+
case K: return stepperK.getMilliamps();
411+
#endif
412+
#if AXIS_IS_TMC(X2)
413+
case X2: return stepperX2.getMilliamps();
414+
#endif
415+
#if AXIS_IS_TMC(Y2)
416+
case Y2: return stepperY2.getMilliamps();
417+
#endif
411418
#if AXIS_IS_TMC(Z2)
412419
case Z2: return stepperZ2.getMilliamps();
413420
#endif
@@ -450,18 +457,27 @@ namespace ExtUI {
450457
#if AXIS_IS_TMC(X)
451458
case X: stepperX.rms_current(constrain(mA, 400, 1500)); break;
452459
#endif
453-
#if AXIS_IS_TMC(X2)
454-
case X2: stepperX2.rms_current(constrain(mA, 400, 1500)); break;
455-
#endif
456460
#if AXIS_IS_TMC(Y)
457461
case Y: stepperY.rms_current(constrain(mA, 400, 1500)); break;
458462
#endif
459-
#if AXIS_IS_TMC(Y2)
460-
case Y2: stepperY2.rms_current(constrain(mA, 400, 1500)); break;
461-
#endif
462463
#if AXIS_IS_TMC(Z)
463464
case Z: stepperZ.rms_current(constrain(mA, 400, 1500)); break;
464465
#endif
466+
#if AXIS_IS_TMC(I)
467+
case I: stepperI.rms_current(constrain(mA, 400, 1500)); break;
468+
#endif
469+
#if AXIS_IS_TMC(J)
470+
case J: stepperJ.rms_current(constrain(mA, 400, 1500)); break;
471+
#endif
472+
#if AXIS_IS_TMC(K)
473+
case K: stepperK.rms_current(constrain(mA, 400, 1500)); break;
474+
#endif
475+
#if AXIS_IS_TMC(X2)
476+
case X2: stepperX2.rms_current(constrain(mA, 400, 1500)); break;
477+
#endif
478+
#if AXIS_IS_TMC(Y2)
479+
case Y2: stepperY2.rms_current(constrain(mA, 400, 1500)); break;
480+
#endif
465481
#if AXIS_IS_TMC(Z2)
466482
case Z2: stepperZ2.rms_current(constrain(mA, 400, 1500)); break;
467483
#endif
@@ -501,66 +517,59 @@ namespace ExtUI {
501517

502518
int getTMCBumpSensitivity(const axis_t axis) {
503519
switch (axis) {
504-
#if ENABLED(X_SENSORLESS)
505-
case X: return stepperX.homing_threshold();
520+
OPTCODE(X_SENSORLESS, case X: return stepperX.homing_threshold())
521+
OPTCODE(Y_SENSORLESS, case Y: return stepperY.homing_threshold())
522+
OPTCODE(Z_SENSORLESS, case Z: return stepperZ.homing_threshold())
523+
OPTCODE(I_SENSORLESS, case I: return stepperI.homing_threshold())
524+
OPTCODE(J_SENSORLESS, case J: return stepperJ.homing_threshold())
525+
OPTCODE(K_SENSORLESS, case K: return stepperK.homing_threshold())
526+
OPTCODE(X2_SENSORLESS, case X2: return stepperX2.homing_threshold())
527+
OPTCODE(Y2_SENSORLESS, case Y2: return stepperY2.homing_threshold())
528+
OPTCODE(Z2_SENSORLESS, case Z2: return stepperZ2.homing_threshold())
529+
OPTCODE(Z3_SENSORLESS, case Z3: return stepperZ3.homing_threshold())
530+
OPTCODE(Z4_SENSORLESS, case Z4: return stepperZ4.homing_threshold())
531+
default: return 0;
532+
}
533+
}
534+
535+
void setTMCBumpSensitivity(const_float_t value, const axis_t axis) {
536+
switch (axis) {
537+
#if X_SENSORLESS
538+
case X: stepperX.homing_threshold(value); break;
506539
#endif
507-
#if ENABLED(X2_SENSORLESS)
508-
case X2: return stepperX2.homing_threshold();
540+
#if Y_SENSORLESS
541+
case Y: stepperY.homing_threshold(value); break;
509542
#endif
510-
#if ENABLED(Y_SENSORLESS)
511-
case Y: return stepperY.homing_threshold();
543+
#if Z_SENSORLESS
544+
case Z: stepperZ.homing_threshold(value); break;
512545
#endif
513-
#if ENABLED(Y2_SENSORLESS)
514-
case Y2: return stepperY2.homing_threshold();
546+
#if I_SENSORLESS
547+
case I: stepperI.homing_threshold(value); break;
515548
#endif
516-
#if ENABLED(Z_SENSORLESS)
517-
case Z: return stepperZ.homing_threshold();
549+
#if J_SENSORLESS
550+
case J: stepperJ.homing_threshold(value); break;
518551
#endif
519-
#if ENABLED(Z2_SENSORLESS)
520-
case Z2: return stepperZ2.homing_threshold();
552+
#if K_SENSORLESS
553+
case K: stepperK.homing_threshold(value); break;
521554
#endif
522-
#if ENABLED(Z3_SENSORLESS)
523-
case Z3: return stepperZ3.homing_threshold();
555+
#if X2_SENSORLESS
556+
case X2: stepperX2.homing_threshold(value); break;
524557
#endif
525-
#if ENABLED(Z4_SENSORLESS)
526-
case Z4: return stepperZ4.homing_threshold();
558+
#if Y2_SENSORLESS
559+
case Y2: stepperY2.homing_threshold(value); break;
527560
#endif
528-
default: return 0;
529-
}
530-
}
531-
532-
void setTMCBumpSensitivity(const_float_t value, const axis_t axis) {
533-
switch (axis) {
534-
#if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS
535-
#if X_SENSORLESS
536-
case X: stepperX.homing_threshold(value); break;
537-
#endif
538-
#if X2_SENSORLESS
539-
case X2: stepperX2.homing_threshold(value); break;
540-
#endif
541-
#if Y_SENSORLESS
542-
case Y: stepperY.homing_threshold(value); break;
543-
#endif
544-
#if Y2_SENSORLESS
545-
case Y2: stepperY2.homing_threshold(value); break;
546-
#endif
547-
#if Z_SENSORLESS
548-
case Z: stepperZ.homing_threshold(value); break;
549-
#endif
550-
#if Z2_SENSORLESS
551-
case Z2: stepperZ2.homing_threshold(value); break;
552-
#endif
553-
#if Z3_SENSORLESS
554-
case Z3: stepperZ3.homing_threshold(value); break;
555-
#endif
556-
#if Z4_SENSORLESS
557-
case Z4: stepperZ4.homing_threshold(value); break;
558-
#endif
559-
#else
560-
UNUSED(value);
561+
#if Z2_SENSORLESS
562+
case Z2: stepperZ2.homing_threshold(value); break;
563+
#endif
564+
#if Z3_SENSORLESS
565+
case Z3: stepperZ3.homing_threshold(value); break;
566+
#endif
567+
#if Z4_SENSORLESS
568+
case Z4: stepperZ4.homing_threshold(value); break;
561569
#endif
562570
default: break;
563571
}
572+
UNUSED(value);
564573
}
565574
#endif
566575

@@ -661,9 +670,7 @@ namespace ExtUI {
661670

662671
#if HAS_JUNCTION_DEVIATION
663672

664-
float getJunctionDeviation_mm() {
665-
return planner.junction_deviation_mm;
666-
}
673+
float getJunctionDeviation_mm() { return planner.junction_deviation_mm; }
667674

668675
void setJunctionDeviation_mm(const_float_t value) {
669676
planner.junction_deviation_mm = constrain(value, 0.001, 0.3);
@@ -682,7 +689,7 @@ namespace ExtUI {
682689
#endif
683690

684691
#if PREHEAT_COUNT
685-
uint16_t getMaterial_preset_E(const uint16_t index) { return ui.material_preset[index].hotend_temp; }
692+
uint16_t getMaterial_preset_E(const uint16_t index) { return ui.material_preset[index].hotend_temp; }
686693
#if HAS_HEATED_BED
687694
uint16_t getMaterial_preset_B(const uint16_t index) { return ui.material_preset[index].bed_temp; }
688695
#endif
@@ -709,9 +716,13 @@ namespace ExtUI {
709716
switch (axis) {
710717
#if ENABLED(BABYSTEP_XY)
711718
case X: babystep.add_steps(X_AXIS, steps); break;
712-
case Y: babystep.add_steps(Y_AXIS, steps); break;
719+
#if HAS_Y_AXIS
720+
case Y: babystep.add_steps(Y_AXIS, steps); break;
721+
#endif
722+
#endif
723+
#if HAS_Z_AXIS
724+
case Z: babystep.add_steps(Z_AXIS, steps); break;
713725
#endif
714-
case Z: babystep.add_steps(Z_AXIS, steps); break;
715726
default: return false;
716727
};
717728
return true;
@@ -750,8 +761,8 @@ namespace ExtUI {
750761
hotend_offset[e][axis] += mm;
751762

752763
normalizeNozzleOffset(X);
753-
normalizeNozzleOffset(Y);
754-
normalizeNozzleOffset(Z);
764+
TERN_(HAS_Y_AXIS, normalizeNozzleOffset(Y));
765+
TERN_(HAS_Z_AXIS, normalizeNozzleOffset(Z));
755766
}
756767
#else
757768
UNUSED(linked_nozzles);
@@ -1014,8 +1025,7 @@ namespace ExtUI {
10141025
TERN_(HAS_FAN, thermalManager.zero_fan_speeds());
10151026
}
10161027

1017-
bool awaitingUserConfirm() { return wait_for_user; }
1018-
1028+
bool awaitingUserConfirm() { return TERN0(HAS_RESUME_CONTINUE, wait_for_user); }
10191029
void setUserConfirmed() { TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); }
10201030

10211031
void printFile(const char *filename) {
@@ -1038,9 +1048,9 @@ namespace ExtUI {
10381048

10391049
bool isMediaInserted() { return TERN0(SDSUPPORT, IS_SD_INSERTED() && card.isMounted()); }
10401050

1041-
void pausePrint() { ui.pause_print(); }
1051+
void pausePrint() { ui.pause_print(); }
10421052
void resumePrint() { ui.resume_print(); }
1043-
void stopPrint() { ui.abort_print(); }
1053+
void stopPrint() { ui.abort_print(); }
10441054

10451055
void onUserConfirmRequired_P(PGM_P const pstr) {
10461056
char msg[strlen_P(pstr) + 1];

Marlin/src/lcd/extui/ui_api.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#include "../../inc/MarlinConfig.h"
4646
#include "../marlinui.h"
47+
#include "../../gcode/gcode.h"
4748

4849
namespace ExtUI {
4950

@@ -53,7 +54,7 @@ namespace ExtUI {
5354

5455
static constexpr size_t eeprom_data_size = 48;
5556

56-
enum axis_t : uint8_t { X, Y, Z, X2, Y2, Z2, Z3, Z4 };
57+
enum axis_t : uint8_t { X, Y, Z, I, J, K, X2, Y2, Z2, Z3, Z4 };
5758
enum extruder_t : uint8_t { E0, E1, E2, E3, E4, E5, E6, E7 };
5859
enum heater_t : uint8_t { H0, H1, H2, H3, H4, H5, BED, CHAMBER, COOLER };
5960
enum fan_t : uint8_t { FAN0, FAN1, FAN2, FAN3, FAN4, FAN5, FAN6, FAN7 };
@@ -78,6 +79,8 @@ namespace ExtUI {
7879
void injectCommands(char * const);
7980
bool commandsInQueue();
8081

82+
GcodeSuite::MarlinBusyState getMachineBusyState();
83+
8184
bool isHeaterIdle(const heater_t);
8285
bool isHeaterIdle(const extruder_t);
8386
void enableHeater(const heater_t);
@@ -125,6 +128,7 @@ namespace ExtUI {
125128
float getAxisMaxAcceleration_mm_s2(const extruder_t);
126129
feedRate_t getMinFeedrate_mm_s();
127130
feedRate_t getMinTravelFeedrate_mm_s();
131+
feedRate_t getFeedrate_mm_s();
128132
float getPrintingAcceleration_mm_s2();
129133
float getRetractAcceleration_mm_s2();
130134
float getTravelAcceleration_mm_s2();
@@ -186,6 +190,8 @@ namespace ExtUI {
186190
void setHostResponse(const uint8_t);
187191
#endif
188192

193+
inline void simulateUserClick() { ui.lcd_clicked = true; }
194+
189195
#if ENABLED(PRINTCOUNTER)
190196
char* getFailedPrints_str(char buffer[21]);
191197
char* getTotalPrints_str(char buffer[21]);

Marlin/src/lcd/marlinui.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ millis_t MarlinUI::next_button_update_ms; // = 0
223223

224224
#endif
225225

226+
#if EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
227+
bool MarlinUI::lcd_clicked;
228+
#endif
229+
226230
#if HAS_LCD_MENU
227231
#include "menu/menu.h"
228232

@@ -247,14 +251,6 @@ millis_t MarlinUI::next_button_update_ms; // = 0
247251
uint8_t MarlinUI::repeat_delay;
248252
#endif
249253

250-
bool MarlinUI::lcd_clicked;
251-
252-
bool MarlinUI::use_click() {
253-
const bool click = lcd_clicked;
254-
lcd_clicked = false;
255-
return click;
256-
}
257-
258254
#if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
259255

260256
bool MarlinUI::external_control; // = false

0 commit comments

Comments
 (0)