2018-10-22 19:37:48 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-22 19:37:48 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2018-10-22 19:37:48 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
/**************
|
|
|
|
* ui_api.cpp *
|
|
|
|
**************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* To view a copy of the GNU General Public License, go to the following *
|
|
|
|
* location: <http://www.gnu.org/licenses/>. *
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 17:07:52 -05:00
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
2018-10-08 15:44:05 -05:00
|
|
|
|
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
|
2018-11-13 01:47:45 -06:00
|
|
|
#include "../ultralcd.h"
|
2018-10-08 15:44:05 -05:00
|
|
|
#include "../../gcode/queue.h"
|
|
|
|
#include "../../module/motion.h"
|
|
|
|
#include "../../module/planner.h"
|
|
|
|
#include "../../module/probe.h"
|
|
|
|
#include "../../module/temperature.h"
|
2019-03-05 06:39:15 -06:00
|
|
|
#include "../../module/printcounter.h"
|
2018-10-08 15:44:05 -05:00
|
|
|
#include "../../libs/duration_t.h"
|
2018-10-22 19:37:48 -05:00
|
|
|
#include "../../HAL/shared/Delay.h"
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2019-03-05 06:39:15 -06:00
|
|
|
#if ENABLED(PRINTCOUNTER)
|
|
|
|
#include "../../core/utility.h"
|
2019-06-11 05:58:43 -05:00
|
|
|
#include "../../libs/numtostr.h"
|
2019-03-05 06:39:15 -06:00
|
|
|
#endif
|
|
|
|
|
2019-08-20 03:44:17 -05:00
|
|
|
#if EXTRUDERS > 1
|
2018-10-08 15:44:05 -05:00
|
|
|
#include "../../module/tool_change.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-12 15:55:47 -06:00
|
|
|
#if ENABLED(EMERGENCY_PARSER)
|
|
|
|
#include "../../feature/emergency_parser.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
#if ENABLED(SDSUPPORT)
|
2018-10-16 16:58:29 -05:00
|
|
|
#include "../../sd/cardreader.h"
|
2018-10-20 01:44:46 -05:00
|
|
|
#define IFSD(A,B) (A)
|
|
|
|
#else
|
|
|
|
#define IFSD(A,B) (B)
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
|
|
|
|
2019-03-23 23:09:18 -05:00
|
|
|
#if HAS_TRINAMIC
|
2019-01-17 18:48:29 -06:00
|
|
|
#include "../../feature/tmc_util.h"
|
2019-08-31 19:44:45 -05:00
|
|
|
#include "../../module/stepper/indirection.h"
|
2019-01-17 18:48:29 -06:00
|
|
|
#endif
|
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
#include "ui_api.h"
|
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
2019-05-03 23:53:15 -05:00
|
|
|
#include "../../feature/backlash.h"
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
|
|
|
|
2019-03-17 07:57:54 -05:00
|
|
|
#if HAS_LEVELING
|
2019-03-25 20:41:38 -05:00
|
|
|
#include "../../feature/bedlevel/bedlevel.h"
|
2019-03-17 07:57:54 -05:00
|
|
|
#endif
|
|
|
|
|
2019-02-12 20:08:34 -06:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2018-10-16 07:28:52 -05:00
|
|
|
#include "../../feature/runout.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-06 18:04:34 -05:00
|
|
|
#if ENABLED(BABYSTEPPING)
|
|
|
|
#include "../../feature/babystep.h"
|
|
|
|
#endif
|
|
|
|
|
2019-07-17 04:07:41 -05:00
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
#include "../../feature/host_actions.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
inline float clamp(const float value, const float minimum, const float maximum) {
|
2019-07-05 18:01:21 -05:00
|
|
|
return _MAX(_MIN(value, maximum), minimum);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
static struct {
|
|
|
|
uint8_t printer_killed : 1;
|
|
|
|
uint8_t manual_motion : 1;
|
|
|
|
} flags;
|
2018-10-22 19:37:48 -05:00
|
|
|
|
2018-11-14 13:13:51 -06:00
|
|
|
namespace ExtUI {
|
2018-10-22 19:37:48 -05:00
|
|
|
#ifdef __SAM3X8E__
|
|
|
|
/**
|
|
|
|
* Implement a special millis() to allow time measurement
|
|
|
|
* within an ISR (such as when the printer is killed).
|
|
|
|
*
|
|
|
|
* To keep proper time, must be called at least every 1s.
|
|
|
|
*/
|
|
|
|
uint32_t safe_millis() {
|
|
|
|
// Not killed? Just call millis()
|
2018-10-30 19:42:26 -05:00
|
|
|
if (!flags.printer_killed) return millis();
|
2018-10-22 19:37:48 -05:00
|
|
|
|
|
|
|
static uint32_t currTimeHI = 0; /* Current time */
|
|
|
|
|
|
|
|
// Machine was killed, reinit SysTick so we are able to compute time without ISRs
|
|
|
|
if (currTimeHI == 0) {
|
|
|
|
// Get the last time the Arduino time computed (from CMSIS) and convert it to SysTick
|
2018-10-31 17:07:52 -05:00
|
|
|
currTimeHI = (uint32_t)((GetTickCount() * (uint64_t)(F_CPU / 8000)) >> 24);
|
2018-10-22 19:37:48 -05:00
|
|
|
|
|
|
|
// Reinit the SysTick timer to maximize its period
|
|
|
|
SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; // get the full range for the systick timer
|
|
|
|
SysTick->VAL = 0; // Load the SysTick Counter Value
|
|
|
|
SysTick->CTRL = // MCLK/8 as source
|
|
|
|
// No interrupts
|
|
|
|
SysTick_CTRL_ENABLE_Msk; // Enable SysTick Timer
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if there was a timer overflow from the last read
|
|
|
|
if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) {
|
|
|
|
// There was. This means (SysTick_LOAD_RELOAD_Msk * 1000 * 8)/F_CPU ms has elapsed
|
|
|
|
currTimeHI++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate current time in milliseconds
|
|
|
|
uint32_t currTimeLO = SysTick_LOAD_RELOAD_Msk - SysTick->VAL; // (in MCLK/8)
|
|
|
|
uint64_t currTime = ((uint64_t)currTimeLO) | (((uint64_t)currTimeHI) << 24);
|
|
|
|
|
|
|
|
// The ms count is
|
|
|
|
return (uint32_t)(currTime / (F_CPU / 8000));
|
|
|
|
}
|
2018-11-17 22:21:44 -06:00
|
|
|
#endif // __SAM3X8E__
|
2018-10-22 19:37:48 -05:00
|
|
|
|
2019-05-10 15:56:13 -05:00
|
|
|
void delay_us(unsigned long us) { DELAY_US(us); }
|
2018-10-08 15:44:05 -05:00
|
|
|
|
|
|
|
void delay_ms(unsigned long ms) {
|
2018-10-30 19:42:26 -05:00
|
|
|
if (flags.printer_killed)
|
2018-10-22 19:37:48 -05:00
|
|
|
DELAY_US(ms * 1000);
|
|
|
|
else
|
|
|
|
safe_delay(ms);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void yield() {
|
2018-10-30 19:42:26 -05:00
|
|
|
if (!flags.printer_killed)
|
2018-10-22 19:37:48 -05:00
|
|
|
thermalManager.manage_heater();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-05-10 15:56:13 -05:00
|
|
|
void enableHeater(const extruder_t extruder) {
|
2019-09-10 02:20:49 -05:00
|
|
|
#if HOTENDS && HEATER_IDLE_HANDLER
|
2019-05-10 15:56:13 -05:00
|
|
|
thermalManager.reset_heater_idle_timer(extruder - E0);
|
2019-09-16 16:49:46 -05:00
|
|
|
#else
|
|
|
|
UNUSED(extruder);
|
2019-05-10 15:56:13 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void enableHeater(const heater_t heater) {
|
|
|
|
#if HEATER_IDLE_HANDLER
|
2019-06-07 07:08:41 -05:00
|
|
|
switch (heater) {
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
case BED:
|
|
|
|
thermalManager.reset_bed_idle_timer();
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
case CHAMBER: return; // Chamber has no idle timer
|
|
|
|
#endif
|
2019-09-10 02:20:49 -05:00
|
|
|
default:
|
|
|
|
#if HOTENDS
|
|
|
|
thermalManager.reset_heater_idle_timer(heater - H0);
|
|
|
|
#endif
|
|
|
|
break;
|
2019-06-07 07:08:41 -05:00
|
|
|
}
|
2019-09-16 16:49:46 -05:00
|
|
|
#else
|
|
|
|
UNUSED(heater);
|
2019-05-10 15:56:13 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isHeaterIdle(const extruder_t extruder) {
|
|
|
|
return false
|
2019-09-10 02:20:49 -05:00
|
|
|
#if HOTENDS && HEATER_IDLE_HANDLER
|
2019-05-10 15:56:13 -05:00
|
|
|
|| thermalManager.hotend_idle[extruder - E0].timed_out
|
2019-09-16 16:49:46 -05:00
|
|
|
#else
|
|
|
|
; UNUSED(extruder)
|
2019-05-10 15:56:13 -05:00
|
|
|
#endif
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isHeaterIdle(const heater_t heater) {
|
2019-06-07 07:08:41 -05:00
|
|
|
#if HEATER_IDLE_HANDLER
|
|
|
|
switch (heater) {
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
case BED: return thermalManager.bed_idle.timed_out;
|
|
|
|
#endif
|
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
case CHAMBER: return false; // Chamber has no idle timer
|
|
|
|
#endif
|
2019-09-10 02:20:49 -05:00
|
|
|
default:
|
|
|
|
#if HOTENDS
|
|
|
|
return thermalManager.hotend_idle[heater - H0].timed_out;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2019-06-07 07:08:41 -05:00
|
|
|
}
|
|
|
|
#else
|
2019-09-16 16:49:46 -05:00
|
|
|
UNUSED(heater);
|
2019-06-07 07:08:41 -05:00
|
|
|
return false;
|
|
|
|
#endif
|
2019-05-10 15:56:13 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getActualTemp_celsius(const heater_t heater) {
|
2019-06-07 07:08:41 -05:00
|
|
|
switch (heater) {
|
2018-10-08 15:44:05 -05:00
|
|
|
#if HAS_HEATED_BED
|
2019-06-07 07:08:41 -05:00
|
|
|
case BED: return thermalManager.degBed();
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
2019-06-07 07:08:41 -05:00
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
case CHAMBER: return thermalManager.degChamber();
|
|
|
|
#endif
|
|
|
|
default: return thermalManager.degHotend(heater - H0);
|
|
|
|
}
|
2018-10-30 19:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
float getActualTemp_celsius(const extruder_t extruder) {
|
|
|
|
return thermalManager.degHotend(extruder - E0);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getTargetTemp_celsius(const heater_t heater) {
|
2019-06-07 07:08:41 -05:00
|
|
|
switch (heater) {
|
2018-10-08 15:44:05 -05:00
|
|
|
#if HAS_HEATED_BED
|
2019-06-07 07:08:41 -05:00
|
|
|
case BED: return thermalManager.degTargetBed();
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
2019-06-07 07:08:41 -05:00
|
|
|
#if HAS_HEATED_CHAMBER
|
|
|
|
case CHAMBER: return thermalManager.degTargetChamber();
|
|
|
|
#endif
|
|
|
|
default: return thermalManager.degTargetHotend(heater - H0);
|
|
|
|
}
|
2018-10-30 19:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
float getTargetTemp_celsius(const extruder_t extruder) {
|
|
|
|
return thermalManager.degTargetHotend(extruder - E0);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-01-12 00:41:48 -06:00
|
|
|
float getTargetFan_percent(const fan_t fan) {
|
2019-06-29 00:23:57 -05:00
|
|
|
#if FAN_COUNT > 0
|
|
|
|
return thermalManager.fanPercent(thermalManager.fan_speed[fan - FAN0]);
|
|
|
|
#else
|
|
|
|
UNUSED(fan);
|
|
|
|
return 0;
|
|
|
|
#endif
|
2019-01-12 00:41:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
float getActualFan_percent(const fan_t fan) {
|
2019-06-29 00:23:57 -05:00
|
|
|
#if FAN_COUNT > 0
|
|
|
|
return thermalManager.fanPercent(thermalManager.scaledFanSpeed(fan - FAN0));
|
|
|
|
#else
|
|
|
|
UNUSED(fan);
|
|
|
|
return 0;
|
|
|
|
#endif
|
2019-01-12 00:41:48 -06:00
|
|
|
}
|
2018-10-08 15:44:05 -05:00
|
|
|
|
|
|
|
float getAxisPosition_mm(const axis_t axis) {
|
2018-10-30 19:42:26 -05:00
|
|
|
return flags.manual_motion ? destination[axis] : current_position[axis];
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-08-20 03:44:17 -05:00
|
|
|
float getAxisPosition_mm(const extruder_t extruder) {
|
2019-08-21 04:15:37 -05:00
|
|
|
const extruder_t old_tool = getActiveTool();
|
2019-08-20 03:44:17 -05:00
|
|
|
setActiveTool(extruder, true);
|
|
|
|
const float pos = flags.manual_motion ? destination[E_AXIS] : current_position[E_AXIS];
|
|
|
|
setActiveTool(old_tool, true);
|
|
|
|
return pos;
|
2018-10-30 19:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisPosition_mm(const float position, const axis_t axis) {
|
|
|
|
// Start with no limits to movement
|
|
|
|
float min = current_position[axis] - 1000,
|
|
|
|
max = current_position[axis] + 1000;
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
// Limit to software endstops, if enabled
|
2018-11-03 03:56:33 -05:00
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
2018-10-30 19:42:26 -05:00
|
|
|
if (soft_endstops_enabled) switch (axis) {
|
|
|
|
case X_AXIS:
|
|
|
|
#if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
|
2019-03-13 05:48:36 -05:00
|
|
|
min = soft_endstop[X_AXIS].min;
|
2018-10-30 19:42:26 -05:00
|
|
|
#endif
|
|
|
|
#if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
|
2019-03-13 05:48:36 -05:00
|
|
|
max = soft_endstop[X_AXIS].max;
|
2018-10-30 19:42:26 -05:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case Y_AXIS:
|
|
|
|
#if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
|
2019-03-13 05:48:36 -05:00
|
|
|
min = soft_endstop[Y_AXIS].min;
|
2018-10-30 19:42:26 -05:00
|
|
|
#endif
|
|
|
|
#if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
|
2019-03-13 05:48:36 -05:00
|
|
|
max = soft_endstop[Y_AXIS].max;
|
2018-10-30 19:42:26 -05:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case Z_AXIS:
|
|
|
|
#if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
|
2019-03-13 05:48:36 -05:00
|
|
|
min = soft_endstop[Z_AXIS].min;
|
2018-10-30 19:42:26 -05:00
|
|
|
#endif
|
|
|
|
#if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
|
2019-03-13 05:48:36 -05:00
|
|
|
max = soft_endstop[Z_AXIS].max;
|
2018-10-30 19:42:26 -05:00
|
|
|
#endif
|
|
|
|
default: break;
|
|
|
|
}
|
2018-11-03 03:56:33 -05:00
|
|
|
#endif // HAS_SOFTWARE_ENDSTOPS
|
2018-10-30 19:42:26 -05:00
|
|
|
|
|
|
|
// Delta limits XY based on the current offset from center
|
|
|
|
// This assumes the center is 0,0
|
|
|
|
#if ENABLED(DELTA)
|
|
|
|
if (axis != Z_AXIS) {
|
|
|
|
max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
|
|
|
|
min = -max;
|
|
|
|
}
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
2018-10-30 19:42:26 -05:00
|
|
|
|
2019-08-20 03:44:17 -05:00
|
|
|
constexpr float max_manual_feedrate[XYZE] = MANUAL_FEEDRATE;
|
2019-08-28 04:23:13 -05:00
|
|
|
setFeedrate_mm_s(MMM_TO_MMS(max_manual_feedrate[axis]));
|
2019-08-20 03:44:17 -05:00
|
|
|
|
2019-05-10 15:56:13 -05:00
|
|
|
if (!flags.manual_motion) set_destination_from_current();
|
2018-10-30 19:42:26 -05:00
|
|
|
destination[axis] = clamp(position, min, max);
|
|
|
|
flags.manual_motion = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisPosition_mm(const float position, const extruder_t extruder) {
|
|
|
|
setActiveTool(extruder, true);
|
|
|
|
|
2019-08-20 03:44:17 -05:00
|
|
|
constexpr float max_manual_feedrate[XYZE] = MANUAL_FEEDRATE;
|
2019-08-28 04:23:13 -05:00
|
|
|
setFeedrate_mm_s(MMM_TO_MMS(max_manual_feedrate[E_AXIS]));
|
2019-05-10 15:56:13 -05:00
|
|
|
if (!flags.manual_motion) set_destination_from_current();
|
2018-10-30 19:42:26 -05:00
|
|
|
destination[E_AXIS] = position;
|
|
|
|
flags.manual_motion = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _processManualMoveToDestination() {
|
|
|
|
// Lower max_response_lag makes controls more responsive, but makes CPU work harder
|
|
|
|
constexpr float max_response_lag = 0.1; // seconds
|
|
|
|
constexpr uint8_t segments_to_buffer = 4; // keep planner filled with this many segments
|
|
|
|
|
|
|
|
if (flags.manual_motion && planner.movesplanned() < segments_to_buffer) {
|
|
|
|
float saved_destination[XYZ];
|
|
|
|
COPY(saved_destination, destination);
|
|
|
|
// Compute direction vector from current_position towards destination.
|
|
|
|
destination[X_AXIS] -= current_position[X_AXIS];
|
|
|
|
destination[Y_AXIS] -= current_position[Y_AXIS];
|
|
|
|
destination[Z_AXIS] -= current_position[Z_AXIS];
|
|
|
|
const float inv_length = RSQRT(sq(destination[X_AXIS]) + sq(destination[Y_AXIS]) + sq(destination[Z_AXIS]));
|
|
|
|
// Find move segment length so that all segments can execute in less time than max_response_lag
|
|
|
|
const float scale = inv_length * feedrate_mm_s * max_response_lag / segments_to_buffer;
|
|
|
|
if (scale < 1) {
|
|
|
|
// Move a small bit towards the destination.
|
|
|
|
destination[X_AXIS] = scale * destination[X_AXIS] + current_position[X_AXIS];
|
|
|
|
destination[Y_AXIS] = scale * destination[Y_AXIS] + current_position[Y_AXIS];
|
|
|
|
destination[Z_AXIS] = scale * destination[Z_AXIS] + current_position[Z_AXIS];
|
|
|
|
prepare_move_to_destination();
|
|
|
|
COPY(destination, saved_destination);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We are close enough to finish off the move.
|
|
|
|
COPY(destination, saved_destination);
|
|
|
|
prepare_move_to_destination();
|
|
|
|
flags.manual_motion = false;
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
void setActiveTool(const extruder_t extruder, bool no_move) {
|
2018-11-17 22:21:44 -06:00
|
|
|
#if EXTRUDERS > 1
|
|
|
|
const uint8_t e = extruder - E0;
|
2019-08-20 03:44:17 -05:00
|
|
|
if (e != active_extruder) tool_change(e, no_move);
|
2018-11-17 22:21:44 -06:00
|
|
|
active_extruder = e;
|
2019-06-29 00:23:57 -05:00
|
|
|
#else
|
|
|
|
UNUSED(extruder);
|
|
|
|
UNUSED(no_move);
|
2018-10-24 16:36:11 -05:00
|
|
|
#endif
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
extruder_t getActiveTool() {
|
|
|
|
switch (active_extruder) {
|
|
|
|
case 5: return E5;
|
|
|
|
case 4: return E4;
|
|
|
|
case 3: return E3;
|
|
|
|
case 2: return E2;
|
|
|
|
case 1: return E1;
|
|
|
|
default: return E0;
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 15:44:05 -05:00
|
|
|
|
|
|
|
bool isMoving() { return planner.has_blocks_queued(); }
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
bool canMove(const axis_t axis) {
|
2018-10-08 15:44:05 -05:00
|
|
|
switch (axis) {
|
2018-10-30 19:42:26 -05:00
|
|
|
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
|
|
|
|
case X: return TEST(axis_homed, X_AXIS);
|
|
|
|
case Y: return TEST(axis_homed, Y_AXIS);
|
|
|
|
case Z: return TEST(axis_homed, Z_AXIS);
|
|
|
|
#else
|
|
|
|
case X: case Y: case Z: return true;
|
|
|
|
#endif
|
|
|
|
default: return false;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
bool canMove(const extruder_t extruder) {
|
|
|
|
return !thermalManager.tooColdToExtrude(extruder - E0);
|
|
|
|
}
|
|
|
|
|
2019-03-23 23:09:18 -05:00
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
2019-05-10 15:56:13 -05:00
|
|
|
bool getSoftEndstopState() { return soft_endstops_enabled; }
|
|
|
|
void setSoftEndstopState(const bool value) { soft_endstops_enabled = value; }
|
2019-03-23 23:09:18 -05:00
|
|
|
#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
|
2019-03-25 20:41:38 -05:00
|
|
|
default: break;
|
2019-03-23 23:09:18 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-03-25 20:41:38 -05:00
|
|
|
default: break;
|
2019-03-23 23:09:18 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTMCBumpSensitivity(const axis_t axis) {
|
|
|
|
switch (axis) {
|
|
|
|
#if X_SENSORLESS && AXIS_HAS_STALLGUARD(X)
|
2019-06-20 15:47:50 -05:00
|
|
|
case X: return stepperX.homing_threshold();
|
2019-03-23 23:09:18 -05:00
|
|
|
#endif
|
|
|
|
#if Y_SENSORLESS && AXIS_HAS_STALLGUARD(Y)
|
2019-06-20 15:47:50 -05:00
|
|
|
case Y: return stepperY.homing_threshold();
|
2019-03-23 23:09:18 -05:00
|
|
|
#endif
|
|
|
|
#if Z_SENSORLESS && AXIS_HAS_STALLGUARD(Z)
|
2019-06-20 15:47:50 -05:00
|
|
|
case Z: return stepperZ.homing_threshold();
|
2019-03-23 23:09:18 -05:00
|
|
|
#endif
|
2019-03-25 20:41:38 -05:00
|
|
|
default: return 0;
|
2019-03-23 23:09:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTMCBumpSensitivity(const float value, const axis_t axis) {
|
|
|
|
switch (axis) {
|
|
|
|
#if X_SENSORLESS && AXIS_HAS_STALLGUARD(X)
|
2019-06-20 15:47:50 -05:00
|
|
|
case X: stepperX.homing_threshold(value); break;
|
2019-03-23 23:09:18 -05:00
|
|
|
#endif
|
|
|
|
#if Y_SENSORLESS && AXIS_HAS_STALLGUARD(Y)
|
2019-06-20 15:47:50 -05:00
|
|
|
case Y: stepperY.homing_threshold(value); break;
|
2019-03-23 23:09:18 -05:00
|
|
|
#endif
|
|
|
|
#if Z_SENSORLESS && AXIS_HAS_STALLGUARD(Z)
|
2019-06-20 15:47:50 -05:00
|
|
|
case Z: stepperZ.homing_threshold(value); break;
|
2019-03-23 23:09:18 -05:00
|
|
|
#endif
|
2019-03-25 20:41:38 -05:00
|
|
|
default: break;
|
2019-03-23 23:09:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getAxisSteps_per_mm(const axis_t axis) {
|
|
|
|
return planner.settings.axis_steps_per_mm[axis];
|
|
|
|
}
|
|
|
|
|
|
|
|
float getAxisSteps_per_mm(const extruder_t extruder) {
|
2019-06-29 00:23:57 -05:00
|
|
|
UNUSED_E(extruder);
|
2018-10-30 19:42:26 -05:00
|
|
|
return planner.settings.axis_steps_per_mm[E_AXIS_N(extruder - E0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisSteps_per_mm(const float value, const axis_t axis) {
|
|
|
|
planner.settings.axis_steps_per_mm[axis] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisSteps_per_mm(const float value, const extruder_t extruder) {
|
2019-06-29 00:23:57 -05:00
|
|
|
UNUSED_E(extruder);
|
2018-10-30 19:42:26 -05:00
|
|
|
planner.settings.axis_steps_per_mm[E_AXIS_N(axis - E0)] = value;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
float getAxisMaxFeedrate_mm_s(const axis_t axis) {
|
2018-10-30 19:42:26 -05:00
|
|
|
return planner.settings.max_feedrate_mm_s[axis];
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getAxisMaxFeedrate_mm_s(const extruder_t extruder) {
|
2019-06-29 00:23:57 -05:00
|
|
|
UNUSED_E(extruder);
|
2018-10-30 19:42:26 -05:00
|
|
|
return planner.settings.max_feedrate_mm_s[E_AXIS_N(axis - E0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisMaxFeedrate_mm_s(const float value, const axis_t axis) {
|
|
|
|
planner.settings.max_feedrate_mm_s[axis] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisMaxFeedrate_mm_s(const float value, const extruder_t extruder) {
|
2019-06-29 00:23:57 -05:00
|
|
|
UNUSED_E(extruder);
|
2018-10-30 19:42:26 -05:00
|
|
|
planner.settings.max_feedrate_mm_s[E_AXIS_N(axis - E0)] = value;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
float getAxisMaxAcceleration_mm_s2(const axis_t axis) {
|
2018-10-30 19:42:26 -05:00
|
|
|
return planner.settings.max_acceleration_mm_per_s2[axis];
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getAxisMaxAcceleration_mm_s2(const extruder_t extruder) {
|
2019-06-29 00:23:57 -05:00
|
|
|
UNUSED_E(extruder);
|
2018-10-30 19:42:26 -05:00
|
|
|
return planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(extruder - E0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisMaxAcceleration_mm_s2(const float value, const axis_t axis) {
|
|
|
|
planner.settings.max_acceleration_mm_per_s2[axis] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisMaxAcceleration_mm_s2(const float value, const extruder_t extruder) {
|
2019-06-29 00:23:57 -05:00
|
|
|
UNUSED_E(extruder);
|
2018-10-30 19:42:26 -05:00
|
|
|
planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(extruder - E0)] = value;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-02-12 20:08:34 -06:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2018-10-30 19:42:26 -05:00
|
|
|
bool getFilamentRunoutEnabled() { return runout.enabled; }
|
|
|
|
void setFilamentRunoutEnabled(const bool value) { runout.enabled = value; }
|
2018-10-16 07:28:52 -05:00
|
|
|
|
2019-05-03 23:53:15 -05:00
|
|
|
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
|
2019-05-10 15:56:13 -05:00
|
|
|
float getFilamentRunoutDistance_mm() { return runout.runout_distance(); }
|
|
|
|
void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(clamp(value, 0, 999)); }
|
2018-10-16 07:28:52 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
#if ENABLED(LIN_ADVANCE)
|
2018-10-30 19:42:26 -05:00
|
|
|
float getLinearAdvance_mm_mm_s(const extruder_t extruder) {
|
|
|
|
return (extruder < EXTRUDERS) ? planner.extruder_advance_K[extruder - E0] : 0;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
void setLinearAdvance_mm_mm_s(const float value, const extruder_t extruder) {
|
2018-10-08 15:44:05 -05:00
|
|
|
if (extruder < EXTRUDERS)
|
2018-10-30 19:42:26 -05:00
|
|
|
planner.extruder_advance_K[extruder - E0] = clamp(value, 0, 999);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(JUNCTION_DEVIATION)
|
2018-10-31 17:07:52 -05:00
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
float getJunctionDeviation_mm() {
|
|
|
|
return planner.junction_deviation_mm;
|
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
void setJunctionDeviation_mm(const float value) {
|
|
|
|
planner.junction_deviation_mm = clamp(value, 0.01, 0.3);
|
2019-03-17 07:57:54 -05:00
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
planner.recalculate_max_e_jerk();
|
|
|
|
#endif
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
2018-10-31 17:07:52 -05:00
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
#else
|
2018-10-31 17:07:52 -05:00
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
float getAxisMaxJerk_mm_s(const axis_t axis) {
|
2018-10-31 17:07:52 -05:00
|
|
|
return planner.max_jerk[axis];
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-06-29 00:23:57 -05:00
|
|
|
float getAxisMaxJerk_mm_s(const extruder_t) {
|
2018-10-31 17:07:52 -05:00
|
|
|
return planner.max_jerk[E_AXIS];
|
2018-10-30 19:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void setAxisMaxJerk_mm_s(const float value, const axis_t axis) {
|
|
|
|
planner.max_jerk[axis] = value;
|
|
|
|
}
|
|
|
|
|
2019-06-29 00:23:57 -05:00
|
|
|
void setAxisMaxJerk_mm_s(const float value, const extruder_t) {
|
2018-10-30 19:42:26 -05:00
|
|
|
planner.max_jerk[E_AXIS] = value;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getFeedrate_mm_s() { return feedrate_mm_s; }
|
2018-10-16 16:58:29 -05:00
|
|
|
float getMinFeedrate_mm_s() { return planner.settings.min_feedrate_mm_s; }
|
|
|
|
float getMinTravelFeedrate_mm_s() { return planner.settings.min_travel_feedrate_mm_s; }
|
|
|
|
float getPrintingAcceleration_mm_s2() { return planner.settings.acceleration; }
|
|
|
|
float getRetractAcceleration_mm_s2() { return planner.settings.retract_acceleration; }
|
|
|
|
float getTravelAcceleration_mm_s2() { return planner.settings.travel_acceleration; }
|
2018-10-30 19:42:26 -05:00
|
|
|
void setFeedrate_mm_s(const float fr) { feedrate_mm_s = fr; }
|
2018-10-16 16:58:29 -05:00
|
|
|
void setMinFeedrate_mm_s(const float fr) { planner.settings.min_feedrate_mm_s = fr; }
|
|
|
|
void setMinTravelFeedrate_mm_s(const float fr) { planner.settings.min_travel_feedrate_mm_s = fr; }
|
|
|
|
void setPrintingAcceleration_mm_s2(const float acc) { planner.settings.acceleration = acc; }
|
|
|
|
void setRetractAcceleration_mm_s2(const float acc) { planner.settings.retract_acceleration = acc; }
|
|
|
|
void setTravelAcceleration_mm_s2(const float acc) { planner.settings.travel_acceleration = acc; }
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2019-02-06 07:16:54 -06:00
|
|
|
#if ENABLED(BABYSTEPPING)
|
|
|
|
bool babystepAxis_steps(const int16_t steps, const axis_t axis) {
|
|
|
|
switch (axis) {
|
|
|
|
#if ENABLED(BABYSTEP_XY)
|
2019-04-06 18:04:34 -05:00
|
|
|
case X: babystep.add_steps(X_AXIS, steps); break;
|
|
|
|
case Y: babystep.add_steps(Y_AXIS, steps); break;
|
2019-02-06 07:16:54 -06:00
|
|
|
#endif
|
2019-04-06 18:04:34 -05:00
|
|
|
case Z: babystep.add_steps(Z_AXIS, steps); break;
|
2019-02-06 07:16:54 -06:00
|
|
|
default: return false;
|
|
|
|
};
|
|
|
|
return true;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-02-06 07:16:54 -06:00
|
|
|
/**
|
|
|
|
* This function adjusts an axis during a print.
|
|
|
|
*
|
|
|
|
* When linked_nozzles is false, each nozzle in a multi-nozzle
|
|
|
|
* printer can be babystepped independently of the others. This
|
|
|
|
* lets the user to fine tune the Z-offset and Nozzle Offsets
|
|
|
|
* while observing the first layer of a print, regardless of
|
|
|
|
* what nozzle is printing.
|
|
|
|
*/
|
|
|
|
void smartAdjustAxis_steps(const int16_t steps, const axis_t axis, bool linked_nozzles) {
|
|
|
|
const float mm = steps * planner.steps_to_mm[axis];
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2019-02-06 07:16:54 -06:00
|
|
|
if (!babystepAxis_steps(steps, axis)) return;
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
|
|
|
|
// Make it so babystepping in Z adjusts the Z probe offset.
|
|
|
|
if (axis == Z
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
&& (linked_nozzles || active_extruder == 0)
|
|
|
|
#endif
|
|
|
|
) zprobe_zoffset += mm;
|
2019-07-17 03:16:10 -05:00
|
|
|
#else
|
|
|
|
UNUSED(mm);
|
2019-02-06 07:16:54 -06:00
|
|
|
#endif
|
|
|
|
|
2019-07-20 01:55:34 -05:00
|
|
|
#if EXTRUDERS > 1 && HAS_HOTEND_OFFSET
|
2019-02-06 07:16:54 -06:00
|
|
|
/**
|
|
|
|
* When linked_nozzles is false, as an axis is babystepped
|
|
|
|
* adjust the hotend offsets so that the other nozzles are
|
|
|
|
* unaffected by the babystepping of the active nozzle.
|
|
|
|
*/
|
|
|
|
if (!linked_nozzles) {
|
|
|
|
HOTEND_LOOP()
|
|
|
|
if (e != active_extruder)
|
|
|
|
hotend_offset[axis][e] += mm;
|
|
|
|
|
|
|
|
normalizeNozzleOffset(X);
|
|
|
|
normalizeNozzleOffset(Y);
|
|
|
|
normalizeNozzleOffset(Z);
|
|
|
|
}
|
2018-10-08 15:44:05 -05:00
|
|
|
#else
|
2019-02-06 07:16:54 -06:00
|
|
|
UNUSED(linked_nozzles);
|
2019-07-17 03:16:10 -05:00
|
|
|
UNUSED(mm);
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
2019-02-06 07:16:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a mm displacement to a number of whole number of
|
|
|
|
* steps that is at least mm long.
|
|
|
|
*/
|
|
|
|
int16_t mmToWholeSteps(const float mm, const axis_t axis) {
|
|
|
|
const float steps = mm / planner.steps_to_mm[axis];
|
|
|
|
return steps > 0 ? ceil(steps) : floor(steps);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-25 04:46:02 -05:00
|
|
|
float getZOffset_mm() {
|
|
|
|
#if HAS_BED_PROBE
|
2019-02-06 07:16:54 -06:00
|
|
|
return zprobe_zoffset;
|
2019-08-25 04:46:02 -05:00
|
|
|
#elif ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
|
|
|
return babystep.axis_total[BS_TOTAL_AXIS(Z_AXIS) + 1];
|
|
|
|
#else
|
|
|
|
return 0.0;
|
|
|
|
#endif
|
|
|
|
}
|
2019-02-06 07:16:54 -06:00
|
|
|
|
2019-08-25 04:46:02 -05:00
|
|
|
void setZOffset_mm(const float value) {
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX))
|
2019-02-06 07:16:54 -06:00
|
|
|
zprobe_zoffset = value;
|
2019-08-25 04:46:02 -05:00
|
|
|
#elif ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
|
|
|
babystep.add_mm(Z_AXIS, (value - babystep.axis_total[BS_TOTAL_AXIS(Z_AXIS) + 1]));
|
|
|
|
#else
|
|
|
|
UNUSED(value);
|
|
|
|
#endif
|
|
|
|
}
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2019-03-11 20:48:49 -05:00
|
|
|
#if HAS_HOTEND_OFFSET
|
2019-02-06 07:16:54 -06:00
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getNozzleOffset_mm(const axis_t axis, const extruder_t extruder) {
|
|
|
|
if (extruder - E0 >= HOTENDS) return 0;
|
|
|
|
return hotend_offset[axis][extruder - E0];
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
void setNozzleOffset_mm(const float value, const axis_t axis, const extruder_t extruder) {
|
|
|
|
if (extruder - E0 >= HOTENDS) return;
|
|
|
|
hotend_offset[axis][extruder - E0] = value;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
2019-02-06 07:16:54 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The UI should call this if needs to guarantee the first
|
|
|
|
* nozzle offset is zero (such as when it doesn't allow the
|
|
|
|
* user to edit the offset the first nozzle).
|
|
|
|
*/
|
|
|
|
void normalizeNozzleOffset(const axis_t axis) {
|
|
|
|
const float offs = hotend_offset[axis][0];
|
|
|
|
HOTEND_LOOP() hotend_offset[axis][e] -= offs;
|
|
|
|
}
|
|
|
|
|
2019-03-11 20:48:49 -05:00
|
|
|
#endif // HAS_HOTEND_OFFSET
|
2018-10-08 15:44:05 -05:00
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
2019-05-03 23:53:15 -05:00
|
|
|
float getAxisBacklash_mm(const axis_t axis) { return backlash.distance_mm[axis]; }
|
2018-10-30 19:42:26 -05:00
|
|
|
void setAxisBacklash_mm(const float value, const axis_t axis)
|
2019-05-03 23:53:15 -05:00
|
|
|
{ backlash.distance_mm[axis] = clamp(value,0,5); }
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2019-05-03 23:53:15 -05:00
|
|
|
float getBacklashCorrection_percent() { return ui8_to_percent(backlash.correction); }
|
|
|
|
void setBacklashCorrection_percent(const float value) { backlash.correction = map(clamp(value, 0, 100), 0, 100, 0, 255); }
|
2018-10-08 15:44:05 -05:00
|
|
|
|
|
|
|
#ifdef BACKLASH_SMOOTHING_MM
|
2019-05-03 23:53:15 -05:00
|
|
|
float getBacklashSmoothing_mm() { return backlash.smoothing_mm; }
|
|
|
|
void setBacklashSmoothing_mm(const float value) { backlash.smoothing_mm = clamp(value, 0, 999); }
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint8_t getProgress_percent() {
|
2019-03-07 18:00:38 -06:00
|
|
|
return ui.get_progress();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t getProgress_seconds_elapsed() {
|
2018-10-30 19:42:26 -05:00
|
|
|
const duration_t elapsed = print_job_timer.duration();
|
|
|
|
return elapsed.value;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-03-13 00:45:52 -05:00
|
|
|
#if HAS_LEVELING
|
|
|
|
bool getLevelingActive() { return planner.leveling_active; }
|
2019-03-17 07:57:54 -05:00
|
|
|
void setLevelingActive(const bool state) { set_bed_leveling_enabled(state); }
|
2019-05-17 20:37:23 -05:00
|
|
|
bool getMeshValid() { return leveling_is_valid(); }
|
2019-03-13 00:45:52 -05:00
|
|
|
#if HAS_MESH
|
2019-03-18 16:31:11 -05:00
|
|
|
bed_mesh_t getMeshArray() { return Z_VALUES_ARR; }
|
2019-04-26 02:32:01 -05:00
|
|
|
float getMeshPoint(const uint8_t xpos, const uint8_t ypos) { return Z_VALUES(xpos,ypos); }
|
2019-03-13 00:45:52 -05:00
|
|
|
void setMeshPoint(const uint8_t xpos, const uint8_t ypos, const float zoff) {
|
|
|
|
if (WITHIN(xpos, 0, GRID_MAX_POINTS_X) && WITHIN(ypos, 0, GRID_MAX_POINTS_Y)) {
|
|
|
|
Z_VALUES(xpos, ypos) = zoff;
|
|
|
|
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
|
|
|
|
bed_level_virt_interpolate();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
void setHostResponse(const uint8_t response) { host_response_handler(response); }
|
|
|
|
#endif
|
|
|
|
|
2018-10-16 16:58:29 -05:00
|
|
|
#if ENABLED(PRINTCOUNTER)
|
2019-01-12 16:01:04 -06:00
|
|
|
char* getTotalPrints_str(char buffer[21]) { strcpy(buffer,i16tostr3left(print_job_timer.getStats().totalPrints)); return buffer; }
|
|
|
|
char* getFinishedPrints_str(char buffer[21]) { strcpy(buffer,i16tostr3left(print_job_timer.getStats().finishedPrints)); return buffer; }
|
|
|
|
char* getTotalPrintTime_str(char buffer[21]) { duration_t(print_job_timer.getStats().printTime).toString(buffer); return buffer; }
|
2019-08-10 19:25:30 -05:00
|
|
|
char* getLongestPrint_str(char buffer[21]) { duration_t(print_job_timer.getStats().longestPrint).toString(buffer); return buffer; }
|
2018-10-16 16:58:29 -05:00
|
|
|
char* getFilamentUsed_str(char buffer[21]) {
|
|
|
|
printStatistics stats = print_job_timer.getStats();
|
|
|
|
sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
float getFeedrate_percent() { return feedrate_percentage; }
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2019-06-27 14:11:02 -05:00
|
|
|
void injectCommands_P(PGM_P const gcode) {
|
2019-06-19 00:00:19 -05:00
|
|
|
queue.inject_P(gcode);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-06-29 00:23:57 -05:00
|
|
|
bool commandsInQueue() { return (planner.movesplanned() || queue.has_commands_queued()); }
|
2019-05-03 23:53:15 -05:00
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
bool isAxisPositionKnown(const axis_t axis) {
|
2018-10-30 19:42:26 -05:00
|
|
|
return TEST(axis_known_position, axis);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-06-29 00:23:57 -05:00
|
|
|
bool isAxisPositionKnown(const extruder_t) {
|
|
|
|
return TEST(axis_known_position, E_AXIS);
|
|
|
|
}
|
|
|
|
|
2019-04-26 02:32:01 -05:00
|
|
|
bool isPositionKnown() { return all_axes_known(); }
|
|
|
|
bool isMachineHomed() { return all_axes_homed(); }
|
|
|
|
|
2018-11-17 22:21:44 -06:00
|
|
|
PGM_P getFirmwareName_str() {
|
|
|
|
static const char firmware_name[] PROGMEM = "Marlin " SHORT_BUILD_VERSION;
|
|
|
|
return firmware_name;
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
void setTargetTemp_celsius(float value, const heater_t heater) {
|
2019-05-10 15:56:13 -05:00
|
|
|
enableHeater(heater);
|
2018-10-08 15:44:05 -05:00
|
|
|
#if HAS_HEATED_BED
|
2018-11-17 22:21:44 -06:00
|
|
|
if (heater == BED)
|
2019-03-11 16:32:34 -05:00
|
|
|
thermalManager.setTargetBed(clamp(value, 0, BED_MAXTEMP - 10));
|
2018-11-17 22:21:44 -06:00
|
|
|
else
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
2019-09-10 02:20:49 -05:00
|
|
|
{
|
|
|
|
#if HOTENDS
|
|
|
|
static constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
|
|
|
|
const int16_t e = heater - H0;
|
|
|
|
thermalManager.setTargetHotend(clamp(value, 0, heater_maxtemp[e] - 15), e);
|
|
|
|
#endif
|
|
|
|
}
|
2018-10-30 19:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void setTargetTemp_celsius(float value, const extruder_t extruder) {
|
2019-09-10 02:20:49 -05:00
|
|
|
#if HOTENDS
|
|
|
|
constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
|
|
|
|
const int16_t e = extruder - E0;
|
|
|
|
enableHeater(extruder);
|
|
|
|
thermalManager.setTargetHotend(clamp(value, 0, heater_maxtemp[e] - 15), e);
|
|
|
|
#endif
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-01-12 00:41:48 -06:00
|
|
|
void setTargetFan_percent(const float value, const fan_t fan) {
|
2019-06-29 00:23:57 -05:00
|
|
|
#if FAN_COUNT > 0
|
|
|
|
if (fan < FAN_COUNT)
|
|
|
|
thermalManager.set_fan_speed(fan - FAN0, map(clamp(value, 0, 100), 0, 100, 0, 255));
|
|
|
|
#else
|
|
|
|
UNUSED(value);
|
|
|
|
UNUSED(fan);
|
|
|
|
#endif
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
void setFeedrate_percent(const float value) {
|
|
|
|
feedrate_percentage = clamp(value, 10, 500);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2019-03-09 14:13:50 -06:00
|
|
|
void setUserConfirmed(void) {
|
|
|
|
#if HAS_RESUME_CONTINUE
|
|
|
|
wait_for_user = false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
void printFile(const char *filename) {
|
2018-10-30 19:42:26 -05:00
|
|
|
IFSD(card.openAndPrintFile(filename), NOOP);
|
2018-10-20 01:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPrintingFromMediaPaused() {
|
2018-11-06 20:52:39 -06:00
|
|
|
return IFSD(isPrintingFromMedia() && !IS_SD_PRINTING(), false);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPrintingFromMedia() {
|
2019-01-11 20:42:11 -06:00
|
|
|
return IFSD(card.isFileOpen(), false);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPrinting() {
|
2018-11-17 22:21:44 -06:00
|
|
|
return (planner.movesplanned() || isPrintingFromMedia() || IFSD(IS_SD_PRINTING(), false));
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMediaInserted() {
|
2019-09-15 03:10:59 -05:00
|
|
|
return IFSD(IS_SD_INSERTED() && card.isMounted(), false);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void pausePrint() {
|
2019-05-30 16:24:13 -05:00
|
|
|
ui.pause_print();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void resumePrint() {
|
2019-05-30 16:24:13 -05:00
|
|
|
ui.resume_print();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void stopPrint() {
|
2019-06-07 07:08:41 -05:00
|
|
|
ui.abort_print();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
FileList::FileList() { refresh(); }
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2018-10-30 19:42:26 -05:00
|
|
|
void FileList::refresh() { num_files = 0xFFFF; }
|
2018-10-08 15:44:05 -05:00
|
|
|
|
2018-11-17 22:21:44 -06:00
|
|
|
bool FileList::seek(const uint16_t pos, const bool skip_range_check) {
|
2018-10-08 15:44:05 -05:00
|
|
|
#if ENABLED(SDSUPPORT)
|
2019-03-02 16:43:08 -06:00
|
|
|
if (!skip_range_check && (pos + 1) > count()) return false;
|
2018-10-08 15:44:05 -05:00
|
|
|
const uint16_t nr =
|
|
|
|
#if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
|
|
|
|
count() - 1 -
|
|
|
|
#endif
|
|
|
|
pos;
|
|
|
|
|
2018-10-29 13:54:04 -05:00
|
|
|
card.getfilename_sorted(nr);
|
2019-01-03 08:36:43 -06:00
|
|
|
return card.filename[0] != '\0';
|
2018-11-17 22:21:44 -06:00
|
|
|
#else
|
|
|
|
return false;
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* FileList::filename() {
|
2019-01-03 08:36:43 -06:00
|
|
|
return IFSD(card.longFilename[0] ? card.longFilename : card.filename, "");
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* FileList::shortFilename() {
|
2018-10-20 01:44:46 -05:00
|
|
|
return IFSD(card.filename, "");
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* FileList::longFilename() {
|
2018-10-20 01:44:46 -05:00
|
|
|
return IFSD(card.longFilename, "");
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileList::isDir() {
|
2018-11-16 22:39:16 -06:00
|
|
|
return IFSD(card.flag.filenameIsDir, false);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t FileList::count() {
|
2018-10-20 01:44:46 -05:00
|
|
|
return IFSD((num_files = (num_files == 0xFFFF ? card.get_num_Files() : num_files)), 0);
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileList::isAtRootDir() {
|
|
|
|
#if ENABLED(SDSUPPORT)
|
2019-09-16 17:49:55 -05:00
|
|
|
card.flag.workDirIsRoot;
|
2018-10-08 15:44:05 -05:00
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileList::upDir() {
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
card.updir();
|
|
|
|
num_files = 0xFFFF;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-17 22:21:44 -06:00
|
|
|
void FileList::changeDir(const char * const dirname) {
|
2018-10-08 15:44:05 -05:00
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
card.chdir(dirname);
|
|
|
|
num_files = 0xFFFF;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:13:51 -06:00
|
|
|
} // namespace ExtUI
|
2018-10-08 15:44:05 -05:00
|
|
|
|
|
|
|
// At the moment, we piggy-back off the ultralcd calls, but this could be cleaned up in the future
|
|
|
|
|
2018-11-11 12:16:24 -06:00
|
|
|
void MarlinUI::init() {
|
2018-10-08 15:44:05 -05:00
|
|
|
#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
|
|
|
|
SET_INPUT_PULLUP(SD_DETECT_PIN);
|
|
|
|
#endif
|
2019-01-17 13:17:16 -06:00
|
|
|
|
2018-11-14 13:13:51 -06:00
|
|
|
ExtUI::onStartup();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-11-11 12:16:24 -06:00
|
|
|
void MarlinUI::update() {
|
2018-10-08 15:44:05 -05:00
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
static bool last_sd_status;
|
2018-10-19 13:52:44 -05:00
|
|
|
const bool sd_status = IS_SD_INSERTED();
|
2018-10-08 15:44:05 -05:00
|
|
|
if (sd_status != last_sd_status) {
|
|
|
|
last_sd_status = sd_status;
|
|
|
|
if (sd_status) {
|
2019-09-15 03:10:59 -05:00
|
|
|
card.mount();
|
|
|
|
if (card.isMounted())
|
2018-11-14 13:13:51 -06:00
|
|
|
ExtUI::onMediaInserted();
|
2018-10-08 15:44:05 -05:00
|
|
|
else
|
2018-11-14 13:13:51 -06:00
|
|
|
ExtUI::onMediaError();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
else {
|
2019-09-15 03:10:59 -05:00
|
|
|
const bool ok = card.isMounted();
|
2018-10-08 15:44:05 -05:00
|
|
|
card.release();
|
2018-11-14 13:13:51 -06:00
|
|
|
if (ok) ExtUI::onMediaRemoved();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // SDSUPPORT
|
2018-11-14 13:13:51 -06:00
|
|
|
ExtUI::_processManualMoveToDestination();
|
|
|
|
ExtUI::onIdle();
|
2018-10-08 15:44:05 -05:00
|
|
|
}
|
|
|
|
|
2018-11-11 12:16:24 -06:00
|
|
|
void MarlinUI::kill_screen(PGM_P const msg) {
|
2018-10-30 19:42:26 -05:00
|
|
|
if (!flags.printer_killed) {
|
|
|
|
flags.printer_killed = true;
|
2018-11-14 13:13:51 -06:00
|
|
|
ExtUI::onPrinterKilled(msg);
|
2018-10-22 19:37:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 15:44:05 -05:00
|
|
|
#endif // EXTENSIBLE_UI
|