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