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

ultralcd.cpp 176KB

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