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

ultralcd.cpp 156KB

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