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

ultralcd.cpp 175KB

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