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

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