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.

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