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

ultralcd.cpp 176KB

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