My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ultralcd.cpp 174KB

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