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

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