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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "ultralcd.h"
  23. #if ENABLED(ULTRA_LCD)
  24. #include "Marlin.h"
  25. #include "language.h"
  26. #include "cardreader.h"
  27. #include "temperature.h"
  28. #include "planner.h"
  29. #include "stepper.h"
  30. #include "configuration_store.h"
  31. #include "utility.h"
  32. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  33. #include "buzzer.h"
  34. #endif
  35. #if ENABLED(PRINTCOUNTER)
  36. #include "printcounter.h"
  37. #include "duration_t.h"
  38. #endif
  39. #if ENABLED(BLTOUCH)
  40. #include "endstops.h"
  41. #endif
  42. #if ENABLED(AUTO_BED_LEVELING_UBL)
  43. #include "ubl.h"
  44. bool ubl_lcd_map_control = false;
  45. #endif
  46. int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  47. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  48. millis_t previous_lcd_status_ms = 0;
  49. #endif
  50. #if ENABLED(BABYSTEPPING)
  51. long babysteps_done = 0;
  52. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  53. static void lcd_babystep_zoffset();
  54. #else
  55. static void lcd_babystep_z();
  56. #endif
  57. #endif
  58. uint8_t lcd_status_message_level;
  59. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  60. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  61. uint8_t status_scroll_pos = 0;
  62. #endif
  63. #if ENABLED(DOGLCD)
  64. #include "ultralcd_impl_DOGM.h"
  65. #include <U8glib.h>
  66. #else
  67. #include "ultralcd_impl_HD44780.h"
  68. #endif
  69. // The main status screen
  70. void lcd_status_screen();
  71. millis_t next_lcd_update_ms;
  72. uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
  73. uint16_t max_display_update_time = 0;
  74. #if ENABLED(DOGLCD)
  75. bool drawing_screen = false;
  76. #endif
  77. #if ENABLED(DAC_STEPPER_CURRENT)
  78. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  79. uint8_t driverPercent[XYZE];
  80. #endif
  81. #if ENABLED(ULTIPANEL)
  82. #ifndef TALL_FONT_CORRECTION
  83. #define TALL_FONT_CORRECTION 0
  84. #endif
  85. // Function pointer to menu functions.
  86. typedef void (*screenFunc_t)();
  87. #if HAS_POWER_SWITCH
  88. extern bool powersupply_on;
  89. #endif
  90. ////////////////////////////////////////////
  91. ///////////////// Menu Tree ////////////////
  92. ////////////////////////////////////////////
  93. void lcd_main_menu();
  94. void lcd_tune_menu();
  95. void lcd_prepare_menu();
  96. void lcd_move_menu();
  97. void lcd_control_menu();
  98. void lcd_control_temperature_menu();
  99. void lcd_control_temperature_preheat_material1_settings_menu();
  100. void lcd_control_temperature_preheat_material2_settings_menu();
  101. void lcd_control_motion_menu();
  102. void lcd_control_filament_menu();
  103. #if ENABLED(LCD_INFO_MENU)
  104. #if ENABLED(PRINTCOUNTER)
  105. void lcd_info_stats_menu();
  106. #endif
  107. void lcd_info_thermistors_menu();
  108. void lcd_info_board_menu();
  109. void lcd_info_menu();
  110. #endif // LCD_INFO_MENU
  111. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  112. void lcd_advanced_pause_toocold_menu();
  113. void lcd_advanced_pause_option_menu();
  114. void lcd_advanced_pause_init_message();
  115. void lcd_advanced_pause_unload_message();
  116. void lcd_advanced_pause_insert_message();
  117. void lcd_advanced_pause_load_message();
  118. void lcd_advanced_pause_heat_nozzle();
  119. void lcd_advanced_pause_extrude_message();
  120. void lcd_advanced_pause_resume_message();
  121. #endif
  122. #if ENABLED(DAC_STEPPER_CURRENT)
  123. void dac_driver_commit();
  124. void dac_driver_getValues();
  125. void lcd_dac_menu();
  126. void lcd_dac_write_eeprom();
  127. #endif
  128. #if ENABLED(FWRETRACT)
  129. void lcd_control_retract_menu();
  130. #endif
  131. #if ENABLED(DELTA_CALIBRATION_MENU)
  132. void lcd_delta_calibrate_menu();
  133. #endif
  134. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  135. #include "mesh_bed_leveling.h"
  136. extern void mesh_probing_done();
  137. #endif
  138. ////////////////////////////////////////////
  139. //////////// Menu System Actions ///////////
  140. ////////////////////////////////////////////
  141. #define menu_action_back(dummy) _menu_action_back()
  142. void _menu_action_back();
  143. void menu_action_submenu(screenFunc_t data);
  144. void menu_action_gcode(const char* pgcode);
  145. void menu_action_function(screenFunc_t data);
  146. #define DECLARE_MENU_EDIT_TYPE(_type, _name) \
  147. bool _menu_edit_ ## _name(); \
  148. void menu_edit_ ## _name(); \
  149. void menu_edit_callback_ ## _name(); \
  150. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
  151. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
  152. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
  153. typedef void _name##_void
  154. DECLARE_MENU_EDIT_TYPE(int, int3);
  155. DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
  156. DECLARE_MENU_EDIT_TYPE(float, float3);
  157. DECLARE_MENU_EDIT_TYPE(float, float32);
  158. DECLARE_MENU_EDIT_TYPE(float, float43);
  159. DECLARE_MENU_EDIT_TYPE(float, float5);
  160. DECLARE_MENU_EDIT_TYPE(float, float51);
  161. DECLARE_MENU_EDIT_TYPE(float, float52);
  162. DECLARE_MENU_EDIT_TYPE(float, float62);
  163. DECLARE_MENU_EDIT_TYPE(unsigned long, long5);
  164. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  165. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  166. #if ENABLED(SDSUPPORT)
  167. void lcd_sdcard_menu();
  168. void menu_action_sdfile(const char* filename, char* longFilename);
  169. void menu_action_sddirectory(const char* filename, char* longFilename);
  170. #endif
  171. ////////////////////////////////////////////
  172. //////////// Menu System Macros ////////////
  173. ////////////////////////////////////////////
  174. #ifndef ENCODER_FEEDRATE_DEADZONE
  175. #define ENCODER_FEEDRATE_DEADZONE 10
  176. #endif
  177. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  178. #define ENCODER_STEPS_PER_MENU_ITEM 5
  179. #endif
  180. #ifndef ENCODER_PULSES_PER_STEP
  181. #define ENCODER_PULSES_PER_STEP 1
  182. #endif
  183. /**
  184. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  185. *
  186. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  187. * menu_action_[type](arg3...)
  188. *
  189. * Examples:
  190. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  191. * or
  192. * MENU_BACK(MSG_WATCH)
  193. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  194. * menu_action_back()
  195. *
  196. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  197. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  198. * menu_action_function(lcd_sdcard_pause)
  199. *
  200. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  201. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  202. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  203. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  204. *
  205. */
  206. #define _MENU_ITEM_PART_1(TYPE, ...) \
  207. if (_menuLineNr == _thisItemNr) { \
  208. if (lcd_clicked && encoderLine == _thisItemNr) {
  209. #define _MENU_ITEM_PART_2(TYPE, LABEL, ...) \
  210. menu_action_ ## TYPE(__VA_ARGS__); \
  211. if (screen_changed) return; \
  212. } \
  213. if (lcdDrawUpdate) \
  214. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  215. } \
  216. ++_thisItemNr
  217. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  218. _skipStatic = false; \
  219. _MENU_ITEM_PART_1(TYPE, ## __VA_ARGS__); \
  220. _MENU_ITEM_PART_2(TYPE, LABEL, ## __VA_ARGS__); \
  221. }while(0)
  222. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  223. // Used to print static text with no visible cursor.
  224. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  225. #define STATIC_ITEM(LABEL, ...) \
  226. if (_menuLineNr == _thisItemNr) { \
  227. if (_skipStatic && encoderLine <= _thisItemNr) { \
  228. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  229. ++encoderLine; \
  230. } \
  231. if (lcdDrawUpdate) \
  232. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  233. } \
  234. ++_thisItemNr
  235. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  236. bool encoderRateMultiplierEnabled;
  237. #define ENCODER_RATE_MULTIPLY(F) (encoderRateMultiplierEnabled = F)
  238. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  239. /**
  240. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  241. */
  242. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  243. _MENU_ITEM_PART_1(type, ## __VA_ARGS__); \
  244. encoderRateMultiplierEnabled = true; \
  245. lastEncoderMovementMillis = 0; \
  246. _MENU_ITEM_PART_2(type, label, ## __VA_ARGS__); \
  247. }while(0)
  248. #else // !ENCODER_RATE_MULTIPLIER
  249. #define ENCODER_RATE_MULTIPLY(F) NOOP
  250. #endif // !ENCODER_RATE_MULTIPLIER
  251. #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
  252. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  253. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  254. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  255. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  256. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  257. #else // !ENCODER_RATE_MULTIPLIER
  258. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  259. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  260. #endif // !ENCODER_RATE_MULTIPLIER
  261. /**
  262. * START_SCREEN_OR_MENU generates init code for a screen or menu
  263. *
  264. * encoderLine is the position based on the encoder
  265. * encoderTopLine is the top menu line to display
  266. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  267. * _menuLineNr is the menu item to draw and process
  268. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  269. * _countedItems is the total number of items in the menu (after one call)
  270. */
  271. #define START_SCREEN_OR_MENU(LIMIT) \
  272. ENCODER_DIRECTION_MENUS(); \
  273. ENCODER_RATE_MULTIPLY(false); \
  274. if (encoderPosition > 0x8000) encoderPosition = 0; \
  275. static int8_t _countedItems = 0; \
  276. int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
  277. if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
  278. encoderLine = max(0, _countedItems - (LIMIT)); \
  279. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  280. }
  281. #define SCREEN_OR_MENU_LOOP() \
  282. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  283. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
  284. _thisItemNr = 0
  285. /**
  286. * START_SCREEN Opening code for a screen having only static items.
  287. * Do simplified scrolling of the entire screen.
  288. *
  289. * START_MENU Opening code for a screen with menu items.
  290. * Scroll as-needed to keep the selected line in view.
  291. */
  292. #define START_SCREEN() \
  293. START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
  294. encoderTopLine = encoderLine; \
  295. bool _skipStatic = false; \
  296. SCREEN_OR_MENU_LOOP()
  297. #define START_MENU() \
  298. START_SCREEN_OR_MENU(1); \
  299. screen_changed = false; \
  300. NOMORE(encoderTopLine, encoderLine); \
  301. if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
  302. encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
  303. } \
  304. bool _skipStatic = true; \
  305. SCREEN_OR_MENU_LOOP()
  306. #define END_SCREEN() \
  307. } \
  308. _countedItems = _thisItemNr
  309. #define END_MENU() \
  310. } \
  311. _countedItems = _thisItemNr; \
  312. UNUSED(_skipStatic)
  313. ////////////////////////////////////////////
  314. ///////////// Global Variables /////////////
  315. ////////////////////////////////////////////
  316. /**
  317. * REVERSE_MENU_DIRECTION
  318. *
  319. * To reverse the menu direction we need a general way to reverse
  320. * the direction of the encoder everywhere. So encoderDirection is
  321. * added to allow the encoder to go the other way.
  322. *
  323. * This behavior is limited to scrolling Menus and SD card listings,
  324. * and is disabled in other contexts.
  325. */
  326. #if ENABLED(REVERSE_MENU_DIRECTION)
  327. int8_t encoderDirection = 1;
  328. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  329. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  330. #else
  331. #define ENCODER_DIRECTION_NORMAL() ;
  332. #define ENCODER_DIRECTION_MENUS() ;
  333. #endif
  334. // Encoder Movement
  335. volatile int8_t encoderDiff; // Updated in lcd_buttons_update, added to encoderPosition every LCD update
  336. uint32_t encoderPosition;
  337. millis_t lastEncoderMovementMillis = 0;
  338. // Button States
  339. bool lcd_clicked, wait_for_unclick;
  340. volatile uint8_t buttons;
  341. millis_t next_button_update_ms;
  342. #if ENABLED(REPRAPWORLD_KEYPAD)
  343. volatile uint8_t buttons_reprapworld_keypad;
  344. #endif
  345. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  346. volatile uint8_t slow_buttons;
  347. #endif
  348. // Menu System Navigation
  349. screenFunc_t currentScreen = lcd_status_screen;
  350. int8_t encoderTopLine;
  351. typedef struct {
  352. screenFunc_t menu_function;
  353. uint32_t encoder_position;
  354. } menuPosition;
  355. menuPosition screen_history[6];
  356. uint8_t screen_history_depth = 0;
  357. bool screen_changed, defer_return_to_status;
  358. // Value Editing
  359. const char *editLabel;
  360. void *editValue;
  361. int32_t minEditValue, maxEditValue;
  362. screenFunc_t callbackFunc;
  363. bool liveEdit;
  364. // Manual Moves
  365. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  366. millis_t manual_move_start_time = 0;
  367. int8_t manual_move_axis = (int8_t)NO_AXIS;
  368. #if EXTRUDERS > 1
  369. int8_t manual_move_e_index = 0;
  370. #else
  371. #define manual_move_e_index 0
  372. #endif
  373. #if PIN_EXISTS(SD_DETECT)
  374. uint8_t lcd_sd_status;
  375. #endif
  376. #if ENABLED(PIDTEMP)
  377. float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
  378. #endif
  379. /**
  380. * General function to go directly to a screen
  381. */
  382. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0) {
  383. if (currentScreen != screen) {
  384. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  385. static millis_t doubleclick_expire_ms = 0;
  386. // Going to lcd_main_menu from status screen? Remember first click time.
  387. // Going back to status screen within a very short time? Go to Z babystepping.
  388. if (screen == lcd_main_menu) {
  389. if (currentScreen == lcd_status_screen)
  390. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  391. }
  392. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
  393. screen =
  394. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  395. lcd_babystep_zoffset
  396. #else
  397. lcd_babystep_z
  398. #endif
  399. ;
  400. #endif
  401. currentScreen = screen;
  402. encoderPosition = encoder;
  403. if (screen == lcd_status_screen) {
  404. defer_return_to_status = false;
  405. screen_history_depth = 0;
  406. }
  407. lcd_implementation_clear();
  408. #if ENABLED(LCD_PROGRESS_BAR)
  409. // For LCD_PROGRESS_BAR re-initialize custom characters
  410. lcd_set_custom_characters(screen == lcd_status_screen);
  411. #endif
  412. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  413. screen_changed = true;
  414. #if ENABLED(DOGLCD)
  415. drawing_screen = false;
  416. #endif
  417. }
  418. }
  419. /**
  420. * Show "Moving..." till moves are done, then revert to previous display.
  421. */
  422. static const char moving[] PROGMEM = MSG_MOVING;
  423. static const char *sync_message = moving;
  424. //
  425. // Display the synchronize screen until moves are
  426. // finished, and don't return to the caller until
  427. // done. ** This blocks the command queue! **
  428. //
  429. void _lcd_synchronize() {
  430. static bool no_reentry = false;
  431. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
  432. if (no_reentry) return;
  433. // Make this the current handler till all moves are done
  434. no_reentry = true;
  435. screenFunc_t old_screen = currentScreen;
  436. lcd_goto_screen(_lcd_synchronize);
  437. stepper.synchronize();
  438. no_reentry = false;
  439. lcd_goto_screen(old_screen);
  440. }
  441. // Display the synchronize screen with a custom message
  442. // ** This blocks the command queue! **
  443. void lcd_synchronize(const char * const msg=NULL) {
  444. sync_message = msg ? msg : moving;
  445. _lcd_synchronize();
  446. }
  447. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  448. void lcd_save_previous_screen() {
  449. if (screen_history_depth < COUNT(screen_history)) {
  450. screen_history[screen_history_depth].menu_function = currentScreen;
  451. screen_history[screen_history_depth].encoder_position = encoderPosition;
  452. ++screen_history_depth;
  453. }
  454. }
  455. void lcd_goto_previous_menu() {
  456. if (screen_history_depth > 0) {
  457. --screen_history_depth;
  458. lcd_goto_screen(
  459. screen_history[screen_history_depth].menu_function,
  460. screen_history[screen_history_depth].encoder_position
  461. );
  462. }
  463. else
  464. lcd_return_to_status();
  465. }
  466. #endif // ULTIPANEL
  467. /**
  468. *
  469. * "Info Screen"
  470. *
  471. * This is very display-dependent, so the lcd implementation draws this.
  472. */
  473. void lcd_status_screen() {
  474. #if ENABLED(ULTIPANEL)
  475. ENCODER_DIRECTION_NORMAL();
  476. ENCODER_RATE_MULTIPLY(false);
  477. #endif
  478. #if ENABLED(LCD_PROGRESS_BAR)
  479. millis_t ms = millis();
  480. #if DISABLED(PROGRESS_MSG_ONCE)
  481. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  482. progress_bar_ms = ms;
  483. }
  484. #endif
  485. #if PROGRESS_MSG_EXPIRE > 0
  486. // Handle message expire
  487. if (expire_status_ms > 0) {
  488. #if ENABLED(SDSUPPORT)
  489. if (card.isFileOpen()) {
  490. // Expire the message when printing is active
  491. if (IS_SD_PRINTING) {
  492. if (ELAPSED(ms, expire_status_ms)) {
  493. lcd_status_message[0] = '\0';
  494. expire_status_ms = 0;
  495. }
  496. }
  497. else {
  498. expire_status_ms += LCD_UPDATE_INTERVAL;
  499. }
  500. }
  501. else {
  502. expire_status_ms = 0;
  503. }
  504. #else
  505. expire_status_ms = 0;
  506. #endif // SDSUPPORT
  507. }
  508. #endif
  509. #endif // LCD_PROGRESS_BAR
  510. #if ENABLED(ULTIPANEL)
  511. if (lcd_clicked) {
  512. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  513. previous_lcd_status_ms = millis(); // get status message to show up for a while
  514. #endif
  515. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  516. #if ENABLED(LCD_PROGRESS_BAR)
  517. false
  518. #endif
  519. );
  520. lcd_goto_screen(lcd_main_menu);
  521. return;
  522. }
  523. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  524. const int new_frm = feedrate_percentage + (int32_t)encoderPosition;
  525. // Dead zone at 100% feedrate
  526. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  527. feedrate_percentage = 100;
  528. encoderPosition = 0;
  529. }
  530. else if (feedrate_percentage == 100) {
  531. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  532. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  533. encoderPosition = 0;
  534. }
  535. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  536. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  537. encoderPosition = 0;
  538. }
  539. }
  540. else {
  541. feedrate_percentage = new_frm;
  542. encoderPosition = 0;
  543. }
  544. #endif // ULTIPANEL_FEEDMULTIPLY
  545. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  546. #endif // ULTIPANEL
  547. lcd_implementation_status_screen();
  548. }
  549. void lcd_reset_status() { lcd_setstatusPGM(PSTR(""), -1); }
  550. /**
  551. *
  552. * draw the kill screen
  553. *
  554. */
  555. void kill_screen(const char* lcd_msg) {
  556. lcd_init();
  557. lcd_setalertstatusPGM(lcd_msg);
  558. #if ENABLED(DOGLCD)
  559. u8g.firstPage();
  560. do {
  561. lcd_kill_screen();
  562. } while (u8g.nextPage());
  563. #else
  564. lcd_kill_screen();
  565. #endif
  566. }
  567. #if ENABLED(ULTIPANEL)
  568. /**
  569. *
  570. * Audio feedback for controller clicks
  571. *
  572. */
  573. void lcd_buzz(long duration, uint16_t freq) {
  574. #if ENABLED(LCD_USE_I2C_BUZZER)
  575. lcd.buzz(duration, freq);
  576. #elif PIN_EXISTS(BEEPER)
  577. buzzer.tone(duration, freq);
  578. #else
  579. UNUSED(duration); UNUSED(freq);
  580. #endif
  581. }
  582. void lcd_quick_feedback() {
  583. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  584. buttons = 0;
  585. next_button_update_ms = millis() + 500;
  586. // Buzz and wait. The delay is needed for buttons to settle!
  587. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  588. #if ENABLED(LCD_USE_I2C_BUZZER)
  589. delay(10);
  590. #elif PIN_EXISTS(BEEPER)
  591. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  592. #endif
  593. }
  594. void lcd_completion_feedback(const bool good/*=true*/) {
  595. if (good) {
  596. lcd_buzz(100, 659);
  597. lcd_buzz(100, 698);
  598. }
  599. else lcd_buzz(20, 440);
  600. }
  601. inline void line_to_current_z() {
  602. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[Z_AXIS]), active_extruder);
  603. }
  604. inline void line_to_z(const float &z) {
  605. current_position[Z_AXIS] = z;
  606. line_to_current_z();
  607. }
  608. #if ENABLED(SDSUPPORT)
  609. void lcd_sdcard_pause() {
  610. card.pauseSDPrint();
  611. print_job_timer.pause();
  612. #if ENABLED(PARK_HEAD_ON_PAUSE)
  613. enqueue_and_echo_commands_P(PSTR("M125"));
  614. #endif
  615. lcd_setstatusPGM(PSTR(MSG_PRINT_PAUSED), -1);
  616. }
  617. void lcd_sdcard_resume() {
  618. #if ENABLED(PARK_HEAD_ON_PAUSE)
  619. enqueue_and_echo_commands_P(PSTR("M24"));
  620. #else
  621. card.startFileprint();
  622. print_job_timer.start();
  623. #endif
  624. lcd_reset_status();
  625. }
  626. void lcd_sdcard_stop() {
  627. card.stopSDPrint();
  628. clear_command_queue();
  629. quickstop_stepper();
  630. print_job_timer.stop();
  631. thermalManager.disable_all_heaters();
  632. #if FAN_COUNT > 0
  633. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  634. #endif
  635. wait_for_heatup = false;
  636. lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
  637. lcd_return_to_status();
  638. }
  639. #endif // SDSUPPORT
  640. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  641. extern int case_light_brightness;
  642. extern bool case_light_on;
  643. extern void update_case_light();
  644. void case_light_menu() {
  645. START_MENU();
  646. //
  647. // ^ Main
  648. //
  649. MENU_BACK(MSG_MAIN);
  650. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CASE_LIGHT_BRIGHTNESS, &case_light_brightness, 0, 255, update_case_light, true);
  651. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  652. END_MENU();
  653. }
  654. #endif // MENU_ITEM_CASE_LIGHT
  655. #if ENABLED(BLTOUCH)
  656. /**
  657. *
  658. * "BLTouch" submenu
  659. *
  660. */
  661. static void bltouch_menu() {
  662. START_MENU();
  663. //
  664. // ^ Main
  665. //
  666. MENU_BACK(MSG_MAIN);
  667. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  668. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  669. MENU_ITEM(gcode, MSG_BLTOUCH_DEPLOY, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_DEPLOY)));
  670. MENU_ITEM(gcode, MSG_BLTOUCH_STOW, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_STOW)));
  671. END_MENU();
  672. }
  673. #endif // BLTOUCH
  674. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  675. static void progress_bar_test() {
  676. static int8_t bar_percent = 0;
  677. if (lcd_clicked) {
  678. lcd_goto_previous_menu();
  679. lcd_set_custom_characters(false);
  680. return;
  681. }
  682. bar_percent += (int8_t)encoderPosition;
  683. bar_percent = constrain(bar_percent, 0, 100);
  684. encoderPosition = 0;
  685. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  686. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  687. lcd.print(itostr3(bar_percent)); lcd.print('%');
  688. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  689. }
  690. void _progress_bar_test() {
  691. lcd_goto_screen(progress_bar_test);
  692. lcd_set_custom_characters();
  693. }
  694. #endif // LCD_PROGRESS_BAR_TEST
  695. #if HAS_DEBUG_MENU
  696. void lcd_debug_menu() {
  697. START_MENU();
  698. MENU_BACK(MSG_MAIN); // ^ Main
  699. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  700. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  701. #endif
  702. END_MENU();
  703. }
  704. #endif // HAS_DEBUG_MENU
  705. #if ENABLED(CUSTOM_USER_MENUS)
  706. #ifdef USER_SCRIPT_DONE
  707. #define _DONE_SCRIPT "\n" USER_SCRIPT_DONE
  708. #else
  709. #define _DONE_SCRIPT ""
  710. #endif
  711. void _lcd_user_gcode(const char * const cmd) {
  712. lcd_return_to_status();
  713. enqueue_and_echo_commands_P(cmd);
  714. }
  715. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  716. void lcd_user_gcode_1() { _lcd_user_gcode(PSTR(USER_GCODE_1 _DONE_SCRIPT)); }
  717. #endif
  718. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  719. void lcd_user_gcode_2() { _lcd_user_gcode(PSTR(USER_GCODE_2 _DONE_SCRIPT)); }
  720. #endif
  721. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  722. void lcd_user_gcode_3() { _lcd_user_gcode(PSTR(USER_GCODE_3 _DONE_SCRIPT)); }
  723. #endif
  724. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  725. void lcd_user_gcode_4() { _lcd_user_gcode(PSTR(USER_GCODE_4 _DONE_SCRIPT)); }
  726. #endif
  727. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  728. void lcd_user_gcode_5() { _lcd_user_gcode(PSTR(USER_GCODE_5 _DONE_SCRIPT)); }
  729. #endif
  730. void _lcd_user_menu() {
  731. START_MENU();
  732. MENU_BACK(MSG_MAIN);
  733. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  734. MENU_ITEM(function, USER_DESC_1, lcd_user_gcode_1);
  735. #endif
  736. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  737. MENU_ITEM(function, USER_DESC_2, lcd_user_gcode_2);
  738. #endif
  739. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  740. MENU_ITEM(function, USER_DESC_3, lcd_user_gcode_3);
  741. #endif
  742. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  743. MENU_ITEM(function, USER_DESC_4, lcd_user_gcode_4);
  744. #endif
  745. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  746. MENU_ITEM(function, USER_DESC_5, lcd_user_gcode_5);
  747. #endif
  748. END_MENU();
  749. }
  750. #endif
  751. /**
  752. *
  753. * "Main" menu
  754. *
  755. */
  756. void lcd_main_menu() {
  757. START_MENU();
  758. MENU_BACK(MSG_WATCH);
  759. #if ENABLED(CUSTOM_USER_MENUS)
  760. MENU_ITEM(submenu, MSG_USER_MENU, _lcd_user_menu);
  761. #endif
  762. //
  763. // Debug Menu when certain options are enabled
  764. //
  765. #if HAS_DEBUG_MENU
  766. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  767. #endif
  768. //
  769. // Set Case light on/off/brightness
  770. //
  771. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  772. if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) {
  773. MENU_ITEM(submenu, MSG_CASE_LIGHT, case_light_menu);
  774. }
  775. else
  776. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  777. #endif
  778. if (planner.movesplanned() || IS_SD_PRINTING) {
  779. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  780. }
  781. else {
  782. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  783. #if ENABLED(DELTA_CALIBRATION_MENU)
  784. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  785. #endif
  786. }
  787. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  788. #if ENABLED(SDSUPPORT)
  789. if (card.cardOK) {
  790. if (card.isFileOpen()) {
  791. if (card.sdprinting)
  792. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  793. else
  794. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  795. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  796. }
  797. else {
  798. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  799. #if !PIN_EXISTS(SD_DETECT)
  800. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  801. #endif
  802. }
  803. }
  804. else {
  805. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  806. #if !PIN_EXISTS(SD_DETECT)
  807. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  808. #endif
  809. }
  810. #endif // SDSUPPORT
  811. #if ENABLED(LCD_INFO_MENU)
  812. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  813. #endif
  814. END_MENU();
  815. }
  816. /**
  817. *
  818. * "Tune" submenu items
  819. *
  820. */
  821. #if HAS_M206_COMMAND
  822. /**
  823. * Set the home offset based on the current_position
  824. */
  825. void lcd_set_home_offsets() {
  826. // M428 Command
  827. enqueue_and_echo_commands_P(PSTR("M428"));
  828. lcd_return_to_status();
  829. }
  830. #endif
  831. #if ENABLED(BABYSTEPPING)
  832. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  833. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  834. ENCODER_DIRECTION_NORMAL();
  835. if (encoderPosition) {
  836. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  837. encoderPosition = 0;
  838. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  839. thermalManager.babystep_axis(axis, babystep_increment);
  840. babysteps_done += babystep_increment;
  841. }
  842. if (lcdDrawUpdate)
  843. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  844. }
  845. #if ENABLED(BABYSTEP_XY)
  846. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  847. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  848. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  849. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  850. #endif
  851. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  852. void lcd_babystep_zoffset() {
  853. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  854. defer_return_to_status = true;
  855. ENCODER_DIRECTION_NORMAL();
  856. if (encoderPosition) {
  857. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  858. encoderPosition = 0;
  859. const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
  860. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  861. if (planner.abl_enabled)
  862. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  863. zprobe_zoffset = new_zoffset;
  864. refresh_zprobe_zoffset(true);
  865. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  866. }
  867. }
  868. if (lcdDrawUpdate)
  869. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  870. }
  871. #else // !BABYSTEP_ZPROBE_OFFSET
  872. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  873. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  874. #endif // !BABYSTEP_ZPROBE_OFFSET
  875. #endif // BABYSTEPPING
  876. #if ENABLED(AUTO_BED_LEVELING_UBL)
  877. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  878. // seperate value that doesn't lose precision.
  879. static int ubl_encoderPosition = 0;
  880. static void _lcd_mesh_fine_tune(const char* msg) {
  881. defer_return_to_status = true;
  882. if (ubl.encoder_diff) {
  883. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  884. ubl.encoder_diff = 0;
  885. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  886. mesh_edit_value = mesh_edit_accumulator;
  887. encoderPosition = 0;
  888. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  889. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  890. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  891. }
  892. if (lcdDrawUpdate)
  893. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  894. }
  895. void _lcd_mesh_edit_NOP() {
  896. defer_return_to_status = true;
  897. }
  898. float lcd_mesh_edit() {
  899. lcd_goto_screen(_lcd_mesh_edit_NOP);
  900. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  901. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  902. return mesh_edit_value;
  903. }
  904. void lcd_mesh_edit_setup(float initial) {
  905. mesh_edit_value = mesh_edit_accumulator = initial;
  906. lcd_goto_screen(_lcd_mesh_edit_NOP);
  907. }
  908. void _lcd_z_offset_edit() {
  909. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  910. }
  911. float lcd_z_offset_edit() {
  912. lcd_goto_screen(_lcd_z_offset_edit);
  913. return mesh_edit_value;
  914. }
  915. void lcd_z_offset_edit_setup(float initial) {
  916. mesh_edit_value = mesh_edit_accumulator = initial;
  917. lcd_goto_screen(_lcd_z_offset_edit);
  918. }
  919. #endif // AUTO_BED_LEVELING_UBL
  920. /**
  921. * Watch temperature callbacks
  922. */
  923. #if HAS_TEMP_HOTEND
  924. #if WATCH_HOTENDS
  925. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  926. #else
  927. #define _WATCH_FUNC(N) NOOP
  928. #endif
  929. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  930. #if HOTENDS > 1
  931. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  932. #if HOTENDS > 2
  933. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  934. #if HOTENDS > 3
  935. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  936. #if HOTENDS > 4
  937. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  938. #endif // HOTENDS > 4
  939. #endif // HOTENDS > 3
  940. #endif // HOTENDS > 2
  941. #endif // HOTENDS > 1
  942. #endif // HAS_TEMP_HOTEND
  943. void watch_temp_callback_bed() {
  944. #if WATCH_THE_BED
  945. thermalManager.start_watching_bed();
  946. #endif
  947. }
  948. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  949. void lcd_enqueue_filament_change() {
  950. if (!DEBUGGING(DRYRUN) && thermalManager.tooColdToExtrude(active_extruder)) {
  951. lcd_save_previous_screen();
  952. lcd_goto_screen(lcd_advanced_pause_toocold_menu);
  953. return;
  954. }
  955. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  956. enqueue_and_echo_commands_P(PSTR("M600 B0"));
  957. }
  958. #endif // ADVANCED_PAUSE_FEATURE
  959. /**
  960. *
  961. * "Tune" submenu
  962. *
  963. */
  964. void lcd_tune_menu() {
  965. START_MENU();
  966. //
  967. // ^ Main
  968. //
  969. MENU_BACK(MSG_MAIN);
  970. //
  971. // Speed:
  972. //
  973. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  974. // Manual bed leveling, Bed Z:
  975. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  976. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  977. #endif
  978. //
  979. // Nozzle:
  980. // Nozzle [1-4]:
  981. //
  982. #if HOTENDS == 1
  983. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  984. #else // HOTENDS > 1
  985. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  986. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  987. #if HOTENDS > 2
  988. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  989. #if HOTENDS > 3
  990. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  991. #if HOTENDS > 4
  992. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  993. #endif // HOTENDS > 4
  994. #endif // HOTENDS > 3
  995. #endif // HOTENDS > 2
  996. #endif // HOTENDS > 1
  997. //
  998. // Bed:
  999. //
  1000. #if HAS_TEMP_BED
  1001. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1002. #endif
  1003. //
  1004. // Fan Speed:
  1005. //
  1006. #if FAN_COUNT > 0
  1007. #if HAS_FAN0
  1008. #if FAN_COUNT > 1
  1009. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1010. #else
  1011. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1012. #endif
  1013. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1014. #endif
  1015. #if HAS_FAN1
  1016. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1017. #endif
  1018. #if HAS_FAN2
  1019. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1020. #endif
  1021. #endif // FAN_COUNT > 0
  1022. //
  1023. // Flow:
  1024. // Flow [1-5]:
  1025. //
  1026. #if EXTRUDERS == 1
  1027. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  1028. #else // EXTRUDERS > 1
  1029. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  1030. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  1031. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  1032. #if EXTRUDERS > 2
  1033. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  1034. #if EXTRUDERS > 3
  1035. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  1036. #if EXTRUDERS > 4
  1037. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  1038. #endif // EXTRUDERS > 4
  1039. #endif // EXTRUDERS > 3
  1040. #endif // EXTRUDERS > 2
  1041. #endif // EXTRUDERS > 1
  1042. //
  1043. // Babystep X:
  1044. // Babystep Y:
  1045. // Babystep Z:
  1046. //
  1047. #if ENABLED(BABYSTEPPING)
  1048. #if ENABLED(BABYSTEP_XY)
  1049. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  1050. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  1051. #endif
  1052. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1053. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1054. #else
  1055. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  1056. #endif
  1057. #endif
  1058. //
  1059. // Change filament
  1060. //
  1061. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1062. if (!thermalManager.tooColdToExtrude(active_extruder))
  1063. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1064. #endif
  1065. END_MENU();
  1066. }
  1067. /**
  1068. *
  1069. * "Driver current control" submenu items
  1070. *
  1071. */
  1072. #if ENABLED(DAC_STEPPER_CURRENT)
  1073. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  1074. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  1075. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  1076. void lcd_dac_menu() {
  1077. dac_driver_getValues();
  1078. START_MENU();
  1079. MENU_BACK(MSG_CONTROL);
  1080. MENU_ITEM_EDIT_CALLBACK(int8, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  1081. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  1082. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  1083. MENU_ITEM_EDIT_CALLBACK(int8, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  1084. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  1085. END_MENU();
  1086. }
  1087. #endif
  1088. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  1089. /**
  1090. *
  1091. * "Prepare" submenu items
  1092. *
  1093. */
  1094. void _lcd_preheat(const int endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
  1095. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  1096. #if TEMP_SENSOR_BED != 0
  1097. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  1098. #else
  1099. UNUSED(tempb);
  1100. #endif
  1101. #if FAN_COUNT > 0
  1102. #if FAN_COUNT > 1
  1103. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  1104. #else
  1105. fanSpeeds[0] = fan;
  1106. #endif
  1107. #else
  1108. UNUSED(fan);
  1109. #endif
  1110. lcd_return_to_status();
  1111. }
  1112. #if TEMP_SENSOR_0 != 0
  1113. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1114. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1115. #if TEMP_SENSOR_BED != 0
  1116. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1117. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1118. #endif
  1119. #endif
  1120. #if HOTENDS > 1
  1121. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1122. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1123. #if TEMP_SENSOR_BED != 0
  1124. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1125. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1126. #endif
  1127. #if HOTENDS > 2
  1128. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1129. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1130. #if TEMP_SENSOR_BED != 0
  1131. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1132. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1133. #endif
  1134. #if HOTENDS > 3
  1135. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1136. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1137. #if TEMP_SENSOR_BED != 0
  1138. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1139. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1140. #endif
  1141. #if HOTENDS > 4
  1142. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1143. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1144. #if TEMP_SENSOR_BED != 0
  1145. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1146. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1147. #endif
  1148. #endif // HOTENDS > 4
  1149. #endif // HOTENDS > 3
  1150. #endif // HOTENDS > 2
  1151. void lcd_preheat_m1_all() {
  1152. #if HOTENDS > 1
  1153. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1154. #if HOTENDS > 2
  1155. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1156. #if HOTENDS > 3
  1157. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1158. #if HOTENDS > 4
  1159. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1160. #endif // HOTENDS > 4
  1161. #endif // HOTENDS > 3
  1162. #endif // HOTENDS > 2
  1163. #endif // HOTENDS > 1
  1164. #if TEMP_SENSOR_BED != 0
  1165. lcd_preheat_m1_e0();
  1166. #else
  1167. lcd_preheat_m1_e0_only();
  1168. #endif
  1169. }
  1170. void lcd_preheat_m2_all() {
  1171. #if HOTENDS > 1
  1172. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1173. #if HOTENDS > 2
  1174. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1175. #if HOTENDS > 3
  1176. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1177. #if HOTENDS > 4
  1178. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1179. #endif // HOTENDS > 4
  1180. #endif // HOTENDS > 3
  1181. #endif // HOTENDS > 2
  1182. #endif // HOTENDS > 1
  1183. #if TEMP_SENSOR_BED != 0
  1184. lcd_preheat_m2_e0();
  1185. #else
  1186. lcd_preheat_m2_e0_only();
  1187. #endif
  1188. }
  1189. #endif // HOTENDS > 1
  1190. #if TEMP_SENSOR_BED != 0
  1191. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1192. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1193. #endif
  1194. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0)
  1195. void lcd_preheat_m1_menu() {
  1196. START_MENU();
  1197. MENU_BACK(MSG_PREPARE);
  1198. #if HOTENDS == 1
  1199. #if TEMP_SENSOR_BED != 0
  1200. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1201. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1202. #else
  1203. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1204. #endif
  1205. #else
  1206. #if TEMP_SENSOR_BED != 0
  1207. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1208. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1209. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1210. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1211. #else
  1212. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1213. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1214. #endif
  1215. #if HOTENDS > 2
  1216. #if TEMP_SENSOR_BED != 0
  1217. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1218. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1219. #else
  1220. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1221. #endif
  1222. #if HOTENDS > 3
  1223. #if TEMP_SENSOR_BED != 0
  1224. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1225. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1226. #else
  1227. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1228. #endif
  1229. #if HOTENDS > 4
  1230. #if TEMP_SENSOR_BED != 0
  1231. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1232. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1233. #else
  1234. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1235. #endif
  1236. #endif // HOTENDS > 4
  1237. #endif // HOTENDS > 3
  1238. #endif // HOTENDS > 2
  1239. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1240. #endif // HOTENDS > 1
  1241. #if TEMP_SENSOR_BED != 0
  1242. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1243. #endif
  1244. END_MENU();
  1245. }
  1246. void lcd_preheat_m2_menu() {
  1247. START_MENU();
  1248. MENU_BACK(MSG_PREPARE);
  1249. #if HOTENDS == 1
  1250. #if TEMP_SENSOR_BED != 0
  1251. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1252. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1253. #else
  1254. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1255. #endif
  1256. #else
  1257. #if TEMP_SENSOR_BED != 0
  1258. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1259. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1260. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1261. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1262. #else
  1263. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1264. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1265. #endif
  1266. #if HOTENDS > 2
  1267. #if TEMP_SENSOR_BED != 0
  1268. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1269. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1270. #else
  1271. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1272. #endif
  1273. #if HOTENDS > 3
  1274. #if TEMP_SENSOR_BED != 0
  1275. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1276. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1277. #else
  1278. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1279. #endif
  1280. #if HOTENDS > 4
  1281. #if TEMP_SENSOR_BED != 0
  1282. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1283. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1284. #else
  1285. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1286. #endif
  1287. #endif // HOTENDS > 4
  1288. #endif // HOTENDS > 3
  1289. #endif // HOTENDS > 2
  1290. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1291. #endif // HOTENDS > 1
  1292. #if TEMP_SENSOR_BED != 0
  1293. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1294. #endif
  1295. END_MENU();
  1296. }
  1297. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED)
  1298. void lcd_cooldown() {
  1299. #if FAN_COUNT > 0
  1300. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1301. #endif
  1302. thermalManager.disable_all_heaters();
  1303. lcd_return_to_status();
  1304. }
  1305. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1306. void lcd_autostart_sd() {
  1307. card.autostart_index = 0;
  1308. card.setroot();
  1309. card.checkautostart(true);
  1310. }
  1311. #endif
  1312. #if ENABLED(EEPROM_SETTINGS)
  1313. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1314. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1315. #endif
  1316. #if ENABLED(LCD_BED_LEVELING)
  1317. /**
  1318. *
  1319. * "Prepare" > "Level Bed" handlers
  1320. *
  1321. */
  1322. static uint8_t manual_probe_index;
  1323. // LCD probed points are from defaults
  1324. constexpr uint8_t total_probe_points = (
  1325. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  1326. 3
  1327. #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
  1328. GRID_MAX_POINTS
  1329. #endif
  1330. );
  1331. //
  1332. // Raise Z to the "manual probe height"
  1333. // Don't return until done.
  1334. // ** This blocks the command queue! **
  1335. //
  1336. void _lcd_after_probing() {
  1337. #if MANUAL_PROBE_HEIGHT > 0
  1338. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1339. #endif
  1340. // Display "Done" screen and wait for moves to complete
  1341. #if MANUAL_PROBE_HEIGHT > 0 || ENABLED(MESH_BED_LEVELING)
  1342. lcd_synchronize(PSTR(MSG_LEVEL_BED_DONE));
  1343. #endif
  1344. lcd_goto_previous_menu();
  1345. lcd_completion_feedback();
  1346. defer_return_to_status = false;
  1347. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1348. }
  1349. #if ENABLED(MESH_BED_LEVELING)
  1350. // Utility to go to the next mesh point
  1351. inline void _manual_probe_goto_xy(float x, float y) {
  1352. #if MANUAL_PROBE_HEIGHT > 0
  1353. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1354. #endif
  1355. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1356. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1357. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1358. #if MANUAL_PROBE_HEIGHT > 0
  1359. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS));
  1360. #endif
  1361. lcd_synchronize();
  1362. }
  1363. #elif ENABLED(PROBE_MANUALLY)
  1364. bool lcd_wait_for_move;
  1365. //
  1366. // Bed leveling is done. Wait for G29 to complete.
  1367. // A flag is used so that this can release control
  1368. // and allow the command queue to be processed.
  1369. //
  1370. void _lcd_level_bed_done() {
  1371. if (!lcd_wait_for_move) _lcd_after_probing();
  1372. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1373. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1374. }
  1375. #endif
  1376. void _lcd_level_goto_next_point();
  1377. /**
  1378. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1379. */
  1380. void _lcd_level_bed_get_z() {
  1381. ENCODER_DIRECTION_NORMAL();
  1382. if (lcd_clicked) {
  1383. //
  1384. // Save the current Z position
  1385. //
  1386. #if ENABLED(MESH_BED_LEVELING)
  1387. //
  1388. // MBL records the position but doesn't move to the next one
  1389. //
  1390. mbl.set_zigzag_z(manual_probe_index, current_position[Z_AXIS]);
  1391. #endif
  1392. // If done...
  1393. if (++manual_probe_index >= total_probe_points) {
  1394. #if ENABLED(PROBE_MANUALLY)
  1395. //
  1396. // The last G29 will record and enable but not move.
  1397. //
  1398. lcd_wait_for_move = true;
  1399. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1400. lcd_goto_screen(_lcd_level_bed_done);
  1401. #elif ENABLED(MESH_BED_LEVELING)
  1402. _lcd_after_probing();
  1403. mbl.set_has_mesh(true);
  1404. mesh_probing_done();
  1405. #endif
  1406. }
  1407. else {
  1408. // MESH_BED_LEVELING: Z already stored, just move
  1409. // PROBE_MANUALLY: Send G29 to record Z, then move
  1410. _lcd_level_goto_next_point();
  1411. }
  1412. return;
  1413. }
  1414. //
  1415. // Encoder knob or keypad buttons adjust the Z position
  1416. //
  1417. if (encoderPosition) {
  1418. refresh_cmd_timeout();
  1419. const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1420. line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5));
  1421. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1422. encoderPosition = 0;
  1423. }
  1424. //
  1425. // Draw on first display, then only on Z change
  1426. //
  1427. if (lcdDrawUpdate) {
  1428. const float v = current_position[Z_AXIS];
  1429. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1430. }
  1431. }
  1432. /**
  1433. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1434. */
  1435. void _lcd_level_bed_moving() {
  1436. if (lcdDrawUpdate) {
  1437. char msg[10];
  1438. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1439. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1440. }
  1441. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1442. #if ENABLED(PROBE_MANUALLY)
  1443. if (!lcd_wait_for_move) lcd_goto_screen(_lcd_level_bed_get_z);
  1444. #endif
  1445. }
  1446. /**
  1447. * Step 5: Initiate a move to the next point
  1448. */
  1449. void _lcd_level_goto_next_point() {
  1450. // Set the menu to display ahead of blocking call
  1451. lcd_goto_screen(_lcd_level_bed_moving);
  1452. #if ENABLED(MESH_BED_LEVELING)
  1453. int8_t px, py;
  1454. mbl.zigzag(manual_probe_index, px, py);
  1455. // Controls the loop until the move is done
  1456. _manual_probe_goto_xy(
  1457. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1458. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1459. );
  1460. // After the blocking function returns, change menus
  1461. lcd_goto_screen(_lcd_level_bed_get_z);
  1462. #elif ENABLED(PROBE_MANUALLY)
  1463. // G29 Records Z, moves, and signals when it pauses
  1464. lcd_wait_for_move = true;
  1465. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1466. #endif
  1467. }
  1468. /**
  1469. * Step 4: Display "Click to Begin", wait for click
  1470. * Move to the first probe position
  1471. */
  1472. void _lcd_level_bed_homing_done() {
  1473. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1474. if (lcd_clicked) {
  1475. manual_probe_index = 0;
  1476. _lcd_level_goto_next_point();
  1477. }
  1478. }
  1479. /**
  1480. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1481. */
  1482. void _lcd_level_bed_homing() {
  1483. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1484. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1485. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1486. lcd_goto_screen(_lcd_level_bed_homing_done);
  1487. }
  1488. #if ENABLED(PROBE_MANUALLY)
  1489. extern bool g29_in_progress;
  1490. #endif
  1491. /**
  1492. * Step 2: Continue Bed Leveling...
  1493. */
  1494. void _lcd_level_bed_continue() {
  1495. defer_return_to_status = true;
  1496. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1497. lcd_goto_screen(_lcd_level_bed_homing);
  1498. enqueue_and_echo_commands_P(PSTR("G28"));
  1499. }
  1500. static bool _level_state;
  1501. void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(_level_state); }
  1502. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1503. void _lcd_set_z_fade_height() { set_z_fade_height(planner.z_fade_height); }
  1504. #endif
  1505. /**
  1506. * Step 1: Bed Level entry-point
  1507. * - Cancel
  1508. * - Auto Home (if homing needed)
  1509. * - Leveling On/Off (if data exists, and homed)
  1510. * - Level Bed >
  1511. * - Fade Height (Req: ENABLE_LEVELING_FADE_HEIGHT)
  1512. * - Mesh Z Offset (Req: MESH_BED_LEVELING)
  1513. * - Z Probe Offset (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
  1514. * - Load Settings (Req: EEPROM_SETTINGS)
  1515. * - Save Settings (Req: EEPROM_SETTINGS)
  1516. */
  1517. void lcd_bed_leveling() {
  1518. START_MENU();
  1519. MENU_BACK(MSG_PREPARE);
  1520. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1521. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1522. else if (leveling_is_valid()) {
  1523. _level_state = leveling_is_active();
  1524. MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
  1525. }
  1526. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1527. set_z_fade_height(planner.z_fade_height);
  1528. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
  1529. #endif
  1530. //
  1531. // MBL Z Offset
  1532. //
  1533. #if ENABLED(MESH_BED_LEVELING)
  1534. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1535. #endif
  1536. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1537. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1538. #elif HAS_BED_PROBE
  1539. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  1540. #endif
  1541. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1542. #if ENABLED(EEPROM_SETTINGS)
  1543. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  1544. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  1545. #endif
  1546. END_MENU();
  1547. }
  1548. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1549. void _lcd_ubl_level_bed();
  1550. static int ubl_storage_slot = 0,
  1551. custom_bed_temp = 50,
  1552. custom_hotend_temp = 190,
  1553. side_points = 3,
  1554. ubl_fillin_amount = 5,
  1555. ubl_height_amount = 1,
  1556. n_edit_pts = 1,
  1557. x_plot = 0,
  1558. y_plot = 0;
  1559. /**
  1560. * UBL Build Custom Mesh Command
  1561. */
  1562. void _lcd_ubl_build_custom_mesh() {
  1563. char UBL_LCD_GCODE[20];
  1564. enqueue_and_echo_commands_P(PSTR("G28"));
  1565. #if HAS_TEMP_BED
  1566. sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
  1567. enqueue_and_echo_command(UBL_LCD_GCODE);
  1568. #endif
  1569. sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
  1570. enqueue_and_echo_command(UBL_LCD_GCODE);
  1571. enqueue_and_echo_commands_P(PSTR("G29 P1"));
  1572. }
  1573. /**
  1574. * UBL Custom Mesh submenu
  1575. */
  1576. void _lcd_ubl_custom_mesh() {
  1577. START_MENU();
  1578. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1579. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_HOTEND_TEMP, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
  1580. #if HAS_TEMP_BED
  1581. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_BED_TEMP, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 5));
  1582. #endif
  1583. MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  1584. END_MENU();
  1585. }
  1586. /**
  1587. * UBL Adjust Mesh Height Command
  1588. */
  1589. void _lcd_ubl_adjust_height_cmd() {
  1590. char UBL_LCD_GCODE[16];
  1591. const int ind = ubl_height_amount < 0 ? 6 : 7;
  1592. strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6-"));
  1593. sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
  1594. enqueue_and_echo_command(UBL_LCD_GCODE);
  1595. }
  1596. /**
  1597. * UBL Adjust Mesh Height submenu
  1598. */
  1599. void _lcd_ubl_height_adjust_menu() {
  1600. START_MENU();
  1601. MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
  1602. MENU_ITEM_EDIT(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9);
  1603. MENU_ITEM(function, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_adjust_height_cmd);
  1604. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1605. END_MENU();
  1606. }
  1607. /**
  1608. * UBL Edit Mesh submenu
  1609. */
  1610. void _lcd_ubl_edit_mesh() {
  1611. START_MENU();
  1612. MENU_BACK(MSG_UBL_TOOLS);
  1613. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  1614. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  1615. MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_height_adjust_menu);
  1616. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1617. END_MENU();
  1618. }
  1619. /**
  1620. * UBL Validate Custom Mesh Command
  1621. */
  1622. void _lcd_ubl_validate_custom_mesh() {
  1623. char UBL_LCD_GCODE[24];
  1624. const int temp =
  1625. #if HAS_TEMP_BED
  1626. custom_bed_temp
  1627. #else
  1628. 0
  1629. #endif
  1630. ;
  1631. sprintf_P(UBL_LCD_GCODE, PSTR("G28\nG26 C B%i H%i P"), temp, custom_hotend_temp);
  1632. enqueue_and_echo_command(UBL_LCD_GCODE);
  1633. }
  1634. /**
  1635. * UBL Validate Mesh submenu
  1636. */
  1637. void _lcd_ubl_validate_mesh() {
  1638. START_MENU();
  1639. MENU_BACK(MSG_UBL_TOOLS);
  1640. #if HAS_TEMP_BED
  1641. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1642. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1643. #else
  1644. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1645. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1646. #endif
  1647. MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  1648. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1649. END_MENU();
  1650. }
  1651. /**
  1652. * UBL Grid Leveling Command
  1653. */
  1654. void _lcd_ubl_grid_level_cmd() {
  1655. char UBL_LCD_GCODE[10];
  1656. sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
  1657. enqueue_and_echo_command(UBL_LCD_GCODE);
  1658. }
  1659. /**
  1660. * UBL Grid Leveling submenu
  1661. */
  1662. void _lcd_ubl_grid_level() {
  1663. START_MENU();
  1664. MENU_BACK(MSG_UBL_TOOLS);
  1665. MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  1666. MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
  1667. END_MENU();
  1668. }
  1669. /**
  1670. * UBL Mesh Leveling submenu
  1671. */
  1672. void _lcd_ubl_mesh_leveling() {
  1673. START_MENU();
  1674. MENU_BACK(MSG_UBL_TOOLS);
  1675. MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  1676. MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  1677. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1678. END_MENU();
  1679. }
  1680. /**
  1681. * UBL Fill-in Amount Mesh Command
  1682. */
  1683. void _lcd_ubl_fillin_amount_cmd() {
  1684. char UBL_LCD_GCODE[16];
  1685. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  1686. enqueue_and_echo_command(UBL_LCD_GCODE);
  1687. }
  1688. /**
  1689. * UBL Smart Fill-in Command
  1690. */
  1691. void _lcd_ubl_smart_fillin_cmd() {
  1692. char UBL_LCD_GCODE[12];
  1693. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 T0"));
  1694. enqueue_and_echo_command(UBL_LCD_GCODE);
  1695. }
  1696. /**
  1697. * UBL Fill-in Mesh submenu
  1698. */
  1699. void _lcd_ubl_fillin_menu() {
  1700. START_MENU();
  1701. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1702. MENU_ITEM_EDIT(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9);
  1703. MENU_ITEM(function, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_amount_cmd);
  1704. MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
  1705. MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  1706. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1707. END_MENU();
  1708. }
  1709. void _lcd_ubl_invalidate() {
  1710. ubl.invalidate();
  1711. SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
  1712. }
  1713. /**
  1714. * UBL Build Mesh submenu
  1715. */
  1716. void _lcd_ubl_build_mesh() {
  1717. START_MENU();
  1718. MENU_BACK(MSG_UBL_TOOLS);
  1719. #if HAS_TEMP_BED
  1720. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1721. "G28\n"
  1722. "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
  1723. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1724. "G29 P1\n"
  1725. "M104 S0\n"
  1726. "M140 S0"
  1727. ));
  1728. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1729. "G28\n"
  1730. "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
  1731. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1732. "G29 P1\n"
  1733. "M104 S0\n"
  1734. "M140 S0"
  1735. ));
  1736. #else
  1737. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1738. "G28\n"
  1739. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1740. "G29 P1\n"
  1741. "M104 S0"
  1742. ));
  1743. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1744. "G28\n"
  1745. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1746. "G29 P1\n"
  1747. "M104 S0"
  1748. ));
  1749. #endif
  1750. MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  1751. MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  1752. MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_menu);
  1753. MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  1754. MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  1755. MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  1756. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1757. END_MENU();
  1758. }
  1759. /**
  1760. * UBL Load Mesh Command
  1761. */
  1762. void _lcd_ubl_load_mesh_cmd() {
  1763. char UBL_LCD_GCODE[8];
  1764. sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
  1765. enqueue_and_echo_command(UBL_LCD_GCODE);
  1766. }
  1767. /**
  1768. * UBL Save Mesh Command
  1769. */
  1770. void _lcd_ubl_save_mesh_cmd() {
  1771. char UBL_LCD_GCODE[8];
  1772. sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
  1773. enqueue_and_echo_command(UBL_LCD_GCODE);
  1774. }
  1775. /**
  1776. * UBL Mesh Storage submenu
  1777. */
  1778. void _lcd_ubl_storage_mesh() {
  1779. START_MENU();
  1780. MENU_BACK(MSG_UBL_LEVEL_BED);
  1781. MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, 9);
  1782. MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  1783. MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  1784. END_MENU();
  1785. }
  1786. /**
  1787. * UBL LCD "radar" map homing
  1788. */
  1789. void _lcd_ubl_output_map_lcd();
  1790. void _lcd_ubl_map_homing() {
  1791. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1792. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1793. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1794. lcd_goto_screen(_lcd_ubl_output_map_lcd);
  1795. }
  1796. /**
  1797. * UBL LCD "radar" map point editing
  1798. */
  1799. void _lcd_ubl_map_lcd_edit_cmd() {
  1800. char ubl_lcd_gcode [50], str[10], str2[10];
  1801. ubl_lcd_map_control = true; // Used for returning to the map screen
  1802. dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
  1803. dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
  1804. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
  1805. enqueue_and_echo_command(ubl_lcd_gcode);
  1806. }
  1807. #if ENABLED(DOGLCD)
  1808. /**
  1809. * UBL LCD "radar" map data
  1810. */
  1811. #define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
  1812. #define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
  1813. #define MAP_MAX_PIXELS_X 53
  1814. #define MAP_MAX_PIXELS_Y 49
  1815. void _lcd_ubl_plot_drawing_prep() {
  1816. uint8_t i, j, x_offset, y_offset, x_map_pixels, y_map_pixels,
  1817. pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt, inverted_y;
  1818. /*********************************************************/
  1819. /************ Scale the box pixels appropriately *********/
  1820. /*********************************************************/
  1821. x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / GRID_MAX_POINTS_X) * GRID_MAX_POINTS_X;
  1822. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / GRID_MAX_POINTS_Y) * GRID_MAX_POINTS_Y;
  1823. pixels_per_X_mesh_pnt = x_map_pixels / GRID_MAX_POINTS_X;
  1824. pixels_per_Y_mesh_pnt = y_map_pixels / GRID_MAX_POINTS_Y;
  1825. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2;
  1826. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  1827. /*********************************************************/
  1828. /************ Clear the Mesh Map Box**********************/
  1829. /*********************************************************/
  1830. u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
  1831. u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
  1832. u8g.setColorIndex(0); // Now actually clear the mesh map box
  1833. u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
  1834. /*********************************************************/
  1835. /************ Display Mesh Point Locations ***************/
  1836. /*********************************************************/
  1837. u8g.setColorIndex(1);
  1838. for (i = 0; i < GRID_MAX_POINTS_X; i++) {
  1839. for (j = 0; j < GRID_MAX_POINTS_Y; j++) {
  1840. u8g.drawBox(x_offset + i * pixels_per_X_mesh_pnt + pixels_per_X_mesh_pnt / 2,
  1841. y_offset + j * pixels_per_Y_mesh_pnt + pixels_per_Y_mesh_pnt / 2, 1, 1);
  1842. }
  1843. }
  1844. /*********************************************************/
  1845. /************ Fill in the Specified Mesh Point ***********/
  1846. /*********************************************************/
  1847. inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
  1848. // invert the Y to get it to plot in the right location.
  1849. u8g.drawBox(x_offset + x_plot * pixels_per_X_mesh_pnt, y_offset + inverted_y * pixels_per_Y_mesh_pnt,
  1850. pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt);
  1851. /*********************************************************/
  1852. /************** Put Relevent Text on Display *************/
  1853. /*********************************************************/
  1854. // Show X and Y positions at top of screen
  1855. u8g.setColorIndex(1);
  1856. u8g.setPrintPos(5, 7);
  1857. lcd_print("X:");
  1858. lcd_print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
  1859. u8g.setPrintPos(74, 7);
  1860. lcd_print("Y:");
  1861. lcd_print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
  1862. // Print plot position
  1863. u8g.setPrintPos(5, 64);
  1864. lcd_print('(');
  1865. u8g.print(x_plot);
  1866. lcd_print(',');
  1867. u8g.print(y_plot);
  1868. lcd_print(')');
  1869. // Show the location value
  1870. u8g.setPrintPos(74, 64);
  1871. lcd_print("Z:");
  1872. if (!isnan(ubl.z_values[x_plot][y_plot])) {
  1873. lcd_print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  1874. }
  1875. else {
  1876. lcd_print(" -----");
  1877. }
  1878. }
  1879. #endif // DOGLCD
  1880. /**
  1881. * UBL LCD Map Movement
  1882. */
  1883. void ubl_map_move_to_xy() {
  1884. current_position[X_AXIS] = LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]));
  1885. current_position[Y_AXIS] = LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]));
  1886. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1887. }
  1888. /**
  1889. * UBL LCD "radar" map
  1890. */
  1891. void set_current_from_steppers_for_axis(const AxisEnum axis);
  1892. void sync_plan_position();
  1893. void _lcd_ubl_output_map_lcd() {
  1894. static int step_scaler=0;
  1895. int32_t signed_enc_pos;
  1896. defer_return_to_status = true;
  1897. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]) {
  1898. if (lcd_clicked) { return _lcd_ubl_map_lcd_edit_cmd(); }
  1899. ENCODER_DIRECTION_NORMAL();
  1900. if (encoderPosition != 0) {
  1901. signed_enc_pos = (int32_t)encoderPosition;
  1902. step_scaler += signed_enc_pos;
  1903. x_plot = (x_plot + step_scaler / ENCODER_STEPS_PER_MENU_ITEM);
  1904. if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM)
  1905. step_scaler = 0;
  1906. refresh_cmd_timeout();
  1907. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1908. }
  1909. encoderPosition = 0;
  1910. // Encoder to the right (++)
  1911. if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
  1912. if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
  1913. // Encoder to the left (--)
  1914. if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
  1915. if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
  1916. // Prevent underrun/overrun of plot numbers
  1917. x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
  1918. y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
  1919. // Determine number of points to edit
  1920. #if IS_KINEMATIC
  1921. n_edit_pts = 9; //TODO: Delta accessible edit points
  1922. #else
  1923. if (x_plot < 1 || x_plot >= GRID_MAX_POINTS_X - 1)
  1924. if (y_plot < 1 || y_plot >= GRID_MAX_POINTS_Y - 1) n_edit_pts = 4; // Corners
  1925. else n_edit_pts = 6;
  1926. else if (y_plot < 1 || y_plot >= GRID_MAX_POINTS_Y - 1) n_edit_pts = 6; // Edges
  1927. else n_edit_pts = 9; // Field
  1928. #endif
  1929. if (lcdDrawUpdate) {
  1930. #if ENABLED(DOGLCD)
  1931. _lcd_ubl_plot_drawing_prep();
  1932. #else
  1933. _lcd_ubl_output_char_lcd();
  1934. #endif
  1935. ubl_map_move_to_xy(); // Move to current location
  1936. if (planner.movesplanned()>1) { // if the nozzle is moving, cancel the move. There is a new location
  1937. #define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
  1938. #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
  1939. DISABLE_STEPPER_DRIVER_INTERRUPT();
  1940. while (planner.blocks_queued()) planner.discard_current_block();
  1941. stepper.current_block = NULL;
  1942. planner.clear_block_buffer_runtime();
  1943. ENABLE_STEPPER_DRIVER_INTERRUPT();
  1944. set_current_from_steppers_for_axis(ALL_AXES);
  1945. sync_plan_position();
  1946. ubl_map_move_to_xy(); // Move to new location
  1947. }
  1948. }
  1949. safe_delay(10);
  1950. }
  1951. else lcd_goto_screen(_lcd_ubl_map_homing);
  1952. }
  1953. /**
  1954. * UBL Homing before LCD map
  1955. */
  1956. void _lcd_ubl_output_map_lcd_cmd() {
  1957. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1958. enqueue_and_echo_commands_P(PSTR("G28"));
  1959. lcd_goto_screen(_lcd_ubl_map_homing);
  1960. }
  1961. /**
  1962. * UBL Output map submenu
  1963. */
  1964. void _lcd_ubl_output_map() {
  1965. START_MENU();
  1966. MENU_BACK(MSG_UBL_LEVEL_BED);
  1967. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
  1968. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
  1969. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
  1970. MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
  1971. END_MENU();
  1972. }
  1973. /**
  1974. * UBL Tools submenu
  1975. */
  1976. void _lcd_ubl_tools_menu() {
  1977. START_MENU();
  1978. MENU_BACK(MSG_UBL_LEVEL_BED);
  1979. MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  1980. MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  1981. MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
  1982. MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  1983. END_MENU();
  1984. }
  1985. /**
  1986. * UBL System submenu
  1987. *
  1988. * Prepare
  1989. * - Unified Bed Leveling
  1990. * - Manually Build Mesh
  1991. * - Activate UBL
  1992. * - Deactivate UBL
  1993. * - Mesh Storage
  1994. * Memory Slot:
  1995. * Load Bed Mesh
  1996. * Save Bed Mesh
  1997. * - Output Map
  1998. * Topography to Host
  1999. * CSV for Spreadsheet
  2000. * Mesh Output Backup
  2001. * Output to LCD Grid
  2002. * - UBL Tools
  2003. * - Build Mesh
  2004. * Build PLA Mesh
  2005. * Build ABS Mesh
  2006. * - Build Custom Mesh
  2007. * Hotend Temp:
  2008. * Bed Temp:
  2009. * Build Custom Mesh
  2010. * Info Screen
  2011. * - Build Cold Mesh
  2012. * - Fill-in Mesh
  2013. * Fill-in Mesh
  2014. * Smart Fill-in
  2015. * Manual Fill-in
  2016. * Info Screen
  2017. * Continue Bed Mesh
  2018. * Invalidate All
  2019. * Invalidate Closest
  2020. * - Validate Mesh
  2021. * PLA Mesh Validation
  2022. * ABS Mesh Validation
  2023. * - Custom Mesh Validation
  2024. * Hotend Temp:
  2025. * Bed Temp:
  2026. * Validate Mesh
  2027. * Info Screen
  2028. * - Edit Mesh
  2029. * Fine Tune All
  2030. * Fine Tune Closest
  2031. * - Adjust Mesh Height
  2032. * Height Amount:
  2033. * Adjust Mesh Height
  2034. * Info Screen
  2035. * - Mesh Leveling
  2036. * 3-Point Mesh Leveling
  2037. * - Grid Mesh Leveling
  2038. * Side points:
  2039. * Level Mesh
  2040. * Info Screen
  2041. * - Output UBL Info
  2042. */
  2043. void _lcd_ubl_level_bed() {
  2044. START_MENU();
  2045. MENU_BACK(MSG_PREPARE);
  2046. MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
  2047. MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  2048. MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  2049. MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  2050. MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  2051. MENU_ITEM(submenu, MSG_UBL_TOOLS, _lcd_ubl_tools_menu);
  2052. MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
  2053. END_MENU();
  2054. }
  2055. #endif // AUTO_BED_LEVELING_UBL
  2056. /**
  2057. *
  2058. * "Prepare" submenu
  2059. *
  2060. */
  2061. void lcd_prepare_menu() {
  2062. START_MENU();
  2063. //
  2064. // ^ Main
  2065. //
  2066. MENU_BACK(MSG_MAIN);
  2067. //
  2068. // Move Axis
  2069. //
  2070. #if ENABLED(DELTA)
  2071. if (axis_homed[Z_AXIS])
  2072. #endif
  2073. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  2074. //
  2075. // Auto Home
  2076. //
  2077. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2078. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  2079. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  2080. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  2081. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  2082. #endif
  2083. //
  2084. // Level Bed
  2085. //
  2086. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2087. MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  2088. #elif ENABLED(LCD_BED_LEVELING)
  2089. #if ENABLED(PROBE_MANUALLY)
  2090. if (!g29_in_progress)
  2091. #endif
  2092. MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
  2093. #endif
  2094. #if HAS_M206_COMMAND
  2095. //
  2096. // Set Home Offsets
  2097. //
  2098. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  2099. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  2100. #endif
  2101. //
  2102. // Disable Steppers
  2103. //
  2104. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2105. //
  2106. // Change filament
  2107. //
  2108. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2109. if (!thermalManager.tooColdToExtrude(active_extruder))
  2110. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  2111. #endif
  2112. #if TEMP_SENSOR_0 != 0
  2113. //
  2114. // Cooldown
  2115. //
  2116. bool has_heat = false;
  2117. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  2118. #if HAS_TEMP_BED
  2119. if (thermalManager.target_temperature_bed) has_heat = true;
  2120. #endif
  2121. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  2122. //
  2123. // Preheat for Material 1 and 2
  2124. //
  2125. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0
  2126. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  2127. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  2128. #else
  2129. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  2130. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  2131. #endif
  2132. #endif // TEMP_SENSOR_0 != 0
  2133. //
  2134. // BLTouch Self-Test and Reset
  2135. //
  2136. #if ENABLED(BLTOUCH)
  2137. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  2138. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  2139. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  2140. #endif
  2141. //
  2142. // Switch power on/off
  2143. //
  2144. #if HAS_POWER_SWITCH
  2145. if (powersupply_on)
  2146. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  2147. else
  2148. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  2149. #endif
  2150. //
  2151. // Autostart
  2152. //
  2153. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  2154. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  2155. #endif
  2156. END_MENU();
  2157. }
  2158. float move_menu_scale;
  2159. #if ENABLED(DELTA_CALIBRATION_MENU)
  2160. void lcd_move_z();
  2161. void lcd_delta_calibrate_menu();
  2162. void _lcd_calibrate_homing() {
  2163. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  2164. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  2165. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2166. lcd_goto_previous_menu();
  2167. }
  2168. void _lcd_delta_calibrate_home() {
  2169. #if HAS_LEVELING
  2170. reset_bed_level(); // After calibration bed-level data is no longer valid
  2171. #endif
  2172. enqueue_and_echo_commands_P(PSTR("G28"));
  2173. lcd_goto_screen(_lcd_calibrate_homing);
  2174. }
  2175. // Move directly to the tower position with uninterpolated moves
  2176. // If we used interpolated moves it would cause this to become re-entrant
  2177. void _goto_tower_pos(const float &a) {
  2178. #if HAS_LEVELING
  2179. reset_bed_level(); // After calibration bed-level data is no longer valid
  2180. #endif
  2181. line_to_z(max(Z_HOMING_HEIGHT, Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5);
  2182. current_position[X_AXIS] = a < 0 ? LOGICAL_X_POSITION(X_HOME_POS) : cos(RADIANS(a)) * delta_calibration_radius;
  2183. current_position[Y_AXIS] = a < 0 ? LOGICAL_Y_POSITION(Y_HOME_POS) : sin(RADIANS(a)) * delta_calibration_radius;
  2184. line_to_current_z();
  2185. line_to_z(4.0);
  2186. lcd_synchronize();
  2187. move_menu_scale = 0.1;
  2188. lcd_goto_screen(lcd_move_z);
  2189. }
  2190. void _goto_tower_x() { _goto_tower_pos(210); }
  2191. void _goto_tower_y() { _goto_tower_pos(330); }
  2192. void _goto_tower_z() { _goto_tower_pos(90); }
  2193. void _goto_center() { _goto_tower_pos(-1); }
  2194. void lcd_delta_calibrate_menu() {
  2195. START_MENU();
  2196. MENU_BACK(MSG_MAIN);
  2197. #if ENABLED(DELTA_AUTO_CALIBRATION)
  2198. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33"));
  2199. MENU_ITEM(gcode, MSG_DELTA_HEIGHT_CALIBRATE, PSTR("G33 P1"));
  2200. #endif
  2201. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  2202. if (axis_homed[Z_AXIS]) {
  2203. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  2204. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  2205. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  2206. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  2207. }
  2208. END_MENU();
  2209. }
  2210. #endif // DELTA_CALIBRATION_MENU
  2211. /**
  2212. * If the most recent manual move hasn't been fed to the planner yet,
  2213. * and the planner can accept one, send immediately
  2214. */
  2215. inline void manage_manual_move() {
  2216. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  2217. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  2218. manual_move_axis = (int8_t)NO_AXIS;
  2219. }
  2220. }
  2221. /**
  2222. * Set a flag that lcd_update() should start a move
  2223. * to "current_position" after a short delay.
  2224. */
  2225. inline void manual_move_to_current(AxisEnum axis
  2226. #if E_MANUAL > 1
  2227. , int8_t eindex=-1
  2228. #endif
  2229. ) {
  2230. #if E_MANUAL > 1
  2231. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  2232. #endif
  2233. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  2234. manual_move_axis = (int8_t)axis;
  2235. }
  2236. /**
  2237. *
  2238. * "Prepare" > "Move Axis" submenu
  2239. *
  2240. */
  2241. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  2242. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2243. ENCODER_DIRECTION_NORMAL();
  2244. if (encoderPosition) {
  2245. refresh_cmd_timeout();
  2246. float min = current_position[axis] - 1000,
  2247. max = current_position[axis] + 1000;
  2248. #if HAS_SOFTWARE_ENDSTOPS
  2249. // Limit to software endstops, if enabled
  2250. if (soft_endstops_enabled) {
  2251. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  2252. min = soft_endstop_min[axis];
  2253. #endif
  2254. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  2255. max = soft_endstop_max[axis];
  2256. #endif
  2257. }
  2258. #endif
  2259. // Get the new position
  2260. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  2261. // Delta limits XY based on the current offset from center
  2262. // This assumes the center is 0,0
  2263. #if ENABLED(DELTA)
  2264. if (axis != Z_AXIS) {
  2265. max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  2266. min = -max;
  2267. }
  2268. #endif
  2269. // Limit only when trying to move towards the limit
  2270. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  2271. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  2272. manual_move_to_current(axis);
  2273. encoderPosition = 0;
  2274. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2275. }
  2276. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  2277. }
  2278. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  2279. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  2280. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  2281. void _lcd_move_e(
  2282. #if E_MANUAL > 1
  2283. int8_t eindex=-1
  2284. #endif
  2285. ) {
  2286. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2287. ENCODER_DIRECTION_NORMAL();
  2288. if (encoderPosition) {
  2289. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  2290. encoderPosition = 0;
  2291. manual_move_to_current(E_AXIS
  2292. #if E_MANUAL > 1
  2293. , eindex
  2294. #endif
  2295. );
  2296. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2297. }
  2298. if (lcdDrawUpdate) {
  2299. PGM_P pos_label;
  2300. #if E_MANUAL == 1
  2301. pos_label = PSTR(MSG_MOVE_E);
  2302. #else
  2303. switch (eindex) {
  2304. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  2305. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  2306. #if E_MANUAL > 2
  2307. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  2308. #if E_MANUAL > 3
  2309. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  2310. #if E_MANUAL > 4
  2311. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  2312. #endif // E_MANUAL > 4
  2313. #endif // E_MANUAL > 3
  2314. #endif // E_MANUAL > 2
  2315. }
  2316. #endif // E_MANUAL > 1
  2317. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  2318. }
  2319. }
  2320. void lcd_move_e() { _lcd_move_e(); }
  2321. #if E_MANUAL > 1
  2322. void lcd_move_e0() { _lcd_move_e(0); }
  2323. void lcd_move_e1() { _lcd_move_e(1); }
  2324. #if E_MANUAL > 2
  2325. void lcd_move_e2() { _lcd_move_e(2); }
  2326. #if E_MANUAL > 3
  2327. void lcd_move_e3() { _lcd_move_e(3); }
  2328. #if E_MANUAL > 4
  2329. void lcd_move_e4() { _lcd_move_e(4); }
  2330. #endif // E_MANUAL > 4
  2331. #endif // E_MANUAL > 3
  2332. #endif // E_MANUAL > 2
  2333. #endif // E_MANUAL > 1
  2334. /**
  2335. *
  2336. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  2337. *
  2338. */
  2339. screenFunc_t _manual_move_func_ptr;
  2340. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  2341. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  2342. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  2343. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  2344. _manual_move_func_ptr = func;
  2345. START_MENU();
  2346. if (LCD_HEIGHT >= 4) {
  2347. switch(axis) {
  2348. case X_AXIS:
  2349. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  2350. case Y_AXIS:
  2351. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  2352. case Z_AXIS:
  2353. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  2354. default:
  2355. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  2356. }
  2357. }
  2358. MENU_BACK(MSG_MOVE_AXIS);
  2359. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  2360. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  2361. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  2362. END_MENU();
  2363. }
  2364. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  2365. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  2366. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  2367. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  2368. #if E_MANUAL > 1
  2369. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  2370. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  2371. #if E_MANUAL > 2
  2372. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  2373. #if E_MANUAL > 3
  2374. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  2375. #if E_MANUAL > 4
  2376. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  2377. #endif // E_MANUAL > 4
  2378. #endif // E_MANUAL > 3
  2379. #endif // E_MANUAL > 2
  2380. #endif // E_MANUAL > 1
  2381. /**
  2382. *
  2383. * "Prepare" > "Move Axis" submenu
  2384. *
  2385. */
  2386. #if IS_KINEMATIC
  2387. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2388. #if ENABLED(DELTA)
  2389. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  2390. void lcd_lower_z_to_clip_height() {
  2391. line_to_z(delta_clip_start_height);
  2392. lcd_synchronize();
  2393. }
  2394. #else
  2395. #define _MOVE_XY_ALLOWED true
  2396. #endif
  2397. #else
  2398. #define _MOVE_XYZ_ALLOWED true
  2399. #define _MOVE_XY_ALLOWED true
  2400. #endif
  2401. void lcd_move_menu() {
  2402. START_MENU();
  2403. MENU_BACK(MSG_PREPARE);
  2404. if (_MOVE_XYZ_ALLOWED) {
  2405. if (_MOVE_XY_ALLOWED) {
  2406. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  2407. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  2408. }
  2409. #if ENABLED(DELTA)
  2410. else
  2411. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  2412. #endif
  2413. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  2414. }
  2415. else
  2416. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2417. #if ENABLED(SWITCHING_EXTRUDER)
  2418. if (active_extruder)
  2419. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2420. else
  2421. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2422. #endif
  2423. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  2424. #if E_MANUAL > 1
  2425. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  2426. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  2427. #if E_MANUAL > 2
  2428. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  2429. #if E_MANUAL > 3
  2430. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  2431. #if E_MANUAL > 4
  2432. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  2433. #endif // E_MANUAL > 4
  2434. #endif // E_MANUAL > 3
  2435. #endif // E_MANUAL > 2
  2436. #endif // E_MANUAL > 1
  2437. END_MENU();
  2438. }
  2439. /**
  2440. *
  2441. * "Control" submenu
  2442. *
  2443. */
  2444. #if HAS_LCD_CONTRAST
  2445. void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
  2446. #endif
  2447. static void lcd_factory_settings() {
  2448. settings.reset();
  2449. lcd_completion_feedback();
  2450. }
  2451. void lcd_control_menu() {
  2452. START_MENU();
  2453. MENU_BACK(MSG_MAIN);
  2454. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2455. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  2456. MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
  2457. #if HAS_LCD_CONTRAST
  2458. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, (int*)&lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
  2459. #endif
  2460. #if ENABLED(FWRETRACT)
  2461. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  2462. #endif
  2463. #if ENABLED(DAC_STEPPER_CURRENT)
  2464. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  2465. #endif
  2466. #if ENABLED(BLTOUCH)
  2467. MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);
  2468. #endif
  2469. #if ENABLED(EEPROM_SETTINGS)
  2470. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2471. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2472. #endif
  2473. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  2474. #if ENABLED(EEPROM_SETTINGS)
  2475. MENU_ITEM(gcode, MSG_INIT_EEPROM, PSTR("M502\nM500")); // TODO: Add "Are You Sure?" step
  2476. #endif
  2477. END_MENU();
  2478. }
  2479. /**
  2480. *
  2481. * "Temperature" submenu
  2482. *
  2483. */
  2484. #if ENABLED(PID_AUTOTUNE_MENU)
  2485. #if ENABLED(PIDTEMP)
  2486. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  2487. #endif
  2488. #if ENABLED(PIDTEMPBED)
  2489. int autotune_temp_bed = 70;
  2490. #endif
  2491. void _lcd_autotune(int e) {
  2492. char cmd[30];
  2493. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  2494. #if HAS_PID_FOR_BOTH
  2495. e < 0 ? autotune_temp_bed : autotune_temp[e]
  2496. #elif ENABLED(PIDTEMPBED)
  2497. autotune_temp_bed
  2498. #else
  2499. autotune_temp[e]
  2500. #endif
  2501. );
  2502. enqueue_and_echo_command(cmd);
  2503. }
  2504. #endif // PID_AUTOTUNE_MENU
  2505. #if ENABLED(PIDTEMP)
  2506. // Helpers for editing PID Ki & Kd values
  2507. // grab the PID value out of the temp variable; scale it; then update the PID driver
  2508. void copy_and_scalePID_i(int e) {
  2509. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2510. UNUSED(e);
  2511. #endif
  2512. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  2513. thermalManager.updatePID();
  2514. }
  2515. void copy_and_scalePID_d(int e) {
  2516. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2517. UNUSED(e);
  2518. #endif
  2519. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  2520. thermalManager.updatePID();
  2521. }
  2522. #define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
  2523. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  2524. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  2525. #if ENABLED(PID_AUTOTUNE_MENU)
  2526. #define DEFINE_PIDTEMP_FUNCS(N) \
  2527. _DEFINE_PIDTEMP_BASE_FUNCS(N); \
  2528. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); } typedef void _pid_##N##_void
  2529. #else
  2530. #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N) typedef void _pid_##N##_void
  2531. #endif
  2532. DEFINE_PIDTEMP_FUNCS(0);
  2533. #if ENABLED(PID_PARAMS_PER_HOTEND)
  2534. #if HOTENDS > 1
  2535. DEFINE_PIDTEMP_FUNCS(1);
  2536. #if HOTENDS > 2
  2537. DEFINE_PIDTEMP_FUNCS(2);
  2538. #if HOTENDS > 3
  2539. DEFINE_PIDTEMP_FUNCS(3);
  2540. #if HOTENDS > 4
  2541. DEFINE_PIDTEMP_FUNCS(4);
  2542. #endif // HOTENDS > 4
  2543. #endif // HOTENDS > 3
  2544. #endif // HOTENDS > 2
  2545. #endif // HOTENDS > 1
  2546. #endif // PID_PARAMS_PER_HOTEND
  2547. #endif // PIDTEMP
  2548. /**
  2549. *
  2550. * "Control" > "Temperature" submenu
  2551. *
  2552. */
  2553. void lcd_control_temperature_menu() {
  2554. START_MENU();
  2555. //
  2556. // ^ Control
  2557. //
  2558. MENU_BACK(MSG_CONTROL);
  2559. //
  2560. // Nozzle:
  2561. // Nozzle [1-5]:
  2562. //
  2563. #if HOTENDS == 1
  2564. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2565. #else // HOTENDS > 1
  2566. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2567. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  2568. #if HOTENDS > 2
  2569. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  2570. #if HOTENDS > 3
  2571. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  2572. #if HOTENDS > 4
  2573. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  2574. #endif // HOTENDS > 4
  2575. #endif // HOTENDS > 3
  2576. #endif // HOTENDS > 2
  2577. #endif // HOTENDS > 1
  2578. //
  2579. // Bed:
  2580. //
  2581. #if HAS_TEMP_BED
  2582. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  2583. #endif
  2584. //
  2585. // Fan Speed:
  2586. //
  2587. #if FAN_COUNT > 0
  2588. #if HAS_FAN0
  2589. #if FAN_COUNT > 1
  2590. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  2591. #else
  2592. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  2593. #endif
  2594. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  2595. #endif
  2596. #if HAS_FAN1
  2597. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  2598. #endif
  2599. #if HAS_FAN2
  2600. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  2601. #endif
  2602. #endif // FAN_COUNT > 0
  2603. //
  2604. // Autotemp, Min, Max, Fact
  2605. //
  2606. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  2607. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  2608. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  2609. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  2610. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  2611. #endif
  2612. //
  2613. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  2614. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  2615. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  2616. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  2617. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  2618. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  2619. //
  2620. #if ENABLED(PIDTEMP)
  2621. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  2622. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  2623. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  2624. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  2625. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  2626. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  2627. #if ENABLED(PID_EXTRUSION_SCALING)
  2628. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  2629. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  2630. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  2631. #else
  2632. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  2633. #endif
  2634. #if ENABLED(PID_AUTOTUNE_MENU)
  2635. #define PID_MENU_ITEMS(ELABEL, eindex) \
  2636. _PID_MENU_ITEMS(ELABEL, eindex); \
  2637. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  2638. #else
  2639. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  2640. #endif
  2641. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  2642. PID_MENU_ITEMS(" " MSG_E1, 0);
  2643. PID_MENU_ITEMS(" " MSG_E2, 1);
  2644. #if HOTENDS > 2
  2645. PID_MENU_ITEMS(" " MSG_E3, 2);
  2646. #if HOTENDS > 3
  2647. PID_MENU_ITEMS(" " MSG_E4, 3);
  2648. #if HOTENDS > 4
  2649. PID_MENU_ITEMS(" " MSG_E5, 4);
  2650. #endif // HOTENDS > 4
  2651. #endif // HOTENDS > 3
  2652. #endif // HOTENDS > 2
  2653. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2654. PID_MENU_ITEMS("", 0);
  2655. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2656. #endif // PIDTEMP
  2657. //
  2658. // Preheat Material 1 conf
  2659. //
  2660. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  2661. //
  2662. // Preheat Material 2 conf
  2663. //
  2664. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  2665. END_MENU();
  2666. }
  2667. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  2668. #if HOTENDS > 4
  2669. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  2670. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  2671. #elif HOTENDS > 3
  2672. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  2673. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  2674. #elif HOTENDS > 2
  2675. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  2676. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  2677. #elif HOTENDS > 1
  2678. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  2679. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  2680. #else
  2681. #define MINTEMP_ALL HEATER_0_MINTEMP
  2682. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  2683. #endif
  2684. START_MENU();
  2685. MENU_BACK(MSG_TEMPERATURE);
  2686. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  2687. #if TEMP_SENSOR_0 != 0
  2688. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  2689. #endif
  2690. #if TEMP_SENSOR_BED != 0
  2691. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2692. #endif
  2693. #if ENABLED(EEPROM_SETTINGS)
  2694. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2695. #endif
  2696. END_MENU();
  2697. }
  2698. /**
  2699. *
  2700. * "Temperature" > "Preheat Material 1 conf" submenu
  2701. *
  2702. */
  2703. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2704. /**
  2705. *
  2706. * "Temperature" > "Preheat Material 2 conf" submenu
  2707. *
  2708. */
  2709. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2710. /**
  2711. *
  2712. * "Control" > "Motion" submenu
  2713. *
  2714. */
  2715. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2716. #if ENABLED(DISTINCT_E_FACTORS)
  2717. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2718. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2719. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2720. #if E_STEPPERS > 2
  2721. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2722. #if E_STEPPERS > 3
  2723. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2724. #if E_STEPPERS > 4
  2725. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2726. #endif // E_STEPPERS > 4
  2727. #endif // E_STEPPERS > 3
  2728. #endif // E_STEPPERS > 2
  2729. #endif
  2730. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2731. #if ENABLED(DISTINCT_E_FACTORS)
  2732. void _planner_refresh_e_positioning(const uint8_t e) {
  2733. if (e == active_extruder)
  2734. _planner_refresh_positioning();
  2735. else
  2736. planner.steps_to_mm[e] = 1.0 / planner.axis_steps_per_mm[e];
  2737. }
  2738. void _planner_refresh_e0_positioning() { _reset_e_acceleration_rate(0); }
  2739. void _planner_refresh_e1_positioning() { _reset_e_acceleration_rate(1); }
  2740. #if E_STEPPERS > 2
  2741. void _planner_refresh_e2_positioning() { _reset_e_acceleration_rate(2); }
  2742. #if E_STEPPERS > 3
  2743. void _planner_refresh_e3_positioning() { _reset_e_acceleration_rate(3); }
  2744. #if E_STEPPERS > 4
  2745. void _planner_refresh_e4_positioning() { _reset_e_acceleration_rate(4); }
  2746. #endif // E_STEPPERS > 4
  2747. #endif // E_STEPPERS > 3
  2748. #endif // E_STEPPERS > 2
  2749. #endif
  2750. #if HAS_BED_PROBE && DISABLED(BABYSTEP_ZPROBE_OFFSET)
  2751. static void lcd_refresh_zprobe_zoffset() { refresh_zprobe_zoffset(); }
  2752. #endif
  2753. // M203 / M205 Velocity options
  2754. void lcd_control_motion_velocity_menu() {
  2755. START_MENU();
  2756. MENU_BACK(MSG_MOTION);
  2757. // M203 Max Feedrate
  2758. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2759. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2760. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2761. #if ENABLED(DISTINCT_E_FACTORS)
  2762. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2763. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2764. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2765. #if E_STEPPERS > 2
  2766. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2767. #if E_STEPPERS > 3
  2768. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2769. #if E_STEPPERS > 4
  2770. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2771. #endif // E_STEPPERS > 4
  2772. #endif // E_STEPPERS > 3
  2773. #endif // E_STEPPERS > 2
  2774. #else
  2775. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2776. #endif
  2777. // M205 S Min Feedrate
  2778. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2779. // M205 T Min Travel Feedrate
  2780. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2781. END_MENU();
  2782. }
  2783. // M201 / M204 Accelerations
  2784. void lcd_control_motion_acceleration_menu() {
  2785. START_MENU();
  2786. MENU_BACK(MSG_MOTION);
  2787. // M204 P Acceleration
  2788. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2789. // M204 R Retract Acceleration
  2790. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2791. // M204 T Travel Acceleration
  2792. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2793. // M201 settings
  2794. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2795. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2796. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2797. #if ENABLED(DISTINCT_E_FACTORS)
  2798. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2799. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2800. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2801. #if E_STEPPERS > 2
  2802. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2803. #if E_STEPPERS > 3
  2804. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2805. #if E_STEPPERS > 4
  2806. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2807. #endif // E_STEPPERS > 4
  2808. #endif // E_STEPPERS > 3
  2809. #endif // E_STEPPERS > 2
  2810. #else
  2811. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2812. #endif
  2813. END_MENU();
  2814. }
  2815. // M205 Jerk
  2816. void lcd_control_motion_jerk_menu() {
  2817. START_MENU();
  2818. MENU_BACK(MSG_MOTION);
  2819. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2820. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2821. #if ENABLED(DELTA)
  2822. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2823. #else
  2824. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2825. #endif
  2826. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2827. END_MENU();
  2828. }
  2829. // M92 Steps-per-mm
  2830. void lcd_control_motion_steps_per_mm_menu() {
  2831. START_MENU();
  2832. MENU_BACK(MSG_MOTION);
  2833. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2834. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2835. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2836. #if ENABLED(DISTINCT_E_FACTORS)
  2837. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2838. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2839. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2840. #if E_STEPPERS > 2
  2841. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2842. #if E_STEPPERS > 3
  2843. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2844. #if E_STEPPERS > 4
  2845. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2846. #endif // E_STEPPERS > 4
  2847. #endif // E_STEPPERS > 3
  2848. #endif // E_STEPPERS > 2
  2849. #else
  2850. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2851. #endif
  2852. END_MENU();
  2853. }
  2854. void lcd_control_motion_menu() {
  2855. START_MENU();
  2856. MENU_BACK(MSG_CONTROL);
  2857. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2858. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2859. #elif HAS_BED_PROBE
  2860. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  2861. #endif
  2862. // M203 / M205 - Feedrate items
  2863. MENU_ITEM(submenu, MSG_VELOCITY, lcd_control_motion_velocity_menu);
  2864. // M201 - Acceleration items
  2865. MENU_ITEM(submenu, MSG_ACCELERATION, lcd_control_motion_acceleration_menu);
  2866. // M205 - Max Jerk
  2867. MENU_ITEM(submenu, MSG_JERK, lcd_control_motion_jerk_menu);
  2868. // M92 - Steps Per mm
  2869. MENU_ITEM(submenu, MSG_STEPS_PER_MM, lcd_control_motion_steps_per_mm_menu);
  2870. // M540 S - Abort on endstop hit when SD printing
  2871. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2872. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2873. #endif
  2874. END_MENU();
  2875. }
  2876. /**
  2877. *
  2878. * "Control" > "Filament" submenu
  2879. *
  2880. */
  2881. void lcd_control_filament_menu() {
  2882. START_MENU();
  2883. MENU_BACK(MSG_CONTROL);
  2884. #if ENABLED(LIN_ADVANCE)
  2885. MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
  2886. #endif
  2887. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  2888. if (volumetric_enabled) {
  2889. #if EXTRUDERS == 1
  2890. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2891. #else // EXTRUDERS > 1
  2892. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2893. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  2894. #if EXTRUDERS > 2
  2895. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  2896. #if EXTRUDERS > 3
  2897. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  2898. #if EXTRUDERS > 4
  2899. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  2900. #endif // EXTRUDERS > 4
  2901. #endif // EXTRUDERS > 3
  2902. #endif // EXTRUDERS > 2
  2903. #endif // EXTRUDERS > 1
  2904. }
  2905. END_MENU();
  2906. }
  2907. /**
  2908. *
  2909. * "Control" > "Retract" submenu
  2910. *
  2911. */
  2912. #if ENABLED(FWRETRACT)
  2913. void lcd_control_retract_menu() {
  2914. START_MENU();
  2915. MENU_BACK(MSG_CONTROL);
  2916. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  2917. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  2918. #if EXTRUDERS > 1
  2919. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  2920. #endif
  2921. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  2922. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  2923. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  2924. #if EXTRUDERS > 1
  2925. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, -100, 100);
  2926. #endif
  2927. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  2928. END_MENU();
  2929. }
  2930. #endif // FWRETRACT
  2931. #if ENABLED(SDSUPPORT)
  2932. #if !PIN_EXISTS(SD_DETECT)
  2933. void lcd_sd_refresh() {
  2934. card.initsd();
  2935. encoderTopLine = 0;
  2936. }
  2937. #endif
  2938. void lcd_sd_updir() {
  2939. card.updir();
  2940. encoderTopLine = 0;
  2941. screen_changed = true;
  2942. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2943. }
  2944. /**
  2945. *
  2946. * "Print from SD" submenu
  2947. *
  2948. */
  2949. void lcd_sdcard_menu() {
  2950. ENCODER_DIRECTION_MENUS();
  2951. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  2952. const uint16_t fileCnt = card.getnrfilenames();
  2953. START_MENU();
  2954. MENU_BACK(MSG_MAIN);
  2955. card.getWorkDirName();
  2956. if (card.filename[0] == '/') {
  2957. #if !PIN_EXISTS(SD_DETECT)
  2958. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  2959. #endif
  2960. }
  2961. else {
  2962. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  2963. }
  2964. for (uint16_t i = 0; i < fileCnt; i++) {
  2965. if (_menuLineNr == _thisItemNr) {
  2966. const uint16_t nr =
  2967. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  2968. fileCnt - 1 -
  2969. #endif
  2970. i;
  2971. #if ENABLED(SDCARD_SORT_ALPHA)
  2972. card.getfilename_sorted(nr);
  2973. #else
  2974. card.getfilename(nr);
  2975. #endif
  2976. if (card.filenameIsDir)
  2977. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2978. else
  2979. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2980. }
  2981. else {
  2982. MENU_ITEM_DUMMY();
  2983. }
  2984. }
  2985. END_MENU();
  2986. }
  2987. #endif // SDSUPPORT
  2988. #if ENABLED(LCD_INFO_MENU)
  2989. #if ENABLED(PRINTCOUNTER)
  2990. /**
  2991. *
  2992. * About Printer > Statistics submenu
  2993. *
  2994. */
  2995. void lcd_info_stats_menu() {
  2996. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2997. char buffer[21];
  2998. printStatistics stats = print_job_timer.getStats();
  2999. START_SCREEN(); // 12345678901234567890
  3000. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  3001. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  3002. duration_t elapsed = stats.printTime;
  3003. elapsed.toString(buffer);
  3004. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  3005. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3006. elapsed = stats.longestPrint;
  3007. elapsed.toString(buffer);
  3008. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  3009. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3010. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  3011. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  3012. STATIC_ITEM("", false, false, buffer); // 125m
  3013. END_SCREEN();
  3014. }
  3015. #endif // PRINTCOUNTER
  3016. /**
  3017. *
  3018. * About Printer > Thermistors
  3019. *
  3020. */
  3021. void lcd_info_thermistors_menu() {
  3022. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3023. START_SCREEN();
  3024. #define THERMISTOR_ID TEMP_SENSOR_0
  3025. #include "thermistornames.h"
  3026. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  3027. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  3028. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  3029. #if TEMP_SENSOR_1 != 0
  3030. #undef THERMISTOR_ID
  3031. #define THERMISTOR_ID TEMP_SENSOR_1
  3032. #include "thermistornames.h"
  3033. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  3034. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  3035. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  3036. #endif
  3037. #if TEMP_SENSOR_2 != 0
  3038. #undef THERMISTOR_ID
  3039. #define THERMISTOR_ID TEMP_SENSOR_2
  3040. #include "thermistornames.h"
  3041. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  3042. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  3043. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  3044. #endif
  3045. #if TEMP_SENSOR_3 != 0
  3046. #undef THERMISTOR_ID
  3047. #define THERMISTOR_ID TEMP_SENSOR_3
  3048. #include "thermistornames.h"
  3049. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  3050. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  3051. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  3052. #endif
  3053. #if TEMP_SENSOR_4 != 0
  3054. #undef THERMISTOR_ID
  3055. #define THERMISTOR_ID TEMP_SENSOR_4
  3056. #include "thermistornames.h"
  3057. STATIC_ITEM("T4: " THERMISTOR_NAME, false, true);
  3058. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_4_MINTEMP), false);
  3059. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false);
  3060. #endif
  3061. #if TEMP_SENSOR_BED != 0
  3062. #undef THERMISTOR_ID
  3063. #define THERMISTOR_ID TEMP_SENSOR_BED
  3064. #include "thermistornames.h"
  3065. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  3066. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  3067. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  3068. #endif
  3069. END_SCREEN();
  3070. }
  3071. /**
  3072. *
  3073. * About Printer > Board Info
  3074. *
  3075. */
  3076. void lcd_info_board_menu() {
  3077. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3078. START_SCREEN();
  3079. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  3080. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  3081. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  3082. #if POWER_SUPPLY == 0
  3083. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  3084. #elif POWER_SUPPLY == 1
  3085. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  3086. #elif POWER_SUPPLY == 2
  3087. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  3088. #endif
  3089. END_SCREEN();
  3090. }
  3091. /**
  3092. *
  3093. * About Printer > Printer Info
  3094. *
  3095. */
  3096. void lcd_info_printer_menu() {
  3097. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3098. START_SCREEN();
  3099. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  3100. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  3101. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  3102. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  3103. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  3104. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  3105. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  3106. STATIC_ITEM(MSG_3POINT_LEVELING, true); // 3-Point Leveling
  3107. #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
  3108. STATIC_ITEM(MSG_LINEAR_LEVELING, true); // Linear Leveling
  3109. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  3110. STATIC_ITEM(MSG_BILINEAR_LEVELING, true); // Bi-linear Leveling
  3111. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  3112. STATIC_ITEM(MSG_UBL_LEVELING, true); // Unified Bed Leveling
  3113. #elif ENABLED(MESH_BED_LEVELING)
  3114. STATIC_ITEM(MSG_MESH_LEVELING, true); // Mesh Leveling
  3115. #endif
  3116. END_SCREEN();
  3117. }
  3118. /**
  3119. *
  3120. * "About Printer" submenu
  3121. *
  3122. */
  3123. void lcd_info_menu() {
  3124. START_MENU();
  3125. MENU_BACK(MSG_MAIN);
  3126. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  3127. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  3128. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  3129. #if ENABLED(PRINTCOUNTER)
  3130. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  3131. #endif
  3132. END_MENU();
  3133. }
  3134. #endif // LCD_INFO_MENU
  3135. /**
  3136. *
  3137. * Filament Change Feature Screens
  3138. *
  3139. */
  3140. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3141. // Portions from STATIC_ITEM...
  3142. #define HOTEND_STATUS_ITEM() do { \
  3143. if (_menuLineNr == _thisItemNr) { \
  3144. if (lcdDrawUpdate) { \
  3145. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  3146. lcd_implementation_hotend_status(_lcdLineNr); \
  3147. } \
  3148. if (_skipStatic && encoderLine <= _thisItemNr) { \
  3149. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  3150. ++encoderLine; \
  3151. } \
  3152. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  3153. } \
  3154. ++_thisItemNr; \
  3155. }while(0)
  3156. void lcd_advanced_pause_toocold_menu() {
  3157. START_MENU();
  3158. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  3159. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  3160. MENU_BACK(MSG_BACK);
  3161. #if LCD_HEIGHT > 4
  3162. STATIC_ITEM(" ");
  3163. #endif
  3164. HOTEND_STATUS_ITEM();
  3165. END_MENU();
  3166. }
  3167. void lcd_advanced_pause_resume_print() {
  3168. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_RESUME_PRINT;
  3169. }
  3170. void lcd_advanced_pause_extrude_more() {
  3171. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE;
  3172. }
  3173. void lcd_advanced_pause_option_menu() {
  3174. START_MENU();
  3175. #if LCD_HEIGHT > 2
  3176. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  3177. #endif
  3178. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_advanced_pause_resume_print);
  3179. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_advanced_pause_extrude_more);
  3180. END_MENU();
  3181. }
  3182. void lcd_advanced_pause_init_message() {
  3183. START_SCREEN();
  3184. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3185. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  3186. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  3187. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  3188. #define __FC_LINES_A 3
  3189. #else
  3190. #define __FC_LINES_A 2
  3191. #endif
  3192. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  3193. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  3194. #define _FC_LINES_A (__FC_LINES_A + 1)
  3195. #else
  3196. #define _FC_LINES_A __FC_LINES_A
  3197. #endif
  3198. #if LCD_HEIGHT > _FC_LINES_A + 1
  3199. STATIC_ITEM(" ");
  3200. #endif
  3201. HOTEND_STATUS_ITEM();
  3202. END_SCREEN();
  3203. }
  3204. void lcd_advanced_pause_unload_message() {
  3205. START_SCREEN();
  3206. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3207. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  3208. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  3209. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  3210. #define __FC_LINES_B 3
  3211. #else
  3212. #define __FC_LINES_B 2
  3213. #endif
  3214. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  3215. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  3216. #define _FC_LINES_B (__FC_LINES_B + 1)
  3217. #else
  3218. #define _FC_LINES_B __FC_LINES_B
  3219. #endif
  3220. #if LCD_HEIGHT > _FC_LINES_B + 1
  3221. STATIC_ITEM(" ");
  3222. #endif
  3223. HOTEND_STATUS_ITEM();
  3224. END_SCREEN();
  3225. }
  3226. void lcd_advanced_pause_wait_for_nozzles_to_heat() {
  3227. START_SCREEN();
  3228. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3229. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  3230. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  3231. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  3232. #define _FC_LINES_C 3
  3233. #else
  3234. #define _FC_LINES_C 2
  3235. #endif
  3236. #if LCD_HEIGHT > _FC_LINES_C + 1
  3237. STATIC_ITEM(" ");
  3238. #endif
  3239. HOTEND_STATUS_ITEM();
  3240. END_SCREEN();
  3241. }
  3242. void lcd_advanced_pause_heat_nozzle() {
  3243. START_SCREEN();
  3244. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3245. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  3246. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3247. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  3248. #define _FC_LINES_D 3
  3249. #else
  3250. #define _FC_LINES_D 2
  3251. #endif
  3252. #if LCD_HEIGHT > _FC_LINES_D + 1
  3253. STATIC_ITEM(" ");
  3254. #endif
  3255. HOTEND_STATUS_ITEM();
  3256. END_SCREEN();
  3257. }
  3258. void lcd_advanced_pause_insert_message() {
  3259. START_SCREEN();
  3260. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3261. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  3262. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3263. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  3264. #define __FC_LINES_E 3
  3265. #else
  3266. #define __FC_LINES_E 2
  3267. #endif
  3268. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  3269. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  3270. #define _FC_LINES_E (__FC_LINES_E + 1)
  3271. #else
  3272. #define _FC_LINES_E __FC_LINES_E
  3273. #endif
  3274. #if LCD_HEIGHT > _FC_LINES_E + 1
  3275. STATIC_ITEM(" ");
  3276. #endif
  3277. HOTEND_STATUS_ITEM();
  3278. END_SCREEN();
  3279. }
  3280. void lcd_advanced_pause_load_message() {
  3281. START_SCREEN();
  3282. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3283. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  3284. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  3285. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  3286. #define __FC_LINES_F 3
  3287. #else
  3288. #define __FC_LINES_F 2
  3289. #endif
  3290. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  3291. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  3292. #define _FC_LINES_F (__FC_LINES_F + 1)
  3293. #else
  3294. #define _FC_LINES_F __FC_LINES_F
  3295. #endif
  3296. #if LCD_HEIGHT > _FC_LINES_F + 1
  3297. STATIC_ITEM(" ");
  3298. #endif
  3299. HOTEND_STATUS_ITEM();
  3300. END_SCREEN();
  3301. }
  3302. void lcd_advanced_pause_extrude_message() {
  3303. START_SCREEN();
  3304. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3305. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  3306. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  3307. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  3308. #define __FC_LINES_G 3
  3309. #else
  3310. #define __FC_LINES_G 2
  3311. #endif
  3312. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  3313. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  3314. #define _FC_LINES_G (__FC_LINES_G + 1)
  3315. #else
  3316. #define _FC_LINES_G __FC_LINES_G
  3317. #endif
  3318. #if LCD_HEIGHT > _FC_LINES_G + 1
  3319. STATIC_ITEM(" ");
  3320. #endif
  3321. HOTEND_STATUS_ITEM();
  3322. END_SCREEN();
  3323. }
  3324. void lcd_advanced_pause_resume_message() {
  3325. START_SCREEN();
  3326. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3327. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  3328. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  3329. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  3330. #endif
  3331. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  3332. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  3333. #endif
  3334. END_SCREEN();
  3335. }
  3336. void lcd_advanced_pause_show_message(const AdvancedPauseMessage message) {
  3337. switch (message) {
  3338. case ADVANCED_PAUSE_MESSAGE_INIT:
  3339. defer_return_to_status = true;
  3340. lcd_goto_screen(lcd_advanced_pause_init_message);
  3341. break;
  3342. case ADVANCED_PAUSE_MESSAGE_UNLOAD:
  3343. defer_return_to_status = true;
  3344. lcd_goto_screen(lcd_advanced_pause_unload_message);
  3345. break;
  3346. case ADVANCED_PAUSE_MESSAGE_INSERT:
  3347. defer_return_to_status = true;
  3348. lcd_goto_screen(lcd_advanced_pause_insert_message);
  3349. break;
  3350. case ADVANCED_PAUSE_MESSAGE_LOAD:
  3351. defer_return_to_status = true;
  3352. lcd_goto_screen(lcd_advanced_pause_load_message);
  3353. break;
  3354. case ADVANCED_PAUSE_MESSAGE_EXTRUDE:
  3355. defer_return_to_status = true;
  3356. lcd_goto_screen(lcd_advanced_pause_extrude_message);
  3357. break;
  3358. case ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  3359. defer_return_to_status = true;
  3360. lcd_goto_screen(lcd_advanced_pause_heat_nozzle);
  3361. break;
  3362. case ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  3363. defer_return_to_status = true;
  3364. lcd_goto_screen(lcd_advanced_pause_wait_for_nozzles_to_heat);
  3365. break;
  3366. case ADVANCED_PAUSE_MESSAGE_OPTION:
  3367. defer_return_to_status = true;
  3368. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_WAIT_FOR;
  3369. lcd_goto_screen(lcd_advanced_pause_option_menu);
  3370. break;
  3371. case ADVANCED_PAUSE_MESSAGE_RESUME:
  3372. defer_return_to_status = true;
  3373. lcd_goto_screen(lcd_advanced_pause_resume_message);
  3374. break;
  3375. case ADVANCED_PAUSE_MESSAGE_STATUS:
  3376. lcd_return_to_status();
  3377. break;
  3378. }
  3379. }
  3380. #endif // ADVANCED_PAUSE_FEATURE
  3381. /**
  3382. *
  3383. * Functions for editing single values
  3384. *
  3385. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  3386. *
  3387. * For example, DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1) expands into these functions:
  3388. *
  3389. * bool _menu_edit_int3();
  3390. * void menu_edit_int3(); // edit int (interactively)
  3391. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  3392. * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  3393. * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  3394. * void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback, const bool live); // edit int with callback
  3395. *
  3396. * You can then use one of the menu macros to present the edit interface:
  3397. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  3398. *
  3399. * This expands into a more primitive menu item:
  3400. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3401. *
  3402. * ...which calls:
  3403. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3404. */
  3405. #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
  3406. bool _menu_edit_ ## _name() { \
  3407. ENCODER_DIRECTION_NORMAL(); \
  3408. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3409. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  3410. if (lcdDrawUpdate) \
  3411. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  3412. if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
  3413. _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  3414. if (editValue != NULL) *((_type*)editValue) = value; \
  3415. if (liveEdit) (*callbackFunc)(); \
  3416. if (lcd_clicked) lcd_goto_previous_menu(); \
  3417. } \
  3418. return lcd_clicked; \
  3419. } \
  3420. void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
  3421. void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
  3422. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  3423. lcd_save_previous_screen(); \
  3424. \
  3425. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  3426. \
  3427. editLabel = pstr; \
  3428. editValue = ptr; \
  3429. minEditValue = minValue * _scale; \
  3430. maxEditValue = maxValue * _scale - minEditValue; \
  3431. encoderPosition = (*ptr) * _scale - minEditValue; \
  3432. } \
  3433. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  3434. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3435. currentScreen = menu_edit_ ## _name; \
  3436. } \
  3437. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
  3438. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3439. currentScreen = menu_edit_callback_ ## _name; \
  3440. callbackFunc = callback; \
  3441. liveEdit = live; \
  3442. } \
  3443. typedef void _name
  3444. DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
  3445. DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
  3446. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
  3447. DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
  3448. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
  3449. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01);
  3450. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
  3451. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
  3452. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
  3453. DEFINE_MENU_EDIT_TYPE(unsigned long, long5, ftostr5rj, 0.01);
  3454. /**
  3455. *
  3456. * Handlers for RepRap World Keypad input
  3457. *
  3458. */
  3459. #if ENABLED(REPRAPWORLD_KEYPAD)
  3460. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  3461. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  3462. encoderPosition = dir;
  3463. switch (axis) {
  3464. case X_AXIS: lcd_move_x(); break;
  3465. case Y_AXIS: lcd_move_y(); break;
  3466. case Z_AXIS: lcd_move_z();
  3467. default: break;
  3468. }
  3469. }
  3470. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  3471. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  3472. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  3473. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  3474. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  3475. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  3476. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  3477. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  3478. inline void handle_reprapworld_keypad() {
  3479. static uint8_t keypad_debounce = 0;
  3480. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  3481. if (keypad_debounce > 0) keypad_debounce--;
  3482. }
  3483. else if (!keypad_debounce) {
  3484. keypad_debounce = 2;
  3485. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  3486. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  3487. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3488. #endif
  3489. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  3490. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  3491. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3492. #endif
  3493. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  3494. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  3495. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  3496. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  3497. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  3498. }
  3499. else {
  3500. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  3501. }
  3502. }
  3503. }
  3504. #endif // REPRAPWORLD_KEYPAD
  3505. /**
  3506. *
  3507. * Menu actions
  3508. *
  3509. */
  3510. void _menu_action_back() { lcd_goto_previous_menu(); }
  3511. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  3512. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  3513. void menu_action_function(screenFunc_t func) { (*func)(); }
  3514. #if ENABLED(SDSUPPORT)
  3515. void menu_action_sdfile(const char* filename, char* longFilename) {
  3516. UNUSED(longFilename);
  3517. card.openAndPrintFile(filename);
  3518. lcd_return_to_status();
  3519. }
  3520. void menu_action_sddirectory(const char* filename, char* longFilename) {
  3521. UNUSED(longFilename);
  3522. card.chdir(filename);
  3523. encoderPosition = 0;
  3524. screen_changed = true;
  3525. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3526. }
  3527. #endif // SDSUPPORT
  3528. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  3529. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  3530. menu_action_setting_edit_bool(pstr, ptr);
  3531. (*callback)();
  3532. }
  3533. #endif // ULTIPANEL
  3534. void lcd_init() {
  3535. lcd_implementation_init(
  3536. #if ENABLED(LCD_PROGRESS_BAR)
  3537. true
  3538. #endif
  3539. );
  3540. #if ENABLED(NEWPANEL)
  3541. #if BUTTON_EXISTS(EN1)
  3542. SET_INPUT_PULLUP(BTN_EN1);
  3543. #endif
  3544. #if BUTTON_EXISTS(EN2)
  3545. SET_INPUT_PULLUP(BTN_EN2);
  3546. #endif
  3547. #if BUTTON_EXISTS(ENC)
  3548. SET_INPUT_PULLUP(BTN_ENC);
  3549. #endif
  3550. #if ENABLED(REPRAPWORLD_KEYPAD)
  3551. SET_OUTPUT(SHIFT_CLK);
  3552. OUT_WRITE(SHIFT_LD, HIGH);
  3553. SET_INPUT_PULLUP(SHIFT_OUT);
  3554. #endif
  3555. #if BUTTON_EXISTS(UP)
  3556. SET_INPUT(BTN_UP);
  3557. #endif
  3558. #if BUTTON_EXISTS(DWN)
  3559. SET_INPUT(BTN_DWN);
  3560. #endif
  3561. #if BUTTON_EXISTS(LFT)
  3562. SET_INPUT(BTN_LFT);
  3563. #endif
  3564. #if BUTTON_EXISTS(RT)
  3565. SET_INPUT(BTN_RT);
  3566. #endif
  3567. #else // !NEWPANEL
  3568. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  3569. SET_OUTPUT(SR_DATA_PIN);
  3570. SET_OUTPUT(SR_CLK_PIN);
  3571. #elif defined(SHIFT_CLK)
  3572. SET_OUTPUT(SHIFT_CLK);
  3573. OUT_WRITE(SHIFT_LD, HIGH);
  3574. OUT_WRITE(SHIFT_EN, LOW);
  3575. SET_INPUT_PULLUP(SHIFT_OUT);
  3576. #endif // SR_LCD_2W_NL
  3577. #endif // !NEWPANEL
  3578. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3579. SET_INPUT_PULLUP(SD_DETECT_PIN);
  3580. lcd_sd_status = 2; // UNKNOWN
  3581. #endif
  3582. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3583. slow_buttons = 0;
  3584. #endif
  3585. lcd_buttons_update();
  3586. #if ENABLED(ULTIPANEL)
  3587. encoderDiff = 0;
  3588. #endif
  3589. }
  3590. int lcd_strlen(const char* s) {
  3591. int i = 0, j = 0;
  3592. while (s[i]) {
  3593. if (PRINTABLE(s[i])) j++;
  3594. i++;
  3595. }
  3596. return j;
  3597. }
  3598. int lcd_strlen_P(const char* s) {
  3599. int j = 0;
  3600. while (pgm_read_byte(s)) {
  3601. if (PRINTABLE(pgm_read_byte(s))) j++;
  3602. s++;
  3603. }
  3604. return j;
  3605. }
  3606. bool lcd_blink() {
  3607. static uint8_t blink = 0;
  3608. static millis_t next_blink_ms = 0;
  3609. millis_t ms = millis();
  3610. if (ELAPSED(ms, next_blink_ms)) {
  3611. blink ^= 0xFF;
  3612. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  3613. }
  3614. return blink != 0;
  3615. }
  3616. /**
  3617. * Update the LCD, read encoder buttons, etc.
  3618. * - Read button states
  3619. * - Check the SD Card slot state
  3620. * - Act on RepRap World keypad input
  3621. * - Update the encoder position
  3622. * - Apply acceleration to the encoder position
  3623. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  3624. * - Reset the Info Screen timeout if there's any input
  3625. * - Update status indicators, if any
  3626. *
  3627. * Run the current LCD menu handler callback function:
  3628. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  3629. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  3630. * - Call the menu handler. Menu handlers should do the following:
  3631. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  3632. * (Encoder events automatically set lcdDrawUpdate for you.)
  3633. * - if (lcdDrawUpdate) { redraw }
  3634. * - Before exiting the handler set lcdDrawUpdate to:
  3635. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  3636. * - LCDVIEW_REDRAW_NOW to draw now (including remaining stripes).
  3637. * - LCDVIEW_CALL_REDRAW_NEXT to draw now and get LCDVIEW_REDRAW_NOW on the next loop.
  3638. * - LCDVIEW_CALL_NO_REDRAW to draw now and get LCDVIEW_NONE on the next loop.
  3639. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  3640. * so don't change lcdDrawUpdate without considering this.
  3641. *
  3642. * After the menu handler callback runs (or not):
  3643. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  3644. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  3645. *
  3646. * No worries. This function is only called from the main thread.
  3647. */
  3648. void lcd_update() {
  3649. #if ENABLED(ULTIPANEL)
  3650. static millis_t return_to_status_ms = 0;
  3651. manage_manual_move();
  3652. lcd_buttons_update();
  3653. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3654. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  3655. #else
  3656. constexpr bool UBL_CONDITION = true;
  3657. #endif
  3658. // If the action button is pressed...
  3659. if (UBL_CONDITION && LCD_CLICKED) {
  3660. if (!wait_for_unclick) { // If not waiting for a debounce release:
  3661. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  3662. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  3663. wait_for_user = false; // Any click clears wait for user
  3664. lcd_quick_feedback(); // Always make a click sound
  3665. }
  3666. }
  3667. else wait_for_unclick = false;
  3668. #endif
  3669. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3670. const bool sd_status = IS_SD_INSERTED;
  3671. if (sd_status != lcd_sd_status && lcd_detected()) {
  3672. if (sd_status) {
  3673. card.initsd();
  3674. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  3675. }
  3676. else {
  3677. card.release();
  3678. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  3679. }
  3680. lcd_sd_status = sd_status;
  3681. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3682. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3683. #if ENABLED(LCD_PROGRESS_BAR)
  3684. currentScreen == lcd_status_screen
  3685. #endif
  3686. );
  3687. }
  3688. #endif // SDSUPPORT && SD_DETECT_PIN
  3689. const millis_t ms = millis();
  3690. if (ELAPSED(ms, next_lcd_update_ms)
  3691. #if ENABLED(DOGLCD)
  3692. || drawing_screen
  3693. #endif
  3694. ) {
  3695. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  3696. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  3697. lcd_implementation_update_indicators();
  3698. #endif
  3699. #if ENABLED(ULTIPANEL)
  3700. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3701. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3702. #endif
  3703. #if ENABLED(REPRAPWORLD_KEYPAD)
  3704. handle_reprapworld_keypad();
  3705. #endif
  3706. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  3707. if (encoderPastThreshold || lcd_clicked) {
  3708. if (encoderPastThreshold) {
  3709. int32_t encoderMultiplier = 1;
  3710. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  3711. if (encoderRateMultiplierEnabled) {
  3712. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  3713. if (lastEncoderMovementMillis != 0) {
  3714. // Note that the rate is always calculated between two passes through the
  3715. // loop and that the abs of the encoderDiff value is tracked.
  3716. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  3717. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  3718. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  3719. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  3720. SERIAL_ECHO_START();
  3721. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3722. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3723. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3724. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3725. SERIAL_EOL();
  3726. #endif // ENCODER_RATE_MULTIPLIER_DEBUG
  3727. }
  3728. lastEncoderMovementMillis = ms;
  3729. } // encoderRateMultiplierEnabled
  3730. #endif // ENCODER_RATE_MULTIPLIER
  3731. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3732. encoderDiff = 0;
  3733. }
  3734. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3735. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3736. }
  3737. #endif // ULTIPANEL
  3738. // We arrive here every ~100ms when idling often enough.
  3739. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3740. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3741. if (
  3742. #if ENABLED(ULTIPANEL)
  3743. currentScreen == lcd_status_screen &&
  3744. #endif
  3745. !lcd_status_update_delay--
  3746. ) {
  3747. lcd_status_update_delay = 9
  3748. #if ENABLED(DOGLCD)
  3749. + 3
  3750. #endif
  3751. ;
  3752. max_display_update_time--;
  3753. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3754. }
  3755. // then we want to use 1/2 of the time only.
  3756. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3757. #if ENABLED(DOGLCD)
  3758. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3759. #else
  3760. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3761. #endif
  3762. {
  3763. #if ENABLED(DOGLCD)
  3764. if (!drawing_screen)
  3765. #endif
  3766. {
  3767. switch (lcdDrawUpdate) {
  3768. case LCDVIEW_CALL_NO_REDRAW:
  3769. lcdDrawUpdate = LCDVIEW_NONE;
  3770. break;
  3771. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3772. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3773. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3774. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3775. case LCDVIEW_NONE:
  3776. break;
  3777. } // switch
  3778. }
  3779. #if ENABLED(ULTIPANEL)
  3780. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3781. #else
  3782. #define CURRENTSCREEN() lcd_status_screen()
  3783. #endif
  3784. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3785. if (!drawing_screen) {
  3786. u8g.firstPage();
  3787. drawing_screen = 1;
  3788. }
  3789. lcd_setFont(FONT_MENU);
  3790. u8g.setColorIndex(1);
  3791. CURRENTSCREEN();
  3792. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3793. NOLESS(max_display_update_time, millis() - ms);
  3794. return;
  3795. }
  3796. #else
  3797. CURRENTSCREEN();
  3798. #endif
  3799. NOLESS(max_display_update_time, millis() - ms);
  3800. }
  3801. #if ENABLED(ULTIPANEL)
  3802. // Return to Status Screen after a timeout
  3803. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3804. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3805. else if (ELAPSED(ms, return_to_status_ms))
  3806. lcd_return_to_status();
  3807. #endif // ULTIPANEL
  3808. #if ENABLED(DOGLCD)
  3809. if (!drawing_screen)
  3810. #endif
  3811. {
  3812. switch (lcdDrawUpdate) {
  3813. case LCDVIEW_CLEAR_CALL_REDRAW:
  3814. lcd_implementation_clear();
  3815. case LCDVIEW_CALL_REDRAW_NEXT:
  3816. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3817. break;
  3818. case LCDVIEW_REDRAW_NOW:
  3819. lcdDrawUpdate = LCDVIEW_NONE;
  3820. break;
  3821. case LCDVIEW_NONE:
  3822. break;
  3823. } // switch
  3824. }
  3825. } // ELAPSED(ms, next_lcd_update_ms)
  3826. }
  3827. void pad_message_string() {
  3828. uint8_t i = 0, j = 0;
  3829. char c;
  3830. while ((c = lcd_status_message[i]) && j < LCD_WIDTH) {
  3831. if (PRINTABLE(c)) j++;
  3832. i++;
  3833. }
  3834. if (true
  3835. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  3836. && j < LCD_WIDTH
  3837. #endif
  3838. ) {
  3839. // pad with spaces to fill up the line
  3840. while (j++ < LCD_WIDTH) lcd_status_message[i++] = ' ';
  3841. // chop off at the edge
  3842. lcd_status_message[--i] = '\0';
  3843. }
  3844. }
  3845. void lcd_finishstatus(bool persist=false) {
  3846. pad_message_string();
  3847. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3848. UNUSED(persist);
  3849. #endif
  3850. #if ENABLED(LCD_PROGRESS_BAR)
  3851. progress_bar_ms = millis();
  3852. #if PROGRESS_MSG_EXPIRE > 0
  3853. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  3854. #endif
  3855. #endif
  3856. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3857. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  3858. previous_lcd_status_ms = millis(); //get status message to show up for a while
  3859. #endif
  3860. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  3861. status_scroll_pos = 0;
  3862. #endif
  3863. }
  3864. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  3865. void dontExpireStatus() { expire_status_ms = 0; }
  3866. #endif
  3867. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  3868. void lcd_setstatus(const char * const message, const bool persist) {
  3869. if (lcd_status_message_level > 0) return;
  3870. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  3871. lcd_finishstatus(persist);
  3872. }
  3873. void lcd_setstatusPGM(const char * const message, int8_t level) {
  3874. if (level < 0) level = lcd_status_message_level = 0;
  3875. if (level < lcd_status_message_level) return;
  3876. lcd_status_message_level = level;
  3877. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  3878. lcd_finishstatus(level > 0);
  3879. }
  3880. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  3881. if (level < lcd_status_message_level) return;
  3882. lcd_status_message_level = level;
  3883. va_list args;
  3884. va_start(args, fmt);
  3885. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  3886. va_end(args);
  3887. lcd_finishstatus(level > 0);
  3888. }
  3889. void lcd_setalertstatusPGM(const char * const message) {
  3890. lcd_setstatusPGM(message, 1);
  3891. #if ENABLED(ULTIPANEL)
  3892. lcd_return_to_status();
  3893. #endif
  3894. }
  3895. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  3896. #if HAS_LCD_CONTRAST
  3897. void set_lcd_contrast(const uint16_t value) {
  3898. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  3899. u8g.setContrast(lcd_contrast);
  3900. }
  3901. #endif
  3902. #if ENABLED(ULTIPANEL)
  3903. /**
  3904. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  3905. * These values are independent of which pins are used for EN_A and EN_B indications
  3906. * The rotary encoder part is also independent to the chipset used for the LCD
  3907. */
  3908. #if defined(EN_A) && defined(EN_B)
  3909. #define encrot0 0
  3910. #define encrot1 2
  3911. #define encrot2 3
  3912. #define encrot3 1
  3913. #endif
  3914. #define GET_BUTTON_STATES(DST) \
  3915. uint8_t new_##DST = 0; \
  3916. WRITE(SHIFT_LD, LOW); \
  3917. WRITE(SHIFT_LD, HIGH); \
  3918. for (int8_t i = 0; i < 8; i++) { \
  3919. new_##DST >>= 1; \
  3920. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  3921. WRITE(SHIFT_CLK, HIGH); \
  3922. WRITE(SHIFT_CLK, LOW); \
  3923. } \
  3924. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  3925. /**
  3926. * Read encoder buttons from the hardware registers
  3927. * Warning: This function is called from interrupt context!
  3928. */
  3929. void lcd_buttons_update() {
  3930. static uint8_t lastEncoderBits;
  3931. millis_t now = millis();
  3932. if (ELAPSED(now, next_button_update_ms)) {
  3933. #if ENABLED(NEWPANEL)
  3934. uint8_t newbutton = 0;
  3935. #if BUTTON_EXISTS(EN1)
  3936. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  3937. #endif
  3938. #if BUTTON_EXISTS(EN2)
  3939. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  3940. #endif
  3941. #if BUTTON_EXISTS(ENC)
  3942. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  3943. #endif
  3944. #if LCD_HAS_DIRECTIONAL_BUTTONS
  3945. // Manage directional buttons
  3946. #if ENABLED(REVERSE_MENU_DIRECTION)
  3947. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  3948. #else
  3949. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  3950. #endif
  3951. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  3952. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  3953. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  3954. #else
  3955. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  3956. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  3957. #endif
  3958. if (false) {
  3959. // for the else-ifs below
  3960. }
  3961. #if BUTTON_EXISTS(UP)
  3962. else if (BUTTON_PRESSED(UP)) {
  3963. encoderDiff = -(ENCODER_UD_STEPS);
  3964. next_button_update_ms = now + 300;
  3965. }
  3966. #endif
  3967. #if BUTTON_EXISTS(DWN)
  3968. else if (BUTTON_PRESSED(DWN)) {
  3969. encoderDiff = ENCODER_UD_STEPS;
  3970. next_button_update_ms = now + 300;
  3971. }
  3972. #endif
  3973. #if BUTTON_EXISTS(LFT)
  3974. else if (BUTTON_PRESSED(LFT)) {
  3975. encoderDiff = -(ENCODER_LR_PULSES);
  3976. next_button_update_ms = now + 300;
  3977. }
  3978. #endif
  3979. #if BUTTON_EXISTS(RT)
  3980. else if (BUTTON_PRESSED(RT)) {
  3981. encoderDiff = ENCODER_LR_PULSES;
  3982. next_button_update_ms = now + 300;
  3983. }
  3984. #endif
  3985. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  3986. buttons = newbutton;
  3987. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3988. buttons |= slow_buttons;
  3989. #endif
  3990. #if ENABLED(REPRAPWORLD_KEYPAD)
  3991. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  3992. #endif
  3993. #else
  3994. GET_BUTTON_STATES(buttons);
  3995. #endif // !NEWPANEL
  3996. } // next_button_update_ms
  3997. // Manage encoder rotation
  3998. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  3999. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  4000. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  4001. #elif ENABLED(REVERSE_MENU_DIRECTION)
  4002. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  4003. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  4004. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  4005. #define ENCODER_DIFF_CW (encoderDiff--)
  4006. #define ENCODER_DIFF_CCW (encoderDiff++)
  4007. #else
  4008. #define ENCODER_DIFF_CW (encoderDiff++)
  4009. #define ENCODER_DIFF_CCW (encoderDiff--)
  4010. #endif
  4011. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  4012. uint8_t enc = 0;
  4013. if (buttons & EN_A) enc |= B01;
  4014. if (buttons & EN_B) enc |= B10;
  4015. if (enc != lastEncoderBits) {
  4016. switch (enc) {
  4017. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  4018. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  4019. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  4020. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  4021. }
  4022. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4023. if (ubl.has_control_of_lcd_panel) {
  4024. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  4025. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  4026. // knob has not turned.
  4027. }
  4028. #endif
  4029. lastEncoderBits = enc;
  4030. }
  4031. }
  4032. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  4033. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  4034. #else
  4035. bool lcd_detected() { return true; }
  4036. #endif
  4037. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4038. void chirp_at_user() {
  4039. #if ENABLED(LCD_USE_I2C_BUZZER)
  4040. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4041. #elif PIN_EXISTS(BEEPER)
  4042. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4043. #endif
  4044. }
  4045. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  4046. #endif
  4047. #endif // ULTIPANEL
  4048. #endif // ULTRA_LCD