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.

ultralcd.cpp 169KB

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