From a0ca98f699b424dad1e123b89194bfbbcb3e49fe Mon Sep 17 00:00:00 2001 From: Marcio Teixeira Date: Sat, 23 Mar 2019 22:09:18 -0600 Subject: [PATCH] Additional ExtUI features (#13449) --- Marlin/Makefile | 2 +- Marlin/src/lcd/extensible_ui/ui_api.cpp | 123 +++++++++++++++++++++++- Marlin/src/lcd/extensible_ui/ui_api.h | 15 +++ 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/Marlin/Makefile b/Marlin/Makefile index d0ed5cdb78..a62bccd420 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -674,7 +674,7 @@ ASFLAGS := $(CDEFS) ifeq ($(HARDWARE_VARIANT), archim) LD_PREFIX = -Wl,--gc-sections,-Map,Marlin.ino.map,--cref,--check-sections,--entry=Reset_Handler,--unresolved-symbols=report-all,--warn-common,--warn-section-align LD_SUFFIX = $(LDLIBS) - LDFLAGS = -lm -gcc -T$(LDSCRIPT) -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid + LDFLAGS = -lm -T$(LDSCRIPT) -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid else LD_PREFIX = -Wl,--gc-sections,--relax LDFLAGS = -lm diff --git a/Marlin/src/lcd/extensible_ui/ui_api.cpp b/Marlin/src/lcd/extensible_ui/ui_api.cpp index e8595b1eec..80f84e98fd 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.cpp +++ b/Marlin/src/lcd/extensible_ui/ui_api.cpp @@ -74,8 +74,9 @@ #define IFSD(A,B) (B) #endif -#if HAS_TRINAMIC && HAS_LCD_MENU +#if HAS_TRINAMIC #include "../../feature/tmc_util.h" + #include "../../module/stepper_indirection.h" #endif #include "ui_api.h" @@ -339,6 +340,122 @@ namespace ExtUI { return !thermalManager.tooColdToExtrude(extruder - E0); } + #if HAS_SOFTWARE_ENDSTOPS + bool getSoftEndstopState() { + return soft_endstops_enabled; + } + + void setSoftEndstopState(const bool value) { + soft_endstops_enabled = value; + } + #endif + + #if HAS_TRINAMIC + float getAxisCurrent_mA(const axis_t axis) { + switch (axis) { + #if AXIS_IS_TMC(X) + case X: return stepperX.getMilliamps(); + #endif + #if AXIS_IS_TMC(Y) + case Y: return stepperY.getMilliamps(); + #endif + #if AXIS_IS_TMC(Z) + case Z: return stepperZ.getMilliamps(); + #endif + default: return NAN; + }; + } + + float getAxisCurrent_mA(const extruder_t extruder) { + switch (extruder) { + #if AXIS_IS_TMC(E0) + case E0: return stepperE0.getMilliamps(); + #endif + #if AXIS_IS_TMC(E1) + case E1: return stepperE1.getMilliamps(); + #endif + #if AXIS_IS_TMC(E2) + case E2: return stepperE2.getMilliamps(); + #endif + #if AXIS_IS_TMC(E3) + case E3: return stepperE3.getMilliamps(); + #endif + #if AXIS_IS_TMC(E4) + case E4: return stepperE4.getMilliamps(); + #endif + #if AXIS_IS_TMC(E5) + case E5: return stepperE5.getMilliamps(); + #endif + default: return NAN; + }; + } + + void setAxisCurrent_mA(const float mA, const axis_t axis) { + switch (axis) { + #if AXIS_IS_TMC(X) + case X: stepperX.rms_current(clamp(mA, 500, 1500)); break; + #endif + #if AXIS_IS_TMC(Y) + case Y: stepperY.rms_current(clamp(mA, 500, 1500)); break; + #endif + #if AXIS_IS_TMC(Z) + case Z: stepperZ.rms_current(clamp(mA, 500, 1500)); break; + #endif + }; + } + + void setAxisCurrent_mA(const float mA, const extruder_t extruder) { + switch (extruder) { + #if AXIS_IS_TMC(E0) + case E0: stepperE0.rms_current(clamp(mA, 500, 1500)); break; + #endif + #if AXIS_IS_TMC(E1) + case E1: stepperE1.rms_current(clamp(mA, 500, 1500)); break; + #endif + #if AXIS_IS_TMC(E2) + case E2: stepperE2.rms_current(clamp(mA, 500, 1500)); break; + #endif + #if AXIS_IS_TMC(E3) + case E3: stepperE3.rms_current(clamp(mA, 500, 1500)); break; + #endif + #if AXIS_IS_TMC(E4) + case E4: stepperE4.rms_current(clamp(mA, 500, 1500)); break; + #endif + #if AXIS_IS_TMC(E5) + case E5: stepperE5.rms_current(clamp(mA, 500, 1500)); break; + #endif + }; + } + + int getTMCBumpSensitivity(const axis_t axis) { + switch (axis) { + #if X_SENSORLESS && AXIS_HAS_STALLGUARD(X) + case X: return stepperX.sgt(); + #endif + #if Y_SENSORLESS && AXIS_HAS_STALLGUARD(Y) + case Y: return stepperY.sgt(); + #endif + #if Z_SENSORLESS && AXIS_HAS_STALLGUARD(Z) + case Z: return stepperZ.sgt(); + #endif + } + } + + void setTMCBumpSensitivity(const float value, const axis_t axis) { + switch (axis) { + #if X_SENSORLESS && AXIS_HAS_STALLGUARD(X) + case X: stepperX.sgt(clamp(value, -64, 63)); break; + #endif + #if Y_SENSORLESS && AXIS_HAS_STALLGUARD(Y) + case Y: stepperY.sgt(clamp(value, -64, 63)); break; + #endif + #if Z_SENSORLESS && AXIS_HAS_STALLGUARD(Z) + case Z: stepperZ.sgt(clamp(value, -64, 63)); break; + #endif + } + } + #endif + float getAxisSteps_per_mm(const axis_t axis) { return planner.settings.axis_steps_per_mm[axis]; } @@ -787,10 +904,6 @@ void MarlinUI::init() { SET_INPUT_PULLUP(SD_DETECT_PIN); #endif - #if HAS_TRINAMIC && HAS_LCD_MENU - init_tmc_section(); - #endif - ExtUI::onStartup(); } diff --git a/Marlin/src/lcd/extensible_ui/ui_api.h b/Marlin/src/lcd/extensible_ui/ui_api.h index 46b5d805b7..fc7a867818 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.h +++ b/Marlin/src/lcd/extensible_ui/ui_api.h @@ -68,6 +68,21 @@ namespace ExtUI { */ PGM_P getFirmwareName_str(); + #if HAS_SOFTWARE_ENDSTOPS + bool getSoftEndstopState(); + void setSoftEndstopState(const bool); + #endif + + #if HAS_TRINAMIC + float getAxisCurrent_mA(const axis_t); + float getAxisCurrent_mA(const extruder_t); + void setAxisCurrent_mA(const float, const axis_t); + void setAxisCurrent_mA(const float, const extruder_t); + + int getTMCBumpSensitivity(const axis_t); + void setTMCBumpSensitivity(const float, const axis_t); + #endif + float getActualTemp_celsius(const heater_t); float getActualTemp_celsius(const extruder_t); float getTargetTemp_celsius(const heater_t);