Skip to content

Commit

Permalink
馃帹 ExtUI "user click" and other tweaks (MarlinFirmware#22122)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
InsanityAutomation and thinkyhead committed Jun 15, 2021
1 parent 5635515 commit d84e2d6
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 101 deletions.
4 changes: 3 additions & 1 deletion Marlin/src/gcode/bedlevel/mbl/G29.cpp
Expand Up @@ -70,7 +70,7 @@ void GcodeSuite::G29() {
return;
}

int8_t ix, iy;
int8_t ix, iy = 0;

switch (state) {
case MeshReport:
Expand All @@ -88,6 +88,7 @@ void GcodeSuite::G29() {
mbl_probe_index = 0;
if (!ui.wait_for_move) {
queue.inject_P(parser.seen_test('N') ? PSTR("G28" TERN(CAN_SET_LEVELING_AFTER_G28, "L0", "") "\nG29S2") : PSTR("G29S2"));
TERN_(EXTENSIBLE_UI, ExtUI::onMeshLevelingStart());
return;
}
state = MeshNext;
Expand All @@ -109,6 +110,7 @@ void GcodeSuite::G29() {
else {
// Save Z for the previous mesh position
mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, current_position.z));
SET_SOFT_ENDSTOP_LOOSE(false);
}
// If there's another point to sample, move there with optional lift.
Expand Down
176 changes: 93 additions & 83 deletions Marlin/src/lcd/extui/ui_api.cpp
Expand Up @@ -47,6 +47,7 @@

#include "../marlinui.h"
#include "../../gcode/queue.h"
#include "../../gcode/gcode.h"
#include "../../module/motion.h"
#include "../../module/planner.h"
#include "../../module/probe.h"
Expand Down Expand Up @@ -353,14 +354,9 @@ namespace ExtUI {

extruder_t getTool(const uint8_t extruder) {
switch (extruder) {
case 7: return E7;
case 6: return E6;
case 5: return E5;
case 4: return E4;
case 3: return E3;
case 2: return E2;
case 1: return E1;
default: return E0;
default:
case 0: return E0; case 1: return E1; case 2: return E2; case 3: return E3;
case 4: return E4; case 5: return E5; case 6: return E6; case 7: return E7;
}
}

Expand All @@ -372,8 +368,8 @@ namespace ExtUI {
switch (axis) {
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
case X: return axis_should_home(X_AXIS);
case Y: return axis_should_home(Y_AXIS);
case Z: return axis_should_home(Z_AXIS);
OPTCODE(HAS_Y_AXIS, case Y: return axis_should_home(Y_AXIS))
OPTCODE(HAS_Z_AXIS, case Z: return axis_should_home(Z_AXIS))
#else
case X: case Y: case Z: return true;
#endif
Expand All @@ -385,6 +381,8 @@ namespace ExtUI {
return !thermalManager.tooColdToExtrude(extruder - E0);
}

GcodeSuite::MarlinBusyState getMachineBusyState() { return TERN0(HOST_KEEPALIVE_FEATURE, GcodeSuite::busy_state); }

#if HAS_SOFTWARE_ENDSTOPS
bool getSoftEndstopState() { return soft_endstop._enabled; }
void setSoftEndstopState(const bool value) { soft_endstop._enabled = value; }
Expand All @@ -396,18 +394,27 @@ namespace ExtUI {
#if AXIS_IS_TMC(X)
case X: return stepperX.getMilliamps();
#endif
#if AXIS_IS_TMC(X2)
case X2: return stepperX2.getMilliamps();
#endif
#if AXIS_IS_TMC(Y)
case Y: return stepperY.getMilliamps();
#endif
#if AXIS_IS_TMC(Y2)
case Y2: return stepperY2.getMilliamps();
#endif
#if AXIS_IS_TMC(Z)
case Z: return stepperZ.getMilliamps();
#endif
#if AXIS_IS_TMC(I)
case I: return stepperI.getMilliamps();
#endif
#if AXIS_IS_TMC(J)
case J: return stepperJ.getMilliamps();
#endif
#if AXIS_IS_TMC(K)
case K: return stepperK.getMilliamps();
#endif
#if AXIS_IS_TMC(X2)
case X2: return stepperX2.getMilliamps();
#endif
#if AXIS_IS_TMC(Y2)
case Y2: return stepperY2.getMilliamps();
#endif
#if AXIS_IS_TMC(Z2)
case Z2: return stepperZ2.getMilliamps();
#endif
Expand Down Expand Up @@ -450,18 +457,27 @@ namespace ExtUI {
#if AXIS_IS_TMC(X)
case X: stepperX.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(X2)
case X2: stepperX2.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(Y)
case Y: stepperY.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(Y2)
case Y2: stepperY2.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(Z)
case Z: stepperZ.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(I)
case I: stepperI.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(J)
case J: stepperJ.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(K)
case K: stepperK.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(X2)
case X2: stepperX2.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(Y2)
case Y2: stepperY2.rms_current(constrain(mA, 400, 1500)); break;
#endif
#if AXIS_IS_TMC(Z2)
case Z2: stepperZ2.rms_current(constrain(mA, 400, 1500)); break;
#endif
Expand Down Expand Up @@ -501,66 +517,59 @@ namespace ExtUI {

int getTMCBumpSensitivity(const axis_t axis) {
switch (axis) {
#if ENABLED(X_SENSORLESS)
case X: return stepperX.homing_threshold();
OPTCODE(X_SENSORLESS, case X: return stepperX.homing_threshold())
OPTCODE(Y_SENSORLESS, case Y: return stepperY.homing_threshold())
OPTCODE(Z_SENSORLESS, case Z: return stepperZ.homing_threshold())
OPTCODE(I_SENSORLESS, case I: return stepperI.homing_threshold())
OPTCODE(J_SENSORLESS, case J: return stepperJ.homing_threshold())
OPTCODE(K_SENSORLESS, case K: return stepperK.homing_threshold())
OPTCODE(X2_SENSORLESS, case X2: return stepperX2.homing_threshold())
OPTCODE(Y2_SENSORLESS, case Y2: return stepperY2.homing_threshold())
OPTCODE(Z2_SENSORLESS, case Z2: return stepperZ2.homing_threshold())
OPTCODE(Z3_SENSORLESS, case Z3: return stepperZ3.homing_threshold())
OPTCODE(Z4_SENSORLESS, case Z4: return stepperZ4.homing_threshold())
default: return 0;
}
}

void setTMCBumpSensitivity(const_float_t value, const axis_t axis) {
switch (axis) {
#if X_SENSORLESS
case X: stepperX.homing_threshold(value); break;
#endif
#if ENABLED(X2_SENSORLESS)
case X2: return stepperX2.homing_threshold();
#if Y_SENSORLESS
case Y: stepperY.homing_threshold(value); break;
#endif
#if ENABLED(Y_SENSORLESS)
case Y: return stepperY.homing_threshold();
#if Z_SENSORLESS
case Z: stepperZ.homing_threshold(value); break;
#endif
#if ENABLED(Y2_SENSORLESS)
case Y2: return stepperY2.homing_threshold();
#if I_SENSORLESS
case I: stepperI.homing_threshold(value); break;
#endif
#if ENABLED(Z_SENSORLESS)
case Z: return stepperZ.homing_threshold();
#if J_SENSORLESS
case J: stepperJ.homing_threshold(value); break;
#endif
#if ENABLED(Z2_SENSORLESS)
case Z2: return stepperZ2.homing_threshold();
#if K_SENSORLESS
case K: stepperK.homing_threshold(value); break;
#endif
#if ENABLED(Z3_SENSORLESS)
case Z3: return stepperZ3.homing_threshold();
#if X2_SENSORLESS
case X2: stepperX2.homing_threshold(value); break;
#endif
#if ENABLED(Z4_SENSORLESS)
case Z4: return stepperZ4.homing_threshold();
#if Y2_SENSORLESS
case Y2: stepperY2.homing_threshold(value); break;
#endif
default: return 0;
}
}

void setTMCBumpSensitivity(const_float_t value, const axis_t axis) {
switch (axis) {
#if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS
#if X_SENSORLESS
case X: stepperX.homing_threshold(value); break;
#endif
#if X2_SENSORLESS
case X2: stepperX2.homing_threshold(value); break;
#endif
#if Y_SENSORLESS
case Y: stepperY.homing_threshold(value); break;
#endif
#if Y2_SENSORLESS
case Y2: stepperY2.homing_threshold(value); break;
#endif
#if Z_SENSORLESS
case Z: stepperZ.homing_threshold(value); break;
#endif
#if Z2_SENSORLESS
case Z2: stepperZ2.homing_threshold(value); break;
#endif
#if Z3_SENSORLESS
case Z3: stepperZ3.homing_threshold(value); break;
#endif
#if Z4_SENSORLESS
case Z4: stepperZ4.homing_threshold(value); break;
#endif
#else
UNUSED(value);
#if Z2_SENSORLESS
case Z2: stepperZ2.homing_threshold(value); break;
#endif
#if Z3_SENSORLESS
case Z3: stepperZ3.homing_threshold(value); break;
#endif
#if Z4_SENSORLESS
case Z4: stepperZ4.homing_threshold(value); break;
#endif
default: break;
}
UNUSED(value);
}
#endif

Expand Down Expand Up @@ -661,9 +670,7 @@ namespace ExtUI {

#if HAS_JUNCTION_DEVIATION

float getJunctionDeviation_mm() {
return planner.junction_deviation_mm;
}
float getJunctionDeviation_mm() { return planner.junction_deviation_mm; }

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

#if PREHEAT_COUNT
uint16_t getMaterial_preset_E(const uint16_t index) { return ui.material_preset[index].hotend_temp; }
uint16_t getMaterial_preset_E(const uint16_t index) { return ui.material_preset[index].hotend_temp; }
#if HAS_HEATED_BED
uint16_t getMaterial_preset_B(const uint16_t index) { return ui.material_preset[index].bed_temp; }
#endif
Expand All @@ -709,9 +716,13 @@ namespace ExtUI {
switch (axis) {
#if ENABLED(BABYSTEP_XY)
case X: babystep.add_steps(X_AXIS, steps); break;
case Y: babystep.add_steps(Y_AXIS, steps); break;
#if HAS_Y_AXIS
case Y: babystep.add_steps(Y_AXIS, steps); break;
#endif
#endif
#if HAS_Z_AXIS
case Z: babystep.add_steps(Z_AXIS, steps); break;
#endif
case Z: babystep.add_steps(Z_AXIS, steps); break;
default: return false;
};
return true;
Expand Down Expand Up @@ -750,8 +761,8 @@ namespace ExtUI {
hotend_offset[e][axis] += mm;

normalizeNozzleOffset(X);
normalizeNozzleOffset(Y);
normalizeNozzleOffset(Z);
TERN_(HAS_Y_AXIS, normalizeNozzleOffset(Y));
TERN_(HAS_Z_AXIS, normalizeNozzleOffset(Z));
}
#else
UNUSED(linked_nozzles);
Expand Down Expand Up @@ -1014,8 +1025,7 @@ namespace ExtUI {
TERN_(HAS_FAN, thermalManager.zero_fan_speeds());
}

bool awaitingUserConfirm() { return wait_for_user; }

bool awaitingUserConfirm() { return TERN0(HAS_RESUME_CONTINUE, wait_for_user); }
void setUserConfirmed() { TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); }

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

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

void pausePrint() { ui.pause_print(); }
void pausePrint() { ui.pause_print(); }
void resumePrint() { ui.resume_print(); }
void stopPrint() { ui.abort_print(); }
void stopPrint() { ui.abort_print(); }

void onUserConfirmRequired_P(PGM_P const pstr) {
char msg[strlen_P(pstr) + 1];
Expand Down
8 changes: 7 additions & 1 deletion Marlin/src/lcd/extui/ui_api.h
Expand Up @@ -44,6 +44,7 @@

#include "../../inc/MarlinConfig.h"
#include "../marlinui.h"
#include "../../gcode/gcode.h"

namespace ExtUI {

Expand All @@ -53,7 +54,7 @@ namespace ExtUI {

static constexpr size_t eeprom_data_size = 48;

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

GcodeSuite::MarlinBusyState getMachineBusyState();

bool isHeaterIdle(const heater_t);
bool isHeaterIdle(const extruder_t);
void enableHeater(const heater_t);
Expand Down Expand Up @@ -125,6 +128,7 @@ namespace ExtUI {
float getAxisMaxAcceleration_mm_s2(const extruder_t);
feedRate_t getMinFeedrate_mm_s();
feedRate_t getMinTravelFeedrate_mm_s();
feedRate_t getFeedrate_mm_s();
float getPrintingAcceleration_mm_s2();
float getRetractAcceleration_mm_s2();
float getTravelAcceleration_mm_s2();
Expand Down Expand Up @@ -186,6 +190,8 @@ namespace ExtUI {
void setHostResponse(const uint8_t);
#endif

inline void simulateUserClick() { ui.lcd_clicked = true; }

#if ENABLED(PRINTCOUNTER)
char* getFailedPrints_str(char buffer[21]);
char* getTotalPrints_str(char buffer[21]);
Expand Down
12 changes: 4 additions & 8 deletions Marlin/src/lcd/marlinui.cpp
Expand Up @@ -223,6 +223,10 @@ millis_t MarlinUI::next_button_update_ms; // = 0

#endif

#if EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
bool MarlinUI::lcd_clicked;
#endif

#if HAS_LCD_MENU
#include "menu/menu.h"

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

bool MarlinUI::lcd_clicked;

bool MarlinUI::use_click() {
const bool click = lcd_clicked;
lcd_clicked = false;
return click;
}

#if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)

bool MarlinUI::external_control; // = false
Expand Down

0 comments on commit d84e2d6

Please sign in to comment.