My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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