ultralcd.cpp 174 KB

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