My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ultralcd.cpp 158KB

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