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

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