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

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