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

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