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 38KB

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