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

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