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

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