My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_api.cpp 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**************
  23. * ui_api.cpp *
  24. **************/
  25. /****************************************************************************
  26. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  27. * *
  28. * This program is free software: you can redistribute it and/or modify *
  29. * it under the terms of the GNU General Public License as published by *
  30. * the Free Software Foundation, either version 3 of the License, or *
  31. * (at your option) any later version. *
  32. * *
  33. * This program is distributed in the hope that it will be useful, *
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  36. * GNU General Public License for more details. *
  37. * *
  38. * To view a copy of the GNU General Public License, go to the following *
  39. * location: <https://www.gnu.org/licenses/>. *
  40. ****************************************************************************/
  41. #include "../../inc/MarlinConfigPre.h"
  42. #if ENABLED(EXTENSIBLE_UI)
  43. #include "../marlinui.h"
  44. #include "../../gcode/queue.h"
  45. #include "../../gcode/gcode.h"
  46. #include "../../module/motion.h"
  47. #include "../../module/planner.h"
  48. #include "../../module/probe.h"
  49. #include "../../module/temperature.h"
  50. #include "../../module/printcounter.h"
  51. #include "../../libs/duration_t.h"
  52. #include "../../HAL/shared/Delay.h"
  53. #include "../../MarlinCore.h"
  54. #include "../../sd/cardreader.h"
  55. #if ENABLED(PRINTCOUNTER)
  56. #include "../../core/utility.h"
  57. #include "../../libs/numtostr.h"
  58. #endif
  59. #if HAS_MULTI_EXTRUDER
  60. #include "../../module/tool_change.h"
  61. #endif
  62. #if ENABLED(EMERGENCY_PARSER)
  63. #include "../../feature/e_parser.h"
  64. #endif
  65. #if HAS_TRINAMIC_CONFIG
  66. #include "../../feature/tmc_util.h"
  67. #include "../../module/stepper/indirection.h"
  68. #endif
  69. #include "ui_api.h"
  70. #if ENABLED(BACKLASH_GCODE)
  71. #include "../../feature/backlash.h"
  72. #endif
  73. #if HAS_LEVELING
  74. #include "../../feature/bedlevel/bedlevel.h"
  75. #endif
  76. #if HAS_FILAMENT_SENSOR
  77. #include "../../feature/runout.h"
  78. #endif
  79. #if ENABLED(CASE_LIGHT_ENABLE)
  80. #include "../../feature/caselight.h"
  81. #endif
  82. #if ENABLED(POWER_LOSS_RECOVERY)
  83. #include "../../feature/powerloss.h"
  84. #endif
  85. #if ENABLED(BABYSTEPPING)
  86. #include "../../feature/babystep.h"
  87. #endif
  88. #if ENABLED(HOST_PROMPT_SUPPORT)
  89. #include "../../feature/host_actions.h"
  90. #endif
  91. #if M600_PURGE_MORE_RESUMABLE
  92. #include "../../feature/pause.h"
  93. #endif
  94. namespace ExtUI {
  95. static struct {
  96. uint8_t printer_killed : 1;
  97. #if ENABLED(JOYSTICK)
  98. uint8_t jogging : 1;
  99. #endif
  100. } flags;
  101. #ifdef __SAM3X8E__
  102. /**
  103. * Implement a special millis() to allow time measurement
  104. * within an ISR (such as when the printer is killed).
  105. *
  106. * To keep proper time, must be called at least every 1s.
  107. */
  108. uint32_t safe_millis() {
  109. // Not killed? Just call millis()
  110. if (!flags.printer_killed) return millis();
  111. static uint32_t currTimeHI = 0; /* Current time */
  112. // Machine was killed, reinit SysTick so we are able to compute time without ISRs
  113. if (currTimeHI == 0) {
  114. // Get the last time the Arduino time computed (from CMSIS) and convert it to SysTick
  115. currTimeHI = uint32_t((GetTickCount() * uint64_t(F_CPU / 8000)) >> 24);
  116. // Reinit the SysTick timer to maximize its period
  117. SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; // get the full range for the systick timer
  118. SysTick->VAL = 0; // Load the SysTick Counter Value
  119. SysTick->CTRL = // MCLK/8 as source
  120. // No interrupts
  121. SysTick_CTRL_ENABLE_Msk; // Enable SysTick Timer
  122. }
  123. // Check if there was a timer overflow from the last read
  124. if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) {
  125. // There was. This means (SysTick_LOAD_RELOAD_Msk * 1000 * 8)/F_CPU ms has elapsed
  126. currTimeHI++;
  127. }
  128. // Calculate current time in milliseconds
  129. uint32_t currTimeLO = SysTick_LOAD_RELOAD_Msk - SysTick->VAL; // (in MCLK/8)
  130. uint64_t currTime = ((uint64_t)currTimeLO) | (((uint64_t)currTimeHI) << 24);
  131. // The ms count is
  132. return (uint32_t)(currTime / (F_CPU / 8000));
  133. }
  134. #endif // __SAM3X8E__
  135. void delay_us(uint32_t us) { DELAY_US(us); }
  136. void delay_ms(uint32_t ms) {
  137. if (flags.printer_killed)
  138. DELAY_US(ms * 1000);
  139. else
  140. safe_delay(ms);
  141. }
  142. void yield() {
  143. if (!flags.printer_killed) thermalManager.manage_heater();
  144. }
  145. void enableHeater(const extruder_t extruder) {
  146. #if HAS_HOTEND && HEATER_IDLE_HANDLER
  147. thermalManager.reset_hotend_idle_timer(extruder - E0);
  148. #else
  149. UNUSED(extruder);
  150. #endif
  151. }
  152. void enableHeater(const heater_t heater) {
  153. #if HEATER_IDLE_HANDLER
  154. switch (heater) {
  155. #if HAS_HEATED_BED
  156. case BED: thermalManager.reset_bed_idle_timer(); return;
  157. #endif
  158. #if HAS_HEATED_CHAMBER
  159. case CHAMBER: return; // Chamber has no idle timer
  160. #endif
  161. #if HAS_COOLER
  162. case COOLER: return; // Cooler has no idle timer
  163. #endif
  164. default:
  165. TERN_(HAS_HOTEND, thermalManager.reset_hotend_idle_timer(heater - H0));
  166. break;
  167. }
  168. #else
  169. UNUSED(heater);
  170. #endif
  171. }
  172. #if ENABLED(JOYSTICK)
  173. /**
  174. * Jogs in the direction given by the vector (dx, dy, dz).
  175. * The values range from -1 to 1 mapping to the maximum
  176. * feedrate for an axis.
  177. *
  178. * The axis will continue to jog until this function is
  179. * called with all zeros.
  180. */
  181. void jog(const xyz_float_t &dir) {
  182. // The "destination" variable is used as a scratchpad in
  183. // Marlin by GCODE routines, but should remain untouched
  184. // during manual jogging, allowing us to reuse the space
  185. // for our direction vector.
  186. destination = dir;
  187. flags.jogging = !NEAR_ZERO(dir.x) || !NEAR_ZERO(dir.y) || !NEAR_ZERO(dir.z);
  188. }
  189. // Called by the polling routine in "joystick.cpp"
  190. void _joystick_update(xyz_float_t &norm_jog) {
  191. if (flags.jogging) {
  192. #define OUT_OF_RANGE(VALUE) (VALUE < -1.0f || VALUE > 1.0f)
  193. if (OUT_OF_RANGE(destination.x) || OUT_OF_RANGE(destination.y) || OUT_OF_RANGE(destination.z)) {
  194. // If destination on any axis is out of range, it
  195. // probably means the UI forgot to stop jogging and
  196. // ran GCODE that wrote a position to destination.
  197. // To prevent a disaster, stop jogging.
  198. flags.jogging = false;
  199. return;
  200. }
  201. norm_jog = destination;
  202. }
  203. }
  204. #endif
  205. bool isHeaterIdle(const extruder_t extruder) {
  206. #if HAS_HOTEND && HEATER_IDLE_HANDLER
  207. return thermalManager.heater_idle[extruder - E0].timed_out;
  208. #else
  209. UNUSED(extruder);
  210. return false;
  211. #endif
  212. }
  213. bool isHeaterIdle(const heater_t heater) {
  214. #if HEATER_IDLE_HANDLER
  215. switch (heater) {
  216. #if HAS_HEATED_BED
  217. case BED: return thermalManager.heater_idle[thermalManager.IDLE_INDEX_BED].timed_out;
  218. #endif
  219. #if HAS_HEATED_CHAMBER
  220. case CHAMBER: return false; // Chamber has no idle timer
  221. #endif
  222. default:
  223. return TERN0(HAS_HOTEND, thermalManager.heater_idle[heater - H0].timed_out);
  224. }
  225. #else
  226. UNUSED(heater);
  227. return false;
  228. #endif
  229. }
  230. #ifdef TOUCH_UI_LCD_TEMP_SCALING
  231. #define GET_TEMP_ADJUSTMENT(A) (float(A) / (TOUCH_UI_LCD_TEMP_SCALING))
  232. #else
  233. #define GET_TEMP_ADJUSTMENT(A) A
  234. #endif
  235. celsius_float_t getActualTemp_celsius(const heater_t heater) {
  236. switch (heater) {
  237. #if HAS_HEATED_BED
  238. case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degBed());
  239. #endif
  240. #if HAS_HEATED_CHAMBER
  241. case CHAMBER: return GET_TEMP_ADJUSTMENT(thermalManager.degChamber());
  242. #endif
  243. default: return GET_TEMP_ADJUSTMENT(thermalManager.degHotend(heater - H0));
  244. }
  245. }
  246. celsius_float_t getActualTemp_celsius(const extruder_t extruder) {
  247. return GET_TEMP_ADJUSTMENT(thermalManager.degHotend(extruder - E0));
  248. }
  249. celsius_float_t getTargetTemp_celsius(const heater_t heater) {
  250. switch (heater) {
  251. #if HAS_HEATED_BED
  252. case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetBed());
  253. #endif
  254. #if HAS_HEATED_CHAMBER
  255. case CHAMBER: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetChamber());
  256. #endif
  257. default: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetHotend(heater - H0));
  258. }
  259. }
  260. celsius_float_t getTargetTemp_celsius(const extruder_t extruder) {
  261. return GET_TEMP_ADJUSTMENT(thermalManager.degTargetHotend(extruder - E0));
  262. }
  263. float getTargetFan_percent(const fan_t fan) {
  264. UNUSED(fan);
  265. return TERN0(HAS_FAN, thermalManager.fanSpeedPercent(fan - FAN0));
  266. }
  267. float getActualFan_percent(const fan_t fan) {
  268. UNUSED(fan);
  269. return TERN0(HAS_FAN, thermalManager.scaledFanSpeedPercent(fan - FAN0));
  270. }
  271. float getAxisPosition_mm(const axis_t axis) {
  272. return current_position[axis];
  273. }
  274. float getAxisPosition_mm(const extruder_t extruder) {
  275. const extruder_t old_tool = getActiveTool();
  276. setActiveTool(extruder, true);
  277. const float epos = TERN0(JOYSTICK, flags.jogging) ? destination.e : current_position.e;
  278. setActiveTool(old_tool, true);
  279. return epos;
  280. }
  281. void setAxisPosition_mm(const_float_t position, const axis_t axis, const feedRate_t feedrate/*=0*/) {
  282. // Get motion limit from software endstops, if any
  283. float min, max;
  284. soft_endstop.get_manual_axis_limits((AxisEnum)axis, min, max);
  285. // Delta limits XY based on the current offset from center
  286. // This assumes the center is 0,0
  287. #if ENABLED(DELTA)
  288. if (axis != Z) {
  289. max = SQRT(sq(float(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y - axis])); // (Y - axis) == the other axis
  290. min = -max;
  291. }
  292. #endif
  293. current_position[axis] = constrain(position, min, max);
  294. line_to_current_position(feedrate ?: manual_feedrate_mm_s[axis]);
  295. }
  296. void setAxisPosition_mm(const_float_t position, const extruder_t extruder, const feedRate_t feedrate/*=0*/) {
  297. setActiveTool(extruder, true);
  298. current_position.e = position;
  299. line_to_current_position(feedrate ?: manual_feedrate_mm_s.e);
  300. }
  301. void setActiveTool(const extruder_t extruder, bool no_move) {
  302. #if HAS_MULTI_EXTRUDER
  303. const uint8_t e = extruder - E0;
  304. if (e != active_extruder) tool_change(e, no_move);
  305. active_extruder = e;
  306. #else
  307. UNUSED(extruder);
  308. UNUSED(no_move);
  309. #endif
  310. }
  311. extruder_t getTool(const uint8_t extruder) {
  312. switch (extruder) {
  313. default:
  314. case 0: return E0; case 1: return E1; case 2: return E2; case 3: return E3;
  315. case 4: return E4; case 5: return E5; case 6: return E6; case 7: return E7;
  316. }
  317. }
  318. extruder_t getActiveTool() { return getTool(active_extruder); }
  319. bool isMoving() { return planner.has_blocks_queued(); }
  320. bool canMove(const axis_t axis) {
  321. switch (axis) {
  322. #if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
  323. case X: return axis_should_home(X_AXIS);
  324. OPTCODE(HAS_Y_AXIS, case Y: return axis_should_home(Y_AXIS))
  325. OPTCODE(HAS_Z_AXIS, case Z: return axis_should_home(Z_AXIS))
  326. #else
  327. case X: case Y: case Z: return true;
  328. #endif
  329. default: return false;
  330. }
  331. }
  332. bool canMove(const extruder_t extruder) {
  333. return !thermalManager.tooColdToExtrude(extruder - E0);
  334. }
  335. #if ENABLED(HOST_KEEPALIVE_FEATURE)
  336. GcodeSuite::MarlinBusyState getHostKeepaliveState() { return gcode.busy_state; }
  337. bool getHostKeepaliveIsPaused() { return gcode.host_keepalive_is_paused(); }
  338. #endif
  339. #if HAS_SOFTWARE_ENDSTOPS
  340. bool getSoftEndstopState() { return soft_endstop._enabled; }
  341. void setSoftEndstopState(const bool value) { soft_endstop._enabled = value; }
  342. #endif
  343. #if HAS_TRINAMIC_CONFIG
  344. float getAxisCurrent_mA(const axis_t axis) {
  345. switch (axis) {
  346. #if AXIS_IS_TMC(X)
  347. case X: return stepperX.getMilliamps();
  348. #endif
  349. #if AXIS_IS_TMC(Y)
  350. case Y: return stepperY.getMilliamps();
  351. #endif
  352. #if AXIS_IS_TMC(Z)
  353. case Z: return stepperZ.getMilliamps();
  354. #endif
  355. #if AXIS_IS_TMC(I)
  356. case I: return stepperI.getMilliamps();
  357. #endif
  358. #if AXIS_IS_TMC(J)
  359. case J: return stepperJ.getMilliamps();
  360. #endif
  361. #if AXIS_IS_TMC(K)
  362. case K: return stepperK.getMilliamps();
  363. #endif
  364. #if AXIS_IS_TMC(U)
  365. case U: return stepperU.getMilliamps();
  366. #endif
  367. #if AXIS_IS_TMC(V)
  368. case V: return stepperV.getMilliamps();
  369. #endif
  370. #if AXIS_IS_TMC(W)
  371. case W: return stepperW.getMilliamps();
  372. #endif
  373. #if AXIS_IS_TMC(X2)
  374. case X2: return stepperX2.getMilliamps();
  375. #endif
  376. #if AXIS_IS_TMC(Y2)
  377. case Y2: return stepperY2.getMilliamps();
  378. #endif
  379. #if AXIS_IS_TMC(Z2)
  380. case Z2: return stepperZ2.getMilliamps();
  381. #endif
  382. #if AXIS_IS_TMC(Z3)
  383. case Z3: return stepperZ3.getMilliamps();
  384. #endif
  385. #if AXIS_IS_TMC(Z4)
  386. case Z4: return stepperZ4.getMilliamps();
  387. #endif
  388. default: return NAN;
  389. };
  390. }
  391. float getAxisCurrent_mA(const extruder_t extruder) {
  392. switch (extruder) {
  393. #if AXIS_IS_TMC(E0)
  394. case E0: return stepperE0.getMilliamps();
  395. #endif
  396. #if AXIS_IS_TMC(E1)
  397. case E1: return stepperE1.getMilliamps();
  398. #endif
  399. #if AXIS_IS_TMC(E2)
  400. case E2: return stepperE2.getMilliamps();
  401. #endif
  402. #if AXIS_IS_TMC(E3)
  403. case E3: return stepperE3.getMilliamps();
  404. #endif
  405. #if AXIS_IS_TMC(E4)
  406. case E4: return stepperE4.getMilliamps();
  407. #endif
  408. #if AXIS_IS_TMC(E5)
  409. case E5: return stepperE5.getMilliamps();
  410. #endif
  411. #if AXIS_IS_TMC(E6)
  412. case E6: return stepperE6.getMilliamps();
  413. #endif
  414. #if AXIS_IS_TMC(E7)
  415. case E7: return stepperE7.getMilliamps();
  416. #endif
  417. default: return NAN;
  418. };
  419. }
  420. void setAxisCurrent_mA(const_float_t mA, const axis_t axis) {
  421. switch (axis) {
  422. #if AXIS_IS_TMC(X)
  423. case X: stepperX.rms_current(constrain(mA, 400, 1500)); break;
  424. #endif
  425. #if AXIS_IS_TMC(Y)
  426. case Y: stepperY.rms_current(constrain(mA, 400, 1500)); break;
  427. #endif
  428. #if AXIS_IS_TMC(Z)
  429. case Z: stepperZ.rms_current(constrain(mA, 400, 1500)); break;
  430. #endif
  431. #if AXIS_IS_TMC(I)
  432. case I: stepperI.rms_current(constrain(mA, 400, 1500)); break;
  433. #endif
  434. #if AXIS_IS_TMC(J)
  435. case J: stepperJ.rms_current(constrain(mA, 400, 1500)); break;
  436. #endif
  437. #if AXIS_IS_TMC(K)
  438. case K: stepperK.rms_current(constrain(mA, 400, 1500)); break;
  439. #endif
  440. #if AXIS_IS_TMC(U)
  441. case U: stepperU.rms_current(constrain(mA, 400, 1500)); break;
  442. #endif
  443. #if AXIS_IS_TMC(V)
  444. case V: stepperV.rms_current(constrain(mA, 400, 1500)); break;
  445. #endif
  446. #if AXIS_IS_TMC(W)
  447. case W: stepperW.rms_current(constrain(mA, 400, 1500)); break;
  448. #endif
  449. #if AXIS_IS_TMC(X2)
  450. case X2: stepperX2.rms_current(constrain(mA, 400, 1500)); break;
  451. #endif
  452. #if AXIS_IS_TMC(Y2)
  453. case Y2: stepperY2.rms_current(constrain(mA, 400, 1500)); break;
  454. #endif
  455. #if AXIS_IS_TMC(Z2)
  456. case Z2: stepperZ2.rms_current(constrain(mA, 400, 1500)); break;
  457. #endif
  458. #if AXIS_IS_TMC(Z3)
  459. case Z3: stepperZ3.rms_current(constrain(mA, 400, 1500)); break;
  460. #endif
  461. #if AXIS_IS_TMC(Z4)
  462. case Z4: stepperZ4.rms_current(constrain(mA, 400, 1500)); break;
  463. #endif
  464. default: break;
  465. };
  466. }
  467. void setAxisCurrent_mA(const_float_t mA, const extruder_t extruder) {
  468. switch (extruder) {
  469. #if AXIS_IS_TMC(E0)
  470. case E0: stepperE0.rms_current(constrain(mA, 400, 1500)); break;
  471. #endif
  472. #if AXIS_IS_TMC(E1)
  473. case E1: stepperE1.rms_current(constrain(mA, 400, 1500)); break;
  474. #endif
  475. #if AXIS_IS_TMC(E2)
  476. case E2: stepperE2.rms_current(constrain(mA, 400, 1500)); break;
  477. #endif
  478. #if AXIS_IS_TMC(E3)
  479. case E3: stepperE3.rms_current(constrain(mA, 400, 1500)); break;
  480. #endif
  481. #if AXIS_IS_TMC(E4)
  482. case E4: stepperE4.rms_current(constrain(mA, 400, 1500)); break;
  483. #endif
  484. #if AXIS_IS_TMC(E5)
  485. case E5: stepperE5.rms_current(constrain(mA, 400, 1500)); break;
  486. #endif
  487. #if AXIS_IS_TMC(E6)
  488. case E6: stepperE6.rms_current(constrain(mA, 400, 1500)); break;
  489. #endif
  490. #if AXIS_IS_TMC(E7)
  491. case E7: stepperE7.rms_current(constrain(mA, 400, 1500)); break;
  492. #endif
  493. default: break;
  494. };
  495. }
  496. int getTMCBumpSensitivity(const axis_t axis) {
  497. switch (axis) {
  498. OPTCODE(X_SENSORLESS, case X: return stepperX.homing_threshold())
  499. OPTCODE(Y_SENSORLESS, case Y: return stepperY.homing_threshold())
  500. OPTCODE(Z_SENSORLESS, case Z: return stepperZ.homing_threshold())
  501. OPTCODE(I_SENSORLESS, case I: return stepperI.homing_threshold())
  502. OPTCODE(J_SENSORLESS, case J: return stepperJ.homing_threshold())
  503. OPTCODE(K_SENSORLESS, case K: return stepperK.homing_threshold())
  504. OPTCODE(U_SENSORLESS, case U: return stepperU.homing_threshold())
  505. OPTCODE(V_SENSORLESS, case V: return stepperV.homing_threshold())
  506. OPTCODE(W_SENSORLESS, case W: return stepperW.homing_threshold())
  507. OPTCODE(X2_SENSORLESS, case X2: return stepperX2.homing_threshold())
  508. OPTCODE(Y2_SENSORLESS, case Y2: return stepperY2.homing_threshold())
  509. OPTCODE(Z2_SENSORLESS, case Z2: return stepperZ2.homing_threshold())
  510. OPTCODE(Z3_SENSORLESS, case Z3: return stepperZ3.homing_threshold())
  511. OPTCODE(Z4_SENSORLESS, case Z4: return stepperZ4.homing_threshold())
  512. default: return 0;
  513. }
  514. }
  515. void setTMCBumpSensitivity(const_float_t value, const axis_t axis) {
  516. switch (axis) {
  517. #if X_SENSORLESS
  518. case X: stepperX.homing_threshold(value); break;
  519. #endif
  520. #if Y_SENSORLESS
  521. case Y: stepperY.homing_threshold(value); break;
  522. #endif
  523. #if Z_SENSORLESS
  524. case Z: stepperZ.homing_threshold(value); break;
  525. #endif
  526. #if I_SENSORLESS
  527. case I: stepperI.homing_threshold(value); break;
  528. #endif
  529. #if J_SENSORLESS
  530. case J: stepperJ.homing_threshold(value); break;
  531. #endif
  532. #if K_SENSORLESS
  533. case K: stepperK.homing_threshold(value); break;
  534. #endif
  535. #if U_SENSORLESS
  536. case U: stepperU.homing_threshold(value); break;
  537. #endif
  538. #if V_SENSORLESS
  539. case V: stepperV.homing_threshold(value); break;
  540. #endif
  541. #if W_SENSORLESS
  542. case W: stepperW.homing_threshold(value); break;
  543. #endif
  544. #if X2_SENSORLESS
  545. case X2: stepperX2.homing_threshold(value); break;
  546. #endif
  547. #if Y2_SENSORLESS
  548. case Y2: stepperY2.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. default: break;
  560. }
  561. UNUSED(value);
  562. }
  563. #endif
  564. float getAxisSteps_per_mm(const axis_t axis) {
  565. return planner.settings.axis_steps_per_mm[axis];
  566. }
  567. float getAxisSteps_per_mm(const extruder_t extruder) {
  568. UNUSED(extruder);
  569. return planner.settings.axis_steps_per_mm[E_AXIS_N(extruder - E0)];
  570. }
  571. void setAxisSteps_per_mm(const_float_t value, const axis_t axis) {
  572. planner.settings.axis_steps_per_mm[axis] = value;
  573. planner.refresh_positioning();
  574. }
  575. void setAxisSteps_per_mm(const_float_t value, const extruder_t extruder) {
  576. UNUSED(extruder);
  577. planner.settings.axis_steps_per_mm[E_AXIS_N(extruder - E0)] = value;
  578. planner.refresh_positioning();
  579. }
  580. feedRate_t getAxisMaxFeedrate_mm_s(const axis_t axis) {
  581. return planner.settings.max_feedrate_mm_s[axis];
  582. }
  583. feedRate_t getAxisMaxFeedrate_mm_s(const extruder_t extruder) {
  584. UNUSED(extruder);
  585. return planner.settings.max_feedrate_mm_s[E_AXIS_N(extruder - E0)];
  586. }
  587. void setAxisMaxFeedrate_mm_s(const feedRate_t value, const axis_t axis) {
  588. planner.set_max_feedrate((AxisEnum)axis, value);
  589. }
  590. void setAxisMaxFeedrate_mm_s(const feedRate_t value, const extruder_t extruder) {
  591. UNUSED(extruder);
  592. planner.set_max_feedrate(E_AXIS_N(extruder - E0), value);
  593. }
  594. float getAxisMaxAcceleration_mm_s2(const axis_t axis) {
  595. return planner.settings.max_acceleration_mm_per_s2[axis];
  596. }
  597. float getAxisMaxAcceleration_mm_s2(const extruder_t extruder) {
  598. UNUSED(extruder);
  599. return planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(extruder - E0)];
  600. }
  601. void setAxisMaxAcceleration_mm_s2(const_float_t value, const axis_t axis) {
  602. planner.set_max_acceleration((AxisEnum)axis, value);
  603. }
  604. void setAxisMaxAcceleration_mm_s2(const_float_t value, const extruder_t extruder) {
  605. UNUSED(extruder);
  606. planner.set_max_acceleration(E_AXIS_N(extruder - E0), value);
  607. }
  608. #if HAS_FILAMENT_SENSOR
  609. bool getFilamentRunoutEnabled() { return runout.enabled; }
  610. void setFilamentRunoutEnabled(const bool value) { runout.enabled = value; }
  611. bool getFilamentRunoutState() { return runout.filament_ran_out; }
  612. void setFilamentRunoutState(const bool value) { runout.filament_ran_out = value; }
  613. #if HAS_FILAMENT_RUNOUT_DISTANCE
  614. float getFilamentRunoutDistance_mm() { return runout.runout_distance(); }
  615. void setFilamentRunoutDistance_mm(const_float_t value) { runout.set_runout_distance(constrain(value, 0, 999)); }
  616. #endif
  617. #endif
  618. #if ENABLED(CASE_LIGHT_ENABLE)
  619. bool getCaseLightState() { return caselight.on; }
  620. void setCaseLightState(const bool value) {
  621. caselight.on = value;
  622. caselight.update_enabled();
  623. }
  624. #if CASELIGHT_USES_BRIGHTNESS
  625. float getCaseLightBrightness_percent() { return ui8_to_percent(caselight.brightness); }
  626. void setCaseLightBrightness_percent(const_float_t value) {
  627. caselight.brightness = map(constrain(value, 0, 100), 0, 100, 0, 255);
  628. caselight.update_brightness();
  629. }
  630. #endif
  631. #endif
  632. #if ENABLED(POWER_LOSS_RECOVERY)
  633. bool getPowerLossRecoveryEnabled() { return recovery.enabled; }
  634. void setPowerLossRecoveryEnabled(const bool value) { recovery.enable(value); }
  635. #endif
  636. #if ENABLED(LIN_ADVANCE)
  637. float getLinearAdvance_mm_mm_s(const extruder_t extruder) {
  638. return (extruder < EXTRUDERS) ? planner.extruder_advance_K[extruder - E0] : 0;
  639. }
  640. void setLinearAdvance_mm_mm_s(const_float_t value, const extruder_t extruder) {
  641. if (extruder < EXTRUDERS)
  642. planner.extruder_advance_K[extruder - E0] = constrain(value, 0, 10);
  643. }
  644. #endif
  645. #if HAS_JUNCTION_DEVIATION
  646. float getJunctionDeviation_mm() { return planner.junction_deviation_mm; }
  647. void setJunctionDeviation_mm(const_float_t value) {
  648. planner.junction_deviation_mm = constrain(value, 0.001, 0.3);
  649. TERN_(LIN_ADVANCE, planner.recalculate_max_e_jerk());
  650. }
  651. #else
  652. float getAxisMaxJerk_mm_s(const axis_t axis) { return planner.max_jerk[axis]; }
  653. float getAxisMaxJerk_mm_s(const extruder_t) { return planner.max_jerk.e; }
  654. void setAxisMaxJerk_mm_s(const_float_t value, const axis_t axis) { planner.set_max_jerk((AxisEnum)axis, value); }
  655. void setAxisMaxJerk_mm_s(const_float_t value, const extruder_t) { planner.set_max_jerk(E_AXIS, value); }
  656. #endif
  657. #if ENABLED(DUAL_X_CARRIAGE)
  658. uint8_t getIDEX_Mode() { return dual_x_carriage_mode; }
  659. #endif
  660. #if HAS_PREHEAT
  661. uint16_t getMaterial_preset_E(const uint16_t index) { return ui.material_preset[index].hotend_temp; }
  662. #if HAS_HEATED_BED
  663. uint16_t getMaterial_preset_B(const uint16_t index) { return ui.material_preset[index].bed_temp; }
  664. #endif
  665. #endif
  666. feedRate_t getFeedrate_mm_s() { return feedrate_mm_s; }
  667. int16_t getFlow_percent(const extruder_t extr) { return planner.flow_percentage[extr]; }
  668. feedRate_t getMinFeedrate_mm_s() { return planner.settings.min_feedrate_mm_s; }
  669. feedRate_t getMinTravelFeedrate_mm_s() { return planner.settings.min_travel_feedrate_mm_s; }
  670. float getPrintingAcceleration_mm_s2() { return planner.settings.acceleration; }
  671. float getRetractAcceleration_mm_s2() { return planner.settings.retract_acceleration; }
  672. float getTravelAcceleration_mm_s2() { return planner.settings.travel_acceleration; }
  673. void setFeedrate_mm_s(const feedRate_t fr) { feedrate_mm_s = fr; }
  674. void setFlow_percent(const int16_t flow, const extruder_t extr) { planner.set_flow(extr, flow); }
  675. void setMinFeedrate_mm_s(const feedRate_t fr) { planner.settings.min_feedrate_mm_s = fr; }
  676. void setMinTravelFeedrate_mm_s(const feedRate_t fr) { planner.settings.min_travel_feedrate_mm_s = fr; }
  677. void setPrintingAcceleration_mm_s2(const_float_t acc) { planner.settings.acceleration = acc; }
  678. void setRetractAcceleration_mm_s2(const_float_t acc) { planner.settings.retract_acceleration = acc; }
  679. void setTravelAcceleration_mm_s2(const_float_t acc) { planner.settings.travel_acceleration = acc; }
  680. #if ENABLED(BABYSTEPPING)
  681. bool babystepAxis_steps(const int16_t steps, const axis_t axis) {
  682. switch (axis) {
  683. #if ENABLED(BABYSTEP_XY)
  684. case X: babystep.add_steps(X_AXIS, steps); break;
  685. #if HAS_Y_AXIS
  686. case Y: babystep.add_steps(Y_AXIS, steps); break;
  687. #endif
  688. #endif
  689. #if HAS_Z_AXIS
  690. case Z: babystep.add_steps(Z_AXIS, steps); break;
  691. #endif
  692. default: return false;
  693. };
  694. return true;
  695. }
  696. /**
  697. * This function adjusts an axis during a print.
  698. *
  699. * When linked_nozzles is false, each nozzle in a multi-nozzle
  700. * printer can be babystepped independently of the others. This
  701. * lets the user to fine tune the Z-offset and Nozzle Offsets
  702. * while observing the first layer of a print, regardless of
  703. * what nozzle is printing.
  704. */
  705. void smartAdjustAxis_steps(const int16_t steps, const axis_t axis, bool linked_nozzles) {
  706. const float mm = steps * planner.mm_per_step[axis];
  707. UNUSED(mm);
  708. if (!babystepAxis_steps(steps, axis)) return;
  709. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  710. // Make it so babystepping in Z adjusts the Z probe offset.
  711. if (axis == Z && TERN1(HAS_MULTI_EXTRUDER, (linked_nozzles || active_extruder == 0)))
  712. probe.offset.z += mm;
  713. #endif
  714. #if HAS_MULTI_EXTRUDER && HAS_HOTEND_OFFSET
  715. /**
  716. * When linked_nozzles is false, as an axis is babystepped
  717. * adjust the hotend offsets so that the other nozzles are
  718. * unaffected by the babystepping of the active nozzle.
  719. */
  720. if (!linked_nozzles) {
  721. HOTEND_LOOP()
  722. if (e != active_extruder)
  723. hotend_offset[e][axis] += mm;
  724. normalizeNozzleOffset(X);
  725. TERN_(HAS_Y_AXIS, normalizeNozzleOffset(Y));
  726. TERN_(HAS_Z_AXIS, normalizeNozzleOffset(Z));
  727. }
  728. #else
  729. UNUSED(linked_nozzles);
  730. #endif
  731. }
  732. /**
  733. * Converts a mm displacement to a number of whole number of
  734. * steps that is at least mm long.
  735. */
  736. int16_t mmToWholeSteps(const_float_t mm, const axis_t axis) {
  737. const float steps = mm / planner.mm_per_step[axis];
  738. return steps > 0 ? CEIL(steps) : FLOOR(steps);
  739. }
  740. float mmFromWholeSteps(int16_t steps, const axis_t axis) {
  741. return steps * planner.mm_per_step[axis];
  742. }
  743. #endif // BABYSTEPPING
  744. float getZOffset_mm() {
  745. return (0.0f
  746. #if HAS_BED_PROBE
  747. + probe.offset.z
  748. #elif ENABLED(BABYSTEP_DISPLAY_TOTAL)
  749. + planner.mm_per_step[Z_AXIS] * babystep.axis_total[BS_AXIS_IND(Z_AXIS)]
  750. #endif
  751. );
  752. }
  753. void setZOffset_mm(const_float_t value) {
  754. #if HAS_BED_PROBE
  755. if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX))
  756. probe.offset.z = value;
  757. #elif ENABLED(BABYSTEP_DISPLAY_TOTAL)
  758. babystep.add_mm(Z_AXIS, value - getZOffset_mm());
  759. #else
  760. UNUSED(value);
  761. #endif
  762. }
  763. #if HAS_HOTEND_OFFSET
  764. float getNozzleOffset_mm(const axis_t axis, const extruder_t extruder) {
  765. if (extruder - E0 >= HOTENDS) return 0;
  766. return hotend_offset[extruder - E0][axis];
  767. }
  768. void setNozzleOffset_mm(const_float_t value, const axis_t axis, const extruder_t extruder) {
  769. if (extruder - E0 >= HOTENDS) return;
  770. hotend_offset[extruder - E0][axis] = value;
  771. }
  772. /**
  773. * The UI should call this if needs to guarantee the first
  774. * nozzle offset is zero (such as when it doesn't allow the
  775. * user to edit the offset the first nozzle).
  776. */
  777. void normalizeNozzleOffset(const axis_t axis) {
  778. const float offs = hotend_offset[0][axis];
  779. HOTEND_LOOP() hotend_offset[e][axis] -= offs;
  780. }
  781. #endif // HAS_HOTEND_OFFSET
  782. #if HAS_BED_PROBE
  783. float getProbeOffset_mm(const axis_t axis) { return probe.offset.pos[axis]; }
  784. void setProbeOffset_mm(const_float_t val, const axis_t axis) { probe.offset.pos[axis] = val; }
  785. #endif
  786. #if ENABLED(BACKLASH_GCODE)
  787. float getAxisBacklash_mm(const axis_t axis) { return backlash.get_distance_mm((AxisEnum)axis); }
  788. void setAxisBacklash_mm(const_float_t value, const axis_t axis)
  789. { backlash.set_distance_mm((AxisEnum)axis, constrain(value,0,5)); }
  790. float getBacklashCorrection_percent() { return backlash.get_correction() * 100.0f; }
  791. void setBacklashCorrection_percent(const_float_t value) { backlash.set_correction(constrain(value, 0, 100) / 100.0f); }
  792. #ifdef BACKLASH_SMOOTHING_MM
  793. float getBacklashSmoothing_mm() { return backlash.get_smoothing_mm(); }
  794. void setBacklashSmoothing_mm(const_float_t value) { backlash.set_smoothing_mm(constrain(value, 0, 999)); }
  795. #endif
  796. #endif
  797. uint32_t getProgress_seconds_elapsed() {
  798. const duration_t elapsed = print_job_timer.duration();
  799. return elapsed.value;
  800. }
  801. #if HAS_LEVELING
  802. bool getLevelingActive() { return planner.leveling_active; }
  803. void setLevelingActive(const bool state) { set_bed_leveling_enabled(state); }
  804. bool getMeshValid() { return leveling_is_valid(); }
  805. #if HAS_MESH
  806. bed_mesh_t& getMeshArray() { return bedlevel.z_values; }
  807. float getMeshPoint(const xy_uint8_t &pos) { return bedlevel.z_values[pos.x][pos.y]; }
  808. void setMeshPoint(const xy_uint8_t &pos, const_float_t zoff) {
  809. if (WITHIN(pos.x, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(pos.y, 0, (GRID_MAX_POINTS_Y) - 1)) {
  810. bedlevel.z_values[pos.x][pos.y] = zoff;
  811. TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
  812. }
  813. }
  814. void moveToMeshPoint(const xy_uint8_t &pos, const_float_t z) {
  815. #if EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
  816. const feedRate_t old_feedrate = feedrate_mm_s;
  817. const float x_target = MESH_MIN_X + pos.x * (MESH_X_DIST),
  818. y_target = MESH_MIN_Y + pos.y * (MESH_Y_DIST);
  819. if (x_target != current_position.x || y_target != current_position.y) {
  820. // If moving across bed, raise nozzle to safe height over bed
  821. feedrate_mm_s = Z_PROBE_FEEDRATE_FAST;
  822. destination = current_position;
  823. destination.z = Z_CLEARANCE_BETWEEN_PROBES;
  824. prepare_line_to_destination();
  825. feedrate_mm_s = XY_PROBE_FEEDRATE;
  826. destination.x = x_target;
  827. destination.y = y_target;
  828. prepare_line_to_destination();
  829. }
  830. feedrate_mm_s = Z_PROBE_FEEDRATE_FAST;
  831. destination.z = z;
  832. prepare_line_to_destination();
  833. feedrate_mm_s = old_feedrate;
  834. #else
  835. UNUSED(pos);
  836. UNUSED(z);
  837. #endif
  838. }
  839. #endif // HAS_MESH
  840. #endif // HAS_LEVELING
  841. #if ENABLED(HOST_PROMPT_SUPPORT)
  842. void setHostResponse(const uint8_t response) { hostui.handle_response(response); }
  843. #endif
  844. #if ENABLED(PRINTCOUNTER)
  845. char* getFailedPrints_str(char buffer[21]) { strcpy(buffer,i16tostr3left(print_job_timer.getStats().totalPrints - print_job_timer.getStats().finishedPrints)); return buffer; }
  846. char* getTotalPrints_str(char buffer[21]) { strcpy(buffer,i16tostr3left(print_job_timer.getStats().totalPrints)); return buffer; }
  847. char* getFinishedPrints_str(char buffer[21]) { strcpy(buffer,i16tostr3left(print_job_timer.getStats().finishedPrints)); return buffer; }
  848. char* getTotalPrintTime_str(char buffer[21]) { return duration_t(print_job_timer.getStats().printTime).toString(buffer); }
  849. char* getLongestPrint_str(char buffer[21]) { return duration_t(print_job_timer.getStats().longestPrint).toString(buffer); }
  850. char* getFilamentUsed_str(char buffer[21]) {
  851. printStatistics stats = print_job_timer.getStats();
  852. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
  853. return buffer;
  854. }
  855. #endif
  856. float getFeedrate_percent() { return feedrate_percentage; }
  857. #if ENABLED(PIDTEMP)
  858. float getPIDValues_Kp(const extruder_t tool) { return PID_PARAM(Kp, tool); }
  859. float getPIDValues_Ki(const extruder_t tool) { return unscalePID_i(PID_PARAM(Ki, tool)); }
  860. float getPIDValues_Kd(const extruder_t tool) { return unscalePID_d(PID_PARAM(Kd, tool)); }
  861. void setPIDValues(const_float_t p, const_float_t i, const_float_t d, extruder_t tool) {
  862. thermalManager.temp_hotend[tool].pid.Kp = p;
  863. thermalManager.temp_hotend[tool].pid.Ki = scalePID_i(i);
  864. thermalManager.temp_hotend[tool].pid.Kd = scalePID_d(d);
  865. thermalManager.updatePID();
  866. }
  867. void startPIDTune(const celsius_t temp, extruder_t tool) {
  868. thermalManager.PID_autotune(temp, (heater_id_t)tool, 8, true);
  869. }
  870. #endif
  871. #if ENABLED(PIDTEMPBED)
  872. float getBedPIDValues_Kp() { return thermalManager.temp_bed.pid.Kp; }
  873. float getBedPIDValues_Ki() { return unscalePID_i(thermalManager.temp_bed.pid.Ki); }
  874. float getBedPIDValues_Kd() { return unscalePID_d(thermalManager.temp_bed.pid.Kd); }
  875. void setBedPIDValues(const_float_t p, const_float_t i, const_float_t d) {
  876. thermalManager.temp_bed.pid.Kp = p;
  877. thermalManager.temp_bed.pid.Ki = scalePID_i(i);
  878. thermalManager.temp_bed.pid.Kd = scalePID_d(d);
  879. thermalManager.updatePID();
  880. }
  881. void startBedPIDTune(const celsius_t temp) {
  882. thermalManager.PID_autotune(temp, H_BED, 4, true);
  883. }
  884. #endif
  885. void injectCommands_P(PGM_P const gcode) { queue.inject_P(gcode); }
  886. void injectCommands(char * const gcode) { queue.inject(gcode); }
  887. bool commandsInQueue() { return (planner.movesplanned() || queue.has_commands_queued()); }
  888. bool isAxisPositionKnown(const axis_t axis) { return axis_is_trusted((AxisEnum)axis); }
  889. bool isAxisPositionKnown(const extruder_t) { return axis_is_trusted(E_AXIS); }
  890. bool isPositionKnown() { return all_axes_trusted(); }
  891. bool isMachineHomed() { return all_axes_homed(); }
  892. PGM_P getFirmwareName_str() {
  893. static PGMSTR(firmware_name, "Marlin " SHORT_BUILD_VERSION);
  894. return firmware_name;
  895. }
  896. void setTargetTemp_celsius(const_float_t inval, const heater_t heater) {
  897. float value = inval;
  898. #ifdef TOUCH_UI_LCD_TEMP_SCALING
  899. value *= TOUCH_UI_LCD_TEMP_SCALING;
  900. #endif
  901. enableHeater(heater);
  902. switch (heater) {
  903. #if HAS_HEATED_CHAMBER
  904. case CHAMBER: thermalManager.setTargetChamber(LROUND(constrain(value, 0, CHAMBER_MAX_TARGET))); break;
  905. #endif
  906. #if HAS_COOLER
  907. case COOLER: thermalManager.setTargetCooler(LROUND(constrain(value, 0, COOLER_MAXTEMP))); break;
  908. #endif
  909. #if HAS_HEATED_BED
  910. case BED: thermalManager.setTargetBed(LROUND(constrain(value, 0, BED_MAX_TARGET))); break;
  911. #endif
  912. default: {
  913. #if HAS_HOTEND
  914. const int16_t e = heater - H0;
  915. thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e);
  916. #endif
  917. } break;
  918. }
  919. }
  920. void setTargetTemp_celsius(const_float_t inval, const extruder_t extruder) {
  921. float value = inval;
  922. #ifdef TOUCH_UI_LCD_TEMP_SCALING
  923. value *= TOUCH_UI_LCD_TEMP_SCALING;
  924. #endif
  925. #if HAS_HOTEND
  926. const int16_t e = extruder - E0;
  927. enableHeater(extruder);
  928. thermalManager.setTargetHotend(LROUND(constrain(value, 0, thermalManager.hotend_max_target(e))), e);
  929. #endif
  930. }
  931. void setTargetFan_percent(const_float_t value, const fan_t fan) {
  932. #if HAS_FAN
  933. if (fan < FAN_COUNT)
  934. thermalManager.set_fan_speed(fan - FAN0, map(constrain(value, 0, 100), 0, 100, 0, 255));
  935. #else
  936. UNUSED(value);
  937. UNUSED(fan);
  938. #endif
  939. }
  940. void setFeedrate_percent(const_float_t value) { feedrate_percentage = constrain(value, 10, 500); }
  941. void coolDown() { thermalManager.cooldown(); }
  942. bool awaitingUserConfirm() {
  943. return TERN0(HAS_RESUME_CONTINUE, wait_for_user) || getHostKeepaliveIsPaused();
  944. }
  945. void setUserConfirmed() { TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); }
  946. #if M600_PURGE_MORE_RESUMABLE
  947. void setPauseMenuResponse(PauseMenuResponse response) { pause_menu_response = response; }
  948. PauseMessage pauseModeStatus = PAUSE_MESSAGE_STATUS;
  949. PauseMode getPauseMode() { return pause_mode;}
  950. #endif
  951. void printFile(const char *filename) {
  952. TERN(SDSUPPORT, card.openAndPrintFile(filename), UNUSED(filename));
  953. }
  954. bool isPrintingFromMediaPaused() {
  955. return TERN0(SDSUPPORT, IS_SD_PAUSED());
  956. }
  957. bool isPrintingFromMedia() { return TERN0(SDSUPPORT, IS_SD_PRINTING() || IS_SD_PAUSED()); }
  958. bool isPrinting() {
  959. return commandsInQueue() || isPrintingFromMedia() || printJobOngoing() || printingIsPaused();
  960. }
  961. bool isPrintingPaused() {
  962. return isPrinting() && (isPrintingFromMediaPaused() || print_job_timer.isPaused());
  963. }
  964. bool isMediaInserted() { return TERN0(SDSUPPORT, IS_SD_INSERTED()); }
  965. void pausePrint() { ui.pause_print(); }
  966. void resumePrint() { ui.resume_print(); }
  967. void stopPrint() { ui.abort_print(); }
  968. // Simplest approach is to make an SRAM copy
  969. void onUserConfirmRequired(FSTR_P const fstr) {
  970. char msg[strlen_P(FTOP(fstr)) + 1];
  971. strcpy_P(msg, FTOP(fstr));
  972. onUserConfirmRequired(msg);
  973. }
  974. void onStatusChanged(FSTR_P const fstr) {
  975. char msg[strlen_P(FTOP(fstr)) + 1];
  976. strcpy_P(msg, FTOP(fstr));
  977. onStatusChanged(msg);
  978. }
  979. FileList::FileList() { refresh(); }
  980. void FileList::refresh() { num_files = 0xFFFF; }
  981. bool FileList::seek(const uint16_t pos, const bool skip_range_check) {
  982. #if ENABLED(SDSUPPORT)
  983. if (!skip_range_check && (pos + 1) > count()) return false;
  984. card.getfilename_sorted(SD_ORDER(pos, count()));
  985. return card.filename[0] != '\0';
  986. #else
  987. UNUSED(pos);
  988. UNUSED(skip_range_check);
  989. return false;
  990. #endif
  991. }
  992. const char* FileList::filename() {
  993. return TERN(SDSUPPORT, card.longest_filename(), "");
  994. }
  995. const char* FileList::shortFilename() {
  996. return TERN(SDSUPPORT, card.filename, "");
  997. }
  998. const char* FileList::longFilename() {
  999. return TERN(SDSUPPORT, card.longFilename, "");
  1000. }
  1001. bool FileList::isDir() {
  1002. return TERN0(SDSUPPORT, card.flag.filenameIsDir);
  1003. }
  1004. uint16_t FileList::count() {
  1005. return TERN0(SDSUPPORT, (num_files = (num_files == 0xFFFF ? card.get_num_Files() : num_files)));
  1006. }
  1007. bool FileList::isAtRootDir() {
  1008. return TERN1(SDSUPPORT, card.flag.workDirIsRoot);
  1009. }
  1010. void FileList::upDir() {
  1011. #if ENABLED(SDSUPPORT)
  1012. card.cdup();
  1013. num_files = 0xFFFF;
  1014. #endif
  1015. }
  1016. void FileList::changeDir(const char * const dirname) {
  1017. #if ENABLED(SDSUPPORT)
  1018. card.cd(dirname);
  1019. num_files = 0xFFFF;
  1020. #else
  1021. UNUSED(dirname);
  1022. #endif
  1023. }
  1024. } // namespace ExtUI
  1025. // At the moment we hook into MarlinUI methods, but this could be cleaned up in the future
  1026. void MarlinUI::init_lcd() { ExtUI::onStartup(); }
  1027. void MarlinUI::update() { ExtUI::onIdle(); }
  1028. void MarlinUI::kill_screen(FSTR_P const error, FSTR_P const component) {
  1029. using namespace ExtUI;
  1030. if (!flags.printer_killed) {
  1031. flags.printer_killed = true;
  1032. onPrinterKilled(error, component);
  1033. }
  1034. }
  1035. #endif // EXTENSIBLE_UI