My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 173KB

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