My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ultralcd.cpp 143KB

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